src/Entity/Channel/Room.php line 23

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Entity\Sync\SyncableInterface;
  4. use App\Repository\Channel\RoomRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
  9. use Nellapp\Bundle\SDKBundle\Channel\Entity\Room\RoomInterface;
  10. use Nellapp\Bundle\SDKBundle\Channel\Entity\Room\RoomMethodTrait;
  11. use Nellapp\Bundle\SDKBundle\Sync\EntityKeys;
  12. use Symfony\Bridge\Doctrine\IdGenerator\UuidGenerator;
  13. use Symfony\Component\Serializer\Annotation as Serial;
  14. use Symfony\Component\Validator\Constraints as Assert;
  15. #[
  16.     ORM\Entity(repositoryClassRoomRepository::class),
  17.     ORM\Index(columns: ['name'], flags: ['fulltext']),
  18.     ORM\Table(name'channel_rooms')
  19. ]
  20. class Room implements RoomInterfaceSyncableInterface
  21. {
  22.     use RoomMethodTrait;
  23.     #[ORM\IdORM\GeneratedValue(strategy'CUSTOM'), ORM\CustomIdGenerator(class: UuidGenerator::class), ORM\Column(type'string'length36)]
  24.     #[Serial\Groups(['Manager''Sync'])]
  25.     private ?string $id null;
  26.     #[ORM\Column(type'string'length255nullablefalse)]
  27.     #[
  28.         Assert\NotBlank(message'room.name.NotBlank'),
  29.         Assert\Length(
  30.             min2,
  31.             max255,
  32.             minMessage'base.length.min',
  33.             maxMessage'base.length.max'
  34.         )
  35.     ]
  36.     #[Serial\Groups(['Manager''Sync'])]
  37.     private ?string $name null;
  38.     #[ORM\Column(type'integer'nullablefalse)]
  39.     #[Assert\NotBlank(message'room.capacity.NotBlank')]
  40.     #[Serial\Groups(['Manager''Sync'])]
  41.     private ?int $capacity null;
  42.     #[ORM\ManyToMany(targetEntityMaterial::class, mappedBy'rooms')]
  43.     #[Serial\Groups(['Manager'])]
  44.     private ?Collection $materials;
  45.     #[ORM\ManyToOne(targetEntityPlace::class, inversedBy'rooms')]
  46.     #[ORM\JoinColumn(nullablefalse)]
  47.     #[IdGroups(groups: ['Sync'])]
  48.     private ?Place $place null;
  49.     public function __construct()
  50.     {
  51.         $this->materials = new ArrayCollection();
  52.     }
  53.     public static function getSyncKey(): string
  54.     {
  55.         return EntityKeys::CHANNEL_ROOM;
  56.     }
  57.     public function getSyncDisplayLabel(): string
  58.     {
  59.         return (string) $this->getName();
  60.     }
  61.     public function getMaterials(): Collection
  62.     {
  63.         return $this->materials;
  64.     }
  65.     public function addMaterial(Material $material): self
  66.     {
  67.         if (!$this->materials->contains($material)) {
  68.             $this->materials[] = $material;
  69.             $material->addRoom($this);
  70.         }
  71.         return $this;
  72.     }
  73.     public function removeMaterial(Material $material): self
  74.     {
  75.         if ($this->materials->contains($material)) {
  76.             $this->materials->removeElement($material);
  77.             $material->removeRoom($this);
  78.         }
  79.         return $this;
  80.     }
  81. }