src/Entity/Channel/Service.php line 26

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Account\User;
  4. use App\Entity\Sync\SyncableInterface;
  5. use App\Repository\Channel\ServiceRepository;
  6. use Doctrine\Common\Collections\ArrayCollection;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\ORM\Mapping as ORM;
  9. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  10. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampInterface;
  11. use DrosalysWeb\ObjectExtensions\Timestamp\Model\TimestampTrait;
  12. use Nellapp\Bundle\SDKBundle\Auth\Entity\UserInterface;
  13. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  14. use Nellapp\Bundle\SDKBundle\Channel\Entity\Service\ServiceInterface;
  15. use Nellapp\Bundle\SDKBundle\Channel\Entity\Service\ServiceMethodTrait;
  16. use Nellapp\Bundle\SDKBundle\Permission\Entity\ChannelResourceInterface;
  17. use Nellapp\Bundle\SDKBundle\Permission\UsersResource\UsersResourceInterface;
  18. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  19. use Symfony\Component\Serializer\Annotation as Serial;
  20. use Symfony\Component\Validator\Constraints as Assert;
  21. #[ORM\Entity(repositoryClass: ServiceRepository::class)]
  22. #[ORM\Table(name: 'channel_services')]
  23. class Service implements TimestampInterface, SyncableInterface, ServiceInterface, ChannelResourceInterface, UsersResourceInterface
  24. {
  25. use TimestampTrait;
  26. use ServiceMethodTrait;
  27. #[ORM\Id]
  28. #[ORM\GeneratedValue]
  29. #[ORM\Column(type: 'integer')]
  30. #[Serial\Groups(['Sync', 'Manager'])]
  31. private ?int $id = null;
  32. #[ORM\Column(type: 'string', length: 255)]
  33. #[
  34. Assert\NotBlank(message: 'entity.channel.service.name.NotBlank'),
  35. Assert\Length(
  36. min: 2,
  37. max: 255,
  38. minMessage: 'entity.channel.service.name.min',
  39. maxMessage: 'entity.channel.service.name.max',
  40. )
  41. ]
  42. #[Serial\Groups(['Sync', 'Manager'])]
  43. private ?string $label = null;
  44. #[
  45. ORM\ManyToMany(targetEntity: User::class, inversedBy: 'services', cascade: ['persist']),
  46. ORM\JoinTable('channel_service_users')
  47. ]
  48. #[IdGroups(['Sync'])]
  49. private Collection $users;
  50. #[
  51. ORM\ManyToOne(targetEntity: Channel::class),
  52. ORM\JoinColumn(nullable: false, onDelete: 'CASCADE'),
  53. ]
  54. #[IdGroups(['Sync'])]
  55. private ?Channel $channel = null;
  56. #[ORM\Column(type: 'boolean', nullable: false)]
  57. #[Serial\Groups(['Sync'])]
  58. private ?bool $enableOnNim = null;
  59. public function __construct()
  60. {
  61. $this->users = new ArrayCollection();
  62. }
  63. public static function getSyncKey(): string
  64. {
  65. return EntityKeys::CHANNEL_SERVICE;
  66. }
  67. public function getSyncDisplayLabel(): string
  68. {
  69. return (string) $this->getLabel();
  70. }
  71. public static function getPermissionResourceClass(): ?string
  72. {
  73. return ChannelUserServicePermission::class;
  74. }
  75. public function getOwnerChannel(): ?ChannelInterface
  76. {
  77. return $this->getChannel();
  78. }
  79. public function __toString(): string
  80. {
  81. return $this->getLabel();
  82. }
  83. public function hasUser(?UserInterface $user, array $tags = []): bool
  84. {
  85. if (!$user instanceof User) {
  86. return false;
  87. }
  88. return $this->getUsers()->contains($user);
  89. }
  90. }