<?php
namespace App\Entity\Channel;
use App\Entity\Account\User;
use App\Entity\Chat\Resource;
use App\Entity\ResourceInterface;
use App\Enum\ResourceType;
use App\Repository\Channel\GroupRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Nellapp\Bundle\SDKBundle\Channel\Entity\ChannelInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Group\GroupInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Group\GroupMethodTrait;
use Symfony\Component\Serializer\Annotation as Serial;
#[
ORM\Entity(repositoryClass: GroupRepository::class),
ORM\Table(name: 'channel_groups'),
ORM\Index(columns: ['label'], flags: ['fulltext']),
]
class Group implements GroupInterface, ResourceInterface
{
use GroupMethodTrait;
#[ORM\Id, ORM\Column(type: 'string', length: 36)]
#[Serial\Groups(['Manager'])]
private ?string $id = null;
#[ORM\Column(type: 'string')]
#[Serial\Groups(['Manager'])]
private ?string $label = null;
#[
ORM\ManyToMany(targetEntity: User::class, inversedBy: 'groups'),
ORM\JoinTable(name: 'channel_group_users'),
ORM\InverseJoinColumn(name: 'user_id', nullable: false, onDelete: 'CASCADE'),
]
private ?Collection $users;
#[ORM\ManyToOne(targetEntity: Place::class)]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
private ?Place $place = null;
#[
ORM\ManyToOne(targetEntity: ChannelInterface::class),
ORM\JoinColumn(nullable: false),
]
private ?ChannelInterface $channel = null;
#[ORM\OneToOne(mappedBy: 'group', targetEntity: Session::class, cascade: ['persist', 'remove'])]
private ?Session $session = null;
#[ORM\OneToOne(targetEntity: Resource::class, cascade: ['persist', 'remove'])]
#[ORM\JoinColumn(nullable: true, onDelete: 'SET NULL')]
#[IdGroups(['Manager'])]
private ?Resource $resource = null;
public function __construct() {
$this->users = new ArrayCollection();
}
public function getSession(): ?Session
{
return $this->session;
}
public function getResource(): ?Resource
{
return $this->resource;
}
public function setResource(?Resource $resource): static
{
$this->resource = $resource;
return $this;
}
public function createResource(): void
{
$this->resource = new Resource();
$this->resource->setChannel($this->getChannel())->setDtype(ResourceType::GROUP);
if ($this->getSession()) {
$this->resource->setDtype(ResourceType::SESSION);
}
}
}