src/Entity/Chat/Canal.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Chat;
  3. use App\Enum\ConversationType;
  4. use App\Repository\Chat\CanalRepository;
  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 Symfony\Component\Serializer\Annotation as Serial;
  10. use Symfony\Component\Validator\Constraints as Assert;
  11. #[ORM\Entity(repositoryClassCanalRepository::class)]
  12. #[ORM\Table(name'chat_canals')]
  13. class Canal extends Conversation
  14. {
  15.     #[ORM\Column(type'string'length255)]
  16.     #[
  17.         Assert\NotBlank(message'entity.tchat.canal.label.NotBlank'),
  18.         Assert\Length(
  19.             min2,
  20.             max255,
  21.             minMessage'entity.tchat.canal.label.min',
  22.             maxMessage'entity.tchat.canal.label.max',
  23.         )
  24.     ]
  25.     #[Serial\Groups(groups: ['Conversation''PostCanal''Identifier''PutCanal'])]
  26.     private ?string $label null;
  27.     #[ORM\Column(type'text'nullabletrue)]
  28.     #[
  29.         Assert\Length(
  30.             min2,
  31.             max5000,
  32.             minMessage'entity.tchat.canal.description.min',
  33.             maxMessage'entity.tchat.canal.description.max',
  34.         )
  35.     ]
  36.     #[Serial\Groups(groups: ['Conversation''PostCanal''PutCanal'])]
  37.     private ?string $description null;
  38.     #[ORM\ManyToMany(targetEntityResource::class, inversedBy'canals')]
  39.     #[ORM\JoinTable(name'chat_canal_resources')]
  40.     #[IdGroups(groups: ['PostCanal'])]
  41.     #[Serial\Context(
  42.         context: ['entity_id_groups' => true]
  43.     )]
  44.     private Collection $resources;
  45.     #[ORM\Column(type'integer'nullablefalseoptions: ['default' => 2])]
  46.     #[
  47.         Assert\NotBlank()
  48.     ]
  49.     #[Serial\Groups(groups: ['Conversation''PostCanal''PutCanal'])]
  50.     private ?int $openTo null;
  51.     #[ORM\Column(type'boolean'nullablefalse)]
  52.     private ?bool $autoCreation false;
  53.     public function __construct()
  54.     {
  55.         $this->resources = new ArrayCollection();
  56.         parent::__construct();
  57.     }
  58.     public function getLabel(): ?string
  59.     {
  60.         return $this->label;
  61.     }
  62.     public function setLabel(string $label): self
  63.     {
  64.         $this->label $label;
  65.         return $this;
  66.     }
  67.     public function getDescription(): ?string
  68.     {
  69.         return $this->description;
  70.     }
  71.     public function setDescription(?string $description): self
  72.     {
  73.         $this->description $description;
  74.         return $this;
  75.     }
  76.     public function isPublic(): ?bool
  77.     {
  78.         return $this->getType() === ConversationType::CANAL_PUBLIC;
  79.     }
  80.     public function hasResources(): bool
  81.     {
  82.         return !$this->getResources()->isEmpty();
  83.     }
  84.     public function getResources(): Collection
  85.     {
  86.         return $this->resources ?? $this->resources = new ArrayCollection();
  87.     }
  88.     public function setResources(Collection $resources): Canal
  89.     {
  90.         $this->resources $resources;
  91.         return $this;
  92.     }
  93.     public function addResource(Resource $resource): self
  94.     {
  95.         if (!$this->getResources()->contains($resource)) {
  96.             $this->getResources()->add($resource);
  97.         }
  98.         return $this;
  99.     }
  100.     public function removeResource(Resource $resource): self
  101.     {
  102.         $this->getResources()->removeElement($resource);
  103.         return $this;
  104.     }
  105.     public function getOpenTo(): ?int
  106.     {
  107.         return $this->openTo;
  108.     }
  109.     public function setOpenTo(?int $openTo): Canal
  110.     {
  111.         $this->openTo $openTo;
  112.         return $this;
  113.     }
  114.     public function getAutoCreation(): ?bool
  115.     {
  116.         return $this->autoCreation;
  117.     }
  118.     public function setAutoCreation(?bool $autoCreation): Canal
  119.     {
  120.         $this->autoCreation $autoCreation;
  121.         return $this;
  122.     }
  123. }