src/Entity/Channel/ChannelUserRole.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Sync\SyncableInterface;
  4. use App\Repository\Channel\ChannelUserRoleRepository;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  7. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelUserRoleInterface;
  8. use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelUserPermissionInterface;
  9. use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelUserPermissionMethodTrait;
  10. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  11. use Symfony\Component\Serializer\Annotation as Serial;
  12. use Symfony\Component\Validator\Constraints as Assert;
  13. #[
  14. ORM\Entity(repositoryClass: ChannelUserRoleRepository::class),
  15. ORM\Table('channel_user_role'),
  16. ]
  17. class ChannelUserRole implements ChannelUserPermissionInterface, ChannelUserRoleInterface, SyncableInterface
  18. {
  19. use ChannelUserPermissionMethodTrait;
  20. #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
  21. #[Serial\Groups(['Sync', 'Manager'])]
  22. private ?int $id = null;
  23. #[ORM\ManyToOne(targetEntity: Channel::class, inversedBy: 'channelUserRoles')]
  24. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  25. #[IdGroups(['Sync'])]
  26. private ?Channel $channel = null;
  27. #[ORM\Column(type: 'integer', nullable: true)]
  28. private ?int $autoCreatedType = null;
  29. #[ORM\Column(type: 'string', nullable: false)]
  30. #[
  31. Assert\NotBlank(),
  32. Assert\Length(max: 254)
  33. ]
  34. #[Serial\Groups(['Sync', 'Manager'])]
  35. private ?string $name = null;
  36. #[ORM\Column(type: 'simple_array', nullable: true)]
  37. #[Serial\Groups(['Sync'])]
  38. private ?array $perms = [];
  39. public static function getSyncKey(): string
  40. {
  41. return EntityKeys::CHANNEL_USER_ROLE;
  42. }
  43. public function getSyncDisplayLabel(): string
  44. {
  45. return (string) $this->getName();
  46. }
  47. public function __toString(): string
  48. {
  49. return $this->getName() ?? '';
  50. }
  51. public function getId(): ?int
  52. {
  53. return $this->id;
  54. }
  55. public function getChannel(): ?Channel
  56. {
  57. return $this->channel;
  58. }
  59. public function setChannel(?Channel $channel): ChannelUserRole
  60. {
  61. $this->channel = $channel;
  62. return $this;
  63. }
  64. public function getName(): ?string
  65. {
  66. return $this->name;
  67. }
  68. public function setName(?string $name): static
  69. {
  70. $this->name = $name;
  71. return $this;
  72. }
  73. public function getAutoCreatedType(): ?int
  74. {
  75. return $this->autoCreatedType;
  76. }
  77. public function setAutoCreatedType(?int $autoCreatedType): static
  78. {
  79. $this->autoCreatedType = $autoCreatedType;
  80. return $this;
  81. }
  82. public function addPerm(string $perm): ChannelUserRole
  83. {
  84. if (!in_array($perm, $this->perms)) {
  85. $this->perms[] = $perm;
  86. }
  87. return $this;
  88. }
  89. public function removePerm(string $perm): ChannelUserRole
  90. {
  91. if (in_array($perm, $this->perms)) {
  92. $this->perms = array_diff($this->perms, [$perm]);
  93. }
  94. return $this;
  95. }
  96. }