src/Entity/RoleManagement.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Interface\NotificationInterface;
  4. use App\Entity\Traits\TimestampTrait;
  5. use App\Repository\RoleManagementRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  10. #[ORM\Entity(repositoryClassRoleManagementRepository::class)]
  11. #[UniqueEntity(fields: ['roleName'])]
  12. class RoleManagement implements NotificationInterface
  13. {
  14.     use TimestampTrait;
  15.     public const SUPER_ADMIN 'Super Admin';
  16.     public const ROLE_CLIENT 'Client';
  17.     public const REGULAR_ADMIN 'Admin';
  18.     public const STANDARD_USER 'User';
  19.     #[ORM\Id]
  20.     #[ORM\GeneratedValue]
  21.     #[ORM\Column(type'integer')]
  22.     private $id;
  23.     #[ORM\Column(type'string'length255)]
  24.     private $roleName;
  25.     #[ORM\Column(type'json'nullabletrue)]
  26.     private $routePermissions = [];
  27.     #[ORM\ManyToMany(targetEntityNotificationProfile::class, mappedBy'roleToSend')]
  28.     private $notificationProfiles;
  29.     #[ORM\ManyToMany(targetEntityUser::class, mappedBy'userRole')]
  30.     private $users;
  31.     public function __construct()
  32.     {
  33.         $this->notificationProfiles = new ArrayCollection();
  34.         $this->users = new ArrayCollection();
  35.     }
  36.     public function getId(): ?int
  37.     {
  38.         return $this->id;
  39.     }
  40.     public function getRoleName(): ?string
  41.     {
  42.         return $this->roleName;
  43.     }
  44.     public function setRoleName(string $roleName): self
  45.     {
  46.         $this->roleName $roleName;
  47.         return $this;
  48.     }
  49.     public function getRoutePermissions(): ?array
  50.     {
  51.         return $this->routePermissions;
  52.     }
  53.     public function setRoutePermissions(?array $routePermissions): self
  54.     {
  55.         $this->routePermissions $routePermissions;
  56.         return $this;
  57.     }
  58.     /**
  59.      * @return Collection<int, NotificationProfile>
  60.      */
  61.     public function getNotificationProfiles(): Collection
  62.     {
  63.         return $this->notificationProfiles;
  64.     }
  65.     public function addNotificationProfile(NotificationProfile $notificationProfile): self
  66.     {
  67.         if (!$this->notificationProfiles->contains($notificationProfile)) {
  68.             $this->notificationProfiles[] = $notificationProfile;
  69.             $notificationProfile->addRoleToSend($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeNotificationProfile(NotificationProfile $notificationProfile): self
  74.     {
  75.         if ($this->notificationProfiles->removeElement($notificationProfile)) {
  76.             $notificationProfile->removeRoleToSend($this);
  77.         }
  78.         return $this;
  79.     }
  80.     /**
  81.      * @return Collection<int, User>
  82.      */
  83.     public function getUsers(): Collection
  84.     {
  85.         return $this->users;
  86.     }
  87.     public function addUser(User $user): self
  88.     {
  89.         if (!$this->users->contains($user)) {
  90.             $this->users[] = $user;
  91.             $user->addUserRole($this);
  92.         }
  93.         return $this;
  94.     }
  95.     public function removeUser(User $user): self
  96.     {
  97.         if ($this->users->removeElement($user)) {
  98.             $user->removeUserRole($this);
  99.         }
  100.         return $this;
  101.     }
  102. }