src/Entity/Security/Profile.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Security;
  3. use App\Entity\User\User;
  4. use App\Repository\Security\ProfileRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ProfileRepository::class)
  10.  */
  11. class Profile
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $name;
  23.     /**
  24.      * @ORM\OneToMany(targetEntity=Permission::class, mappedBy="profile", orphanRemoval=true)
  25.      */
  26.     private $permissions;
  27.     /**
  28.      * @ORM\OneToMany(targetEntity=User::class, mappedBy="profile")
  29.      */
  30.     private $users;
  31.     public function __construct()
  32.     {
  33.         $this->permissions = new ArrayCollection();
  34.         $this->users = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getName(): ?string
  41.     {
  42.         return $this->name;
  43.     }
  44.     public function setName(string $name): self
  45.     {
  46.         $this->name $name;
  47.         return $this;
  48.     }
  49.     /**
  50.      * @return Collection<int, Permission>
  51.      */
  52.     public function getPermissions(): Collection
  53.     {
  54.         return $this->permissions;
  55.     }
  56.     public function addPermission(Permission $permission): self
  57.     {
  58.         if (!$this->permissions->contains($permission)) {
  59.             $this->permissions[] = $permission;
  60.             $permission->setProfile($this);
  61.         }
  62.         return $this;
  63.     }
  64.     public function removePermission(Permission $permission): self
  65.     {
  66.         if ($this->permissions->removeElement($permission)) {
  67.             // set the owning side to null (unless already changed)
  68.             if ($permission->getProfile() === $this) {
  69.                 $permission->setProfile(null);
  70.             }
  71.         }
  72.         return $this;
  73.     }
  74.     public function __toString(): string
  75.     {
  76.         return $this->name;
  77.     }
  78.     /**
  79.      * @return Collection<int, User>
  80.      */
  81.     public function getUsers(): Collection
  82.     {
  83.         return $this->users;
  84.     }
  85.     public function addUser(User $user): self
  86.     {
  87.         if (!$this->users->contains($user)) {
  88.             $this->users[] = $user;
  89.             $user->setProfile($this);
  90.         }
  91.         return $this;
  92.     }
  93.     public function removeUser(User $user): self
  94.     {
  95.         if ($this->users->removeElement($user)) {
  96.             // set the owning side to null (unless already changed)
  97.             if ($user->getProfile() === $this) {
  98.                 $user->setProfile(null);
  99.             }
  100.         }
  101.         return $this;
  102.     }
  103. }