<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use App\Repository\RoleRepository;
use App\Entity\Traits\TimestampableEntity;
use Doctrine\Common\Collections\Collection;
use ApiPlatform\Core\Annotation\ApiProperty;
use ApiPlatform\Core\Annotation\ApiResource;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\Serializer\Annotation\Groups;
use Symfony\Component\Validator\Constraints as Assert;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_ADMIN')"},
* normalizationContext={"groups"={"Role:Read"}},
* denormalizationContext={"groups"={"Role:Write"}},
* collectionOperations={
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "post"
* },
* itemOperations={
* "get"={"security"="is_granted('IS_AUTHENTICATED_FULLY')"},
* "put",
* "patch",
* "delete"
* }
* )
* @ORM\Entity(repositoryClass=RoleRepository::class)
* @ORM\Table(name="role",indexes={@ORM\Index(name="role_role_idx", columns={"role"})})
*/
class Role
{
/**
* Hook timestampable behavior
* updates createdAt, updatedAt fields
*/
use TimestampableEntity;
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
* @Groups({"Role:Read", "Role:Write"})
*
* @Assert\NotBlank(message="validation.role:name.notBlank")
* @Assert\Length(max=128, maxMessage="validation.role:name.max")
*/
private $name;
/**
* @ORM\Column(type="string", length=128)
* @ApiProperty(
* attributes={
* "openapi_context"={
* "type"="string",
* "enum"={self::ROLE_INSTRUCTOR, self::ROLE_READER, self::ROLE_USER, self::ROLE_STAFF, self::ROLE_RELATION_MANAGER, self::ROLE_SPEAKER,
* self::ROLE_MODERATOR, self::ROLE_SUPPORT, self::ROLE_OPERATOR, self::ROLE_ADMIN, self::ROLE_SUPER_ADMIN}
* }
* }
* )
* @Groups({"Role:Read", "Role:Write"})
*
* @Assert\NotBlank(message="validation.role:role.notBlank")
* @Assert\Length(max=128, maxMessage="validation.role:role.max")
* @Assert\Choice({self::ROLE_INSTRUCTOR, self::ROLE_READER, self::ROLE_USER, self::ROLE_STAFF, self::ROLE_RELATION_MANAGER, self::ROLE_SPEAKER,
* self::ROLE_MODERATOR, self::ROLE_SUPPORT, self::ROLE_OPERATOR, self::ROLE_ADMIN, self::ROLE_SUPER_ADMIN})
*/
private $role;
public const ROLE_GUEST_VOTER = 'ROLE_GUEST_VOTER';
public const ROLE_READER = 'ROLE_READER';
public const ROLE_USER = 'ROLE_USER';
public const ROLE_INSTRUCTOR = 'ROLE_INSTRUCTOR';
public const ROLE_STAFF = 'ROLE_STAFF';
public const ROLE_RELATION_MANAGER = 'ROLE_RELATION_MANAGER';
public const ROLE_SPEAKER = 'ROLE_SPEAKER';
public const ROLE_MODERATOR = 'ROLE_MODERATOR';
public const ROLE_SUPPORT = 'ROLE_SUPPORT';
public const ROLE_OPERATOR = 'ROLE_OPERATOR';
public const ROLE_ADMIN = 'ROLE_ADMIN';
public const ROLE_SUPER_ADMIN = 'ROLE_SUPER_ADMIN';
public function __toString()
{
return $this->getRole();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(string $role): self
{
$this->role = $role;
return $this;
}
}