src/Entity/Channel/Group.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Account\User;
  4. use App\Entity\Chat\Resource;
  5. use App\Entity\ResourceInterface;
  6. use App\Enum\ResourceType;
  7. use App\Repository\Channel\GroupRepository;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. use Doctrine\Common\Collections\Collection;
  10. use Doctrine\ORM\Mapping as ORM;
  11. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  12. use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
  13. use Nellapp\Bundle\SDKBundle\Channel\Entity\Group\GroupInterface;
  14. use Nellapp\Bundle\SDKBundle\Channel\Entity\Group\GroupMethodTrait;
  15. use Symfony\Component\Serializer\Annotation as Serial;
  16. #[
  17.     ORM\Entity(repositoryClassGroupRepository::class),
  18.     ORM\Table(name'channel_groups'),
  19.     ORM\Index(columns: ['label'], flags: ['fulltext']),
  20. ]
  21. class Group implements GroupInterfaceResourceInterface
  22. {
  23.     use GroupMethodTrait;
  24.     #[ORM\IdORM\Column(type'string'length36)]
  25.     #[Serial\Groups(['Manager'])]
  26.     private ?string $id null;
  27.     #[ORM\Column(type'string')]
  28.     #[Serial\Groups(['Manager'])]
  29.     private ?string $label null;
  30.     #[
  31.         ORM\ManyToMany(targetEntityUser::class, inversedBy'groups'),
  32.         ORM\JoinTable(name'channel_group_users'),
  33.         ORM\InverseJoinColumn(name'user_id'nullablefalseonDelete'CASCADE'),
  34.     ]
  35.     private ?Collection $users;
  36.     #[ORM\ManyToOne(targetEntityPlace::class)]
  37.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  38.     private ?Place $place null;
  39.     #[
  40.         ORM\ManyToOne(targetEntityChannelInterface::class),
  41.         ORM\JoinColumn(nullablefalse),
  42.     ]
  43.     private ?ChannelInterface $channel null;
  44.     #[ORM\OneToOne(mappedBy'group'targetEntitySession::class, cascade: ['persist''remove'])]
  45.     private ?Session $session null;
  46.     #[ORM\OneToOne(targetEntityResource::class, cascade: ['persist''remove'])]
  47.     #[ORM\JoinColumn(nullabletrueonDelete'SET NULL')]
  48.     #[IdGroups(['Manager'])]
  49.     private ?Resource $resource null;
  50.     public function __construct() {
  51.         $this->users = new ArrayCollection();
  52.     }
  53.     public function getSession(): ?Session
  54.     {
  55.         return $this->session;
  56.     }
  57.     public function getResource(): ?Resource
  58.     {
  59.         return $this->resource;
  60.     }
  61.     public function setResource(?Resource $resource): static
  62.     {
  63.         $this->resource $resource;
  64.         return $this;
  65.     }
  66.     public function createResource(): void
  67.     {
  68.         $this->resource = new Resource();
  69.         $this->resource->setChannel($this->getChannel())->setDtype(ResourceType::GROUP);
  70.         if ($this->getSession()) {
  71.             $this->resource->setDtype(ResourceType::SESSION);
  72.         }
  73.     }
  74. }