src/Entity/RoleContainer.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use ApiPlatform\Core\Annotation\ApiFilter;
  5. use App\Repository\RoleContainerRepository;
  6. use ApiPlatform\Core\Annotation\ApiResource;
  7. use Symfony\Component\Serializer\Annotation\Groups;
  8. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
  9. use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
  10. /**
  11.  * @ApiResource(
  12.  *      attributes={"security"="is_granted('ROLE_SUPER_ADMIN')"},
  13.  *      normalizationContext={"groups"={"RoleContainer:Read"}, "skip_null_values"=false},
  14.  *      denormalizationContext={"groups"={"RoleContainer:Write"}},
  15.  *      collectionOperations={
  16.  *          "get"={"security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"},
  17.  *     },
  18.  *      itemOperations={
  19.  *          "get"={"security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"}
  20.  *     }
  21.  * )
  22.  * @ApiFilter(SearchFilter::class, properties={"id": "exact", "role": "exact", "container.id": "exact", "user.id": "exact"})
  23.  * @ApiFilter(OrderFilter::class, properties={"id", "container.name": "ASC"})
  24.  * @ORM\Entity(repositoryClass=RoleContainerRepository::class)
  25.  * @ORM\Table(
  26.  *      name="role_container",
  27.  *      indexes={
  28.  *          @ORM\Index(name="role_idx", columns={"role"})
  29.  *      }
  30.  * )
  31.  */
  32. class RoleContainer
  33. {
  34.     /**
  35.      * @ORM\Id
  36.      * @ORM\GeneratedValue
  37.      * @ORM\Column(type="integer")
  38.      * @Groups({"RoleContainer:Read"})
  39.      */
  40.     private $id;
  41.     /**
  42.      * @ORM\Column(type="string", length=128)
  43.      * @Groups({"RoleContainer:Read"})
  44.      */
  45.     private $role;
  46.     public const ROLE_GUEST_VOTER 'ROLE_GUEST_VOTER';
  47.     public const ROLE_READER 'ROLE_READER';
  48.     public const ROLE_USER 'ROLE_USER';
  49.     public const ROLE_INSTRUCTOR 'ROLE_INSTRUCTOR';
  50.     public const ROLE_STAFF 'ROLE_STAFF';
  51.     public const ROLE_RELATION_MANAGER 'ROLE_RELATION_MANAGER';
  52.     public const ROLE_SPEAKER 'ROLE_SPEAKER';
  53.     public const ROLE_MODERATOR 'ROLE_MODERATOR';
  54.     public const ROLE_SUPPORT 'ROLE_SUPPORT';
  55.     public const ROLE_OPERATOR 'ROLE_OPERATOR';
  56.     public const ROLE_ADMIN 'ROLE_ADMIN';
  57.     public const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  58.     /**
  59.      * @ORM\ManyToOne(targetEntity=Container::class)
  60.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  61.      * @Groups({"RoleContainer:Read"})
  62.      */
  63.     private $container;
  64.     /**
  65.      * @ORM\ManyToOne(targetEntity=User::class, inversedBy="roleContainers")
  66.      * @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
  67.      */
  68.     private $user;
  69.     public function __toString()
  70.     {
  71.         return $this->getRole().'.'.$this->getContainer()?->getId();
  72.     }
  73.     public function __construct($role null$container null)
  74.     {
  75.         if ($role) {
  76.             $this->setRole($role);
  77.         }
  78.         if ($container) {
  79.             $this->setContainer($container);
  80.         }
  81.     }
  82.     public function getId(): ?int
  83.     {
  84.         return $this->id;
  85.     }
  86.     public function getRole(): ?string
  87.     {
  88.         return $this->role;
  89.     }
  90.     public function setRole(string $role): self
  91.     {
  92.         $this->role $role;
  93.         return $this;
  94.     }
  95.     public function getContainer(): ?Container
  96.     {
  97.         return $this->container;
  98.     }
  99.     public function setContainer(?Container $container): self
  100.     {
  101.         $this->container $container;
  102.         return $this;
  103.     }
  104.     public function getUser(): ?User
  105.     {
  106.         return $this->user;
  107.     }
  108.     public function setUser(?User $user): self
  109.     {
  110.         $this->user $user;
  111.         return $this;
  112.     }
  113. }