<?php
namespace App\Entity\Channel;
use App\Entity\Sync\SyncableInterface;
use App\Repository\Channel\ChannelUserRoleRepository;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserRoleInterface;
use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelUserPermissionInterface;
use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelUserPermissionMethodTrait;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: ChannelUserRoleRepository::class),
ORM\Table('channel_user_role'),
]
class ChannelUserRole implements ChannelUserPermissionInterface, ChannelUserRoleInterface, SyncableInterface
{
use ChannelUserPermissionMethodTrait;
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
#[Serial\Groups(['Sync', 'Manager'])]
private ?int $id = null;
#[ORM\ManyToOne(targetEntity: Channel::class, inversedBy: 'channelUserRoles')]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(['Sync'])]
private ?Channel $channel = null;
#[ORM\Column(type: 'integer', nullable: true)]
private ?int $autoCreatedType = null;
#[ORM\Column(type: 'string', nullable: false)]
#[
Assert\NotBlank(),
Assert\Length(max: 254)
]
#[Serial\Groups(['Sync', 'Manager'])]
private ?string $name = null;
#[ORM\Column(type: 'simple_array', nullable: true)]
#[Serial\Groups(['Sync'])]
private ?array $perms = [];
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_USER_ROLE;
}
public function getSyncDisplayLabel(): string
{
return (string) $this->getName();
}
public function __toString(): string
{
return $this->getName() ?? '';
}
public function getId(): ?int
{
return $this->id;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): ChannelUserRole
{
$this->channel = $channel;
return $this;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): static
{
$this->name = $name;
return $this;
}
public function getAutoCreatedType(): ?int
{
return $this->autoCreatedType;
}
public function setAutoCreatedType(?int $autoCreatedType): static
{
$this->autoCreatedType = $autoCreatedType;
return $this;
}
public function addPerm(string $perm): ChannelUserRole
{
if (!in_array($perm, $this->perms)) {
$this->perms[] = $perm;
}
return $this;
}
public function removePerm(string $perm): ChannelUserRole
{
if (in_array($perm, $this->perms)) {
$this->perms = array_diff($this->perms, [$perm]);
}
return $this;
}
}