<?php
namespace App\Entity\Channel;
use App\Entity\Sync\SyncableInterface;
use App\Repository\Channel\PlaceRepository;
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\Place\PlaceInterface;
use Nellapp\Bundle\SDKBundle\Channel\Entity\Place\PlaceMethodTrait;
use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
use Symfony\Component\Serializer\Annotation as Serial;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: PlaceRepository::class),
ORM\Index(columns: ['label'], flags: ['fulltext']),
ORM\Table(name: 'channel_places')
]
class Place implements PlaceInterface, SyncableInterface
{
use PlaceMethodTrait;
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
#[Serial\Groups(['Sync', 'Manager'])]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255)]
#[
Assert\NotBlank(message: 'place.label.NotBlank'),
Assert\Length(
min: 2,
max: 255,
minMessage: 'place.length.min',
maxMessage: 'place.length.max'
)
]
#[Serial\Groups(['Manager', 'Sync'])]
private ?string $label = null;
#[ORM\OneToMany(mappedBy: 'place', targetEntity: Room::class, cascade: ['persist', 'remove'])]
#[IdGroups(['Sync'])]
private ?Collection $rooms;
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
#[IdGroups(['Sync'])]
private ?Channel $channel = null;
public function __construct()
{
$this->rooms = new ArrayCollection();
}
public static function getSyncKey(): string
{
return EntityKeys::CHANNEL_PLACE;
}
public function getSyncDisplayLabel(): string
{
return $this->getLabel() ?? '';
}
}