Advertisement
Guest User

Role

a guest
Aug 17th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.72 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Entity;
  4.  
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\ORM\Mapping as ORM;
  7.  
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\RoleRepository")
  10.  * @ORM\Table(name="role")
  11.  */
  12. class Role implements \JsonSerializable
  13. {
  14.     /**
  15.      * @ORM\Id()
  16.      * @ORM\GeneratedValue()
  17.      * @ORM\Column(type="integer")
  18.      * @var int|null $id
  19.      */
  20.     private $id;
  21.  
  22.     /**
  23.      * @ORM\Column(type="string", length=255)
  24.      * @var string $name
  25.      */
  26.     private $name;
  27.  
  28.     /**
  29.      * @ORM\ManyToMany(targetEntity="App\Entity\User", mappedBy="roles")
  30.      * @var User[]|null $users
  31.      */
  32.     private $users;
  33.  
  34.     public function __construct()
  35.     {
  36.         $this->users = new ArrayCollection();
  37.     }
  38.  
  39.     /**
  40.      * @param int $id
  41.      */
  42.     public function setId(int $id): void
  43.     {
  44.         $this->id = $id;
  45.     }
  46.  
  47.     /**
  48.      * @return int|null
  49.      */
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.  
  55.     /**
  56.      * @return string|null
  57.      */
  58.     public function getName(): ?string
  59.     {
  60.         return $this->name;
  61.     }
  62.  
  63.     /**
  64.      * @param string $name
  65.      */
  66.     public function setName(string $name): void
  67.     {
  68.         $this->name = $name;
  69.     }
  70.  
  71.     /**
  72.      * @return User[]|null
  73.      */
  74.     public function getUsers()
  75.     {
  76.         return $this->users;
  77.     }
  78.  
  79.     public function addUser(User $user): void
  80.     {
  81.         $this->users[] = $user;
  82.     }
  83.  
  84.     /**
  85.      * @return array|mixed
  86.      */
  87.     public function jsonSerialize()
  88.     {
  89.         return [
  90.             'id' => $this->getId(),
  91.             'name' => $this->getName(),
  92.             'users' => $this->getUsers()
  93.         ];
  94.     }
  95.  
  96.  
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement