src/Entity/Role.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use App\Repository\RoleRepository;
  5. use App\Entity\Traits\TimestampableEntity;
  6. use Doctrine\Common\Collections\Collection;
  7. use ApiPlatform\Core\Annotation\ApiProperty;
  8. use ApiPlatform\Core\Annotation\ApiResource;
  9. use Doctrine\Common\Collections\ArrayCollection;
  10. use Symfony\Component\Serializer\Annotation\Groups;
  11. use Symfony\Component\Validator\Constraints as Assert;
  12. /**
  13.  * @ApiResource(
  14.  *      attributes={"security"="is_granted('ROLE_ADMIN')"},
  15.  *      normalizationContext={"groups"={"Role:Read"}},
  16.  *      denormalizationContext={"groups"={"Role:Write"}},
  17.  *      collectionOperations={
  18.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  19.  *          "post"
  20.  *      },
  21.  *      itemOperations={
  22.  *          "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
  23.  *          "put",
  24.  *          "patch",
  25.  *          "delete"
  26.  *      }
  27.  * )
  28.  * @ORM\Entity(repositoryClass=RoleRepository::class)
  29.  * @ORM\Table(name="role",indexes={@ORM\Index(name="role_role_idx", columns={"role"})})
  30.  */
  31. class Role
  32. {
  33.     /**
  34.      * Hook timestampable behavior
  35.      * updates createdAt, updatedAt fields
  36.      */
  37.     use TimestampableEntity;
  38.     /**
  39.      * @ORM\Id
  40.      * @ORM\GeneratedValue
  41.      * @ORM\Column(type="integer")
  42.      */
  43.     private $id;
  44.     /**
  45.      * @ORM\Column(type="string", length=128)
  46.      * @Groups({"Role:Read", "Role:Write"})
  47.      *
  48.      * @Assert\NotBlank(message="validation.role:name.notBlank")
  49.      * @Assert\Length(max=128, maxMessage="validation.role:name.max")
  50.      */
  51.     private $name;
  52.     /**
  53.      * @ORM\Column(type="string", length=128)
  54.      * @ApiProperty(
  55.      *     attributes={
  56.      *         "openapi_context"={
  57.      *             "type"="string",
  58.      *             "enum"={self::ROLE_INSTRUCTOR, self::ROLE_READER, self::ROLE_USER, self::ROLE_STAFF, self::ROLE_RELATION_MANAGER, self::ROLE_SPEAKER,
  59.      *                  self::ROLE_MODERATOR, self::ROLE_SUPPORT, self::ROLE_OPERATOR, self::ROLE_ADMIN, self::ROLE_SUPER_ADMIN}
  60.      *         }
  61.      *     }
  62.      * )
  63.      * @Groups({"Role:Read", "Role:Write"})
  64.      *
  65.      * @Assert\NotBlank(message="validation.role:role.notBlank")
  66.      * @Assert\Length(max=128, maxMessage="validation.role:role.max")
  67.      * @Assert\Choice({self::ROLE_INSTRUCTOR, self::ROLE_READER, self::ROLE_USER, self::ROLE_STAFF, self::ROLE_RELATION_MANAGER, self::ROLE_SPEAKER,
  68.      * self::ROLE_MODERATOR, self::ROLE_SUPPORT, self::ROLE_OPERATOR, self::ROLE_ADMIN, self::ROLE_SUPER_ADMIN})
  69.      */
  70.     private $role;
  71.     public const ROLE_GUEST_VOTER 'ROLE_GUEST_VOTER';
  72.     public const ROLE_READER 'ROLE_READER';
  73.     public const ROLE_USER 'ROLE_USER';
  74.     public const ROLE_INSTRUCTOR 'ROLE_INSTRUCTOR';
  75.     public const ROLE_STAFF 'ROLE_STAFF';
  76.     public const ROLE_RELATION_MANAGER 'ROLE_RELATION_MANAGER';
  77.     public const ROLE_SPEAKER 'ROLE_SPEAKER';
  78.     public const ROLE_MODERATOR 'ROLE_MODERATOR';
  79.     public const ROLE_SUPPORT 'ROLE_SUPPORT';
  80.     public const ROLE_OPERATOR 'ROLE_OPERATOR';
  81.     public const ROLE_ADMIN 'ROLE_ADMIN';
  82.     public const ROLE_SUPER_ADMIN 'ROLE_SUPER_ADMIN';
  83.     public function __toString()
  84.     {
  85.         return $this->getRole();
  86.     }
  87.     public function getId(): ?int
  88.     {
  89.         return $this->id;
  90.     }
  91.     public function getName(): ?string
  92.     {
  93.         return $this->name;
  94.     }
  95.     public function setName(string $name): self
  96.     {
  97.         $this->name $name;
  98.         return $this;
  99.     }
  100.     public function getRole(): ?string
  101.     {
  102.         return $this->role;
  103.     }
  104.     public function setRole(string $role): self
  105.     {
  106.         $this->role $role;
  107.         return $this;
  108.     }
  109. }