src/Entity/Channel/Group.php line 23

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\GroupRepository;
  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\Channel\Entity\Group\GroupInterface;
  13. use Nellapp\Bundle\SDKBundle\Channel\Entity\Group\GroupMethodTrait;
  14. use Nellapp\Bundle\SDKBundle\Channel\Entity\Place\PlaceInterface;
  15. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  16. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  17. use Symfony\Component\Serializer\Annotation as Serial;
  18. use Symfony\Component\Validator\Constraints as Assert;
  19. #[ORM\Entity(repositoryClass: GroupRepository::class), ORM\Table(name: 'channel_groups')]
  20. class Group implements SyncableInterface, GroupInterface, TimestampInterface
  21. {
  22.     use GroupMethodTrait;
  23.     use TimestampTrait;
  24.     #[ORM\Id, ORM\GeneratedValue(strategy: 'CUSTOM'), ORM\CustomIdGenerator(class: UuidGenerator::class), ORM\Column(type: 'string', length: 36)]
  25.     #[Serial\Groups(['Manager', 'Sync'])]
  26.     private ?string $id = null;
  27.     #[ORM\Column(type: 'string', length: 255)]
  28.     #[Serial\Groups(['Manager', 'Sync', 'GroupPostManager'])]
  29.     #[
  30.         Assert\NotBlank(message: 'channel.group.label.NotBlank', groups: ['Default', 'flow_sessionCreate_step1']),
  31.         Assert\Length(
  32.             min: 2,
  33.             max: 255,
  34.             minMessage: 'channel.group.label.Length.min',
  35.             maxMessage: 'channel.group.label.Length.max',
  36.             groups: ['Default', 'flow_sessionCreate_step1']
  37.         )
  38.     ]
  39.     private ?string $label = null;
  40.     #[ORM\ManyToOne(targetEntity: Place::class)]
  41.     #[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
  42.     #[Assert\NotBlank(groups: ['Default', 'flow_sessionCreate_step1'])]
  43.     #[IdGroups(groups: 'Sync')]
  44.     private ?Place $place = null;
  45.     #[ORM\ManyToMany(targetEntity: User::class, inversedBy: 'groups', cascade: ['persist']), ORM\JoinTable(name: 'channel_group_users')]
  46.     #[IdGroups(['Sync'])]
  47.     private ?Collection $users;
  48.     #[ORM\ManyToOne(targetEntity: Channel::class), ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  49.     #[IdGroups(['Sync'])]
  50.     private ?Channel $channel;
  51.     #[ORM\OneToOne(mappedBy: 'group', targetEntity: Session::class, cascade: ['persist', 'remove'])]
  52.     private ?Session $session = null;
  53.     public static function getSyncKey(): string
  54.     {
  55.         return EntityKeys::CHANNEL_GROUP;
  56.     }
  57.     public function getSyncDisplayLabel(): string
  58.     {
  59.         return (string) $this->getLabel();
  60.     }
  61.     public function __construct()
  62.     {
  63.         $this->users = new ArrayCollection();
  64.     }
  65.     /**
  66.      * @return int[]
  67.      */
  68.     public function getUserIds(): array
  69.     {
  70.         return array_map(function (User $user) {
  71.             return $user->getId();
  72.         }, $this->getUsers()->toArray());
  73.     }
  74.     public function getSession(): ?Session
  75.     {
  76.         return $this->session;
  77.     }
  78.     public function setSession(?Session $session): static
  79.     {
  80.         $this->session = $session;
  81.         return $this;
  82.     }
  83.     public function getPlace(): ?Place
  84.     {
  85.         return $this->place;
  86.     }
  87.     public function setPlace(?PlaceInterface $place): static
  88.     {
  89.         $this->place = $place;
  90.         return $this;
  91.     }
  92. }