<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use ApiPlatform\Core\Annotation\ApiFilter;
use App\Repository\RoleContainerRepository;
use ApiPlatform\Core\Annotation\ApiResource;
use Symfony\Component\Serializer\Annotation\Groups;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
/**
* @ApiResource(
* attributes={"security"="is_granted('ROLE_SUPER_ADMIN')"},
* normalizationContext={"groups"={"RoleContainer:Read"}, "skip_null_values"=false},
* denormalizationContext={"groups"={"RoleContainer:Write"}},
* collectionOperations={
* "get"={"security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"},
* },
* itemOperations={
* "get"={"security"="is_granted('ROLE_OPERATOR') || is_granted('ROLE_SUPPORT')"}
* }
* )
* @ApiFilter(SearchFilter::class, properties={"id": "exact", "role": "exact", "container.id": "exact", "user.id": "exact"})
* @ApiFilter(OrderFilter::class, properties={"id", "container.name": "ASC"})
* @ORM\Entity(repositoryClass=RoleContainerRepository::class)
* @ORM\Table(
* name="role_container",
* indexes={
* @ORM\Index(name="role_idx", columns={"role"})
* }
* )
*/
class RoleContainer
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
* @Groups({"RoleContainer:Read"})
*/
private $id;
/**
* @ORM\Column(type="string", length=128)
* @Groups({"RoleContainer:Read"})
*/
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';
/**
* @ORM\ManyToOne(targetEntity=Container::class)
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
* @Groups({"RoleContainer:Read"})
*/
private $container;
/**
* @ORM\ManyToOne(targetEntity=User::class, inversedBy="roleContainers")
* @ORM\JoinColumn(nullable=false, onDelete="CASCADE")
*/
private $user;
public function __toString()
{
return $this->getRole().'.'.$this->getContainer()?->getId();
}
public function __construct($role = null, $container = null)
{
if ($role) {
$this->setRole($role);
}
if ($container) {
$this->setContainer($container);
}
}
public function getId(): ?int
{
return $this->id;
}
public function getRole(): ?string
{
return $this->role;
}
public function setRole(string $role): self
{
$this->role = $role;
return $this;
}
public function getContainer(): ?Container
{
return $this->container;
}
public function setContainer(?Container $container): self
{
$this->container = $container;
return $this;
}
public function getUser(): ?User
{
return $this->user;
}
public function setUser(?User $user): self
{
$this->user = $user;
return $this;
}
}