src/Entity/Users/Role.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Users;
  3. use Symfony\Component\Validator\Constraints AS Constraints;
  4. use Symfony\Component\Validator\Constraints AS Assert;
  5. use Doctrine\ORM\Mapping AS ORM;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Ramsey\Uuid\Uuid;
  8. /**
  9.  * @ORM\Entity(repositoryClass="App\Repository\Users\RoleRepository")
  10.  * @ORM\Table(name="users_role")
  11.  */
  12. class Role
  13. {
  14.     /**
  15.     * @ORM\Id
  16.     * @ORM\GeneratedValue(strategy="AUTO")
  17.     * @ORM\Column(type="integer")
  18.     */
  19.     private $id;
  20.     /**
  21.      * @ORM\Column(type="uuid")
  22.      * @Assert\Uuid
  23.      */
  24.      protected $uuid;
  25.     /**
  26.      * @var \DateTime
  27.      *
  28.      * @ORM\Column(type="datetime", nullable=false)
  29.      */
  30.     private $created;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=false)
  33.      */
  34.     private $name;
  35.     /**
  36.      * @ORM\Column(type="string", length=255, nullable=false)
  37.      */
  38.     private $userClass;
  39.     /**
  40.      * @ORM\ManyToMany(targetEntity="User", mappedBy="userRoles")
  41.      * @ORM\JoinColumn(name="role_id", referencedColumnName="id", unique=false)
  42.      **/
  43.     private $users;
  44.     public function __construct()
  45.     {
  46.         // UUID
  47.         if(!$this->getUuid())
  48.         {
  49.             $uuid Uuid::uuid1();
  50.             $this->setUuid($uuid->toString());
  51.         }
  52.         // Set some defaults
  53.         $this->setCreated(new \DateTime());
  54.         $this->users = new ArrayCollection();
  55.     }
  56.     public function __toString()
  57.     {
  58.         return $this->getName();
  59.     }
  60.     public function getId()
  61.     {
  62.         return $this->id;
  63.     }
  64.     public function setUuid($uuid)
  65.     {
  66.         $this->uuid $uuid;
  67.         return $this;
  68.     }
  69.     public function getUuid()
  70.     {
  71.         return $this->uuid;
  72.     }
  73.     public function setCreated(\DateTime $created)
  74.     {
  75.         $this->created $created;
  76.     }
  77.     public function getCreated()
  78.     {
  79.         return $this->created;
  80.     }
  81.     public function getName()
  82.     {
  83.         return $this->name;
  84.     }
  85.     public function setName(string $name)
  86.     {
  87.         $this->name $name;
  88.     }
  89.     public function getUserClass()
  90.     {
  91.         return $this->userClass;
  92.     }
  93.     public function setUserClass(string $userClass)
  94.     {
  95.         $this->userClass $userClass;
  96.     }
  97.     public function getUsers()
  98.     {
  99.         return $this->users;
  100.     }
  101.     public function addUser(\App\Entity\Users\User $user)
  102.     {
  103.         if($this->users->contains($user))
  104.             return true;
  105.         // Add it
  106.         $this->users->add($user);
  107.         $user->addUserRole($this);
  108.     }
  109.     public function removeUser(\App\Entity\Users\User $user)
  110.     {
  111.         $this->users->removeElement($user);
  112.     }
  113. }