<?php
namespace App\Entity\Chat;
use App\Entity\Channel\Channel;
use App\Repository\ResourceRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Drosalys\Bundle\ApiBundle\Serializer\Attributes\IdGroups;
use Symfony\Component\Serializer\Annotation as Serial;
#[ORM\Entity(repositoryClass: ResourceRepository::class)]
#[ORM\Table(name: 'chat_resources')]
class Resource
{
#[
ORM\Id, ORM\GeneratedValue,
ORM\Column(type: 'integer'),
]
#[Serial\Groups(['Resource'])]
#[IdGroups(groups: ['PostCanal'])]
protected ?int $id = null;
#[ORM\ManyToMany(targetEntity: Canal::class, mappedBy: 'resources')]
private Collection $canals;
#[ORM\Column(type: 'string', nullable: false)]
#[Serial\Groups(['Resource'])]
private ?string $dtype = null;
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Channel $channel = null;
public function __construct()
{
$this->canals = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
/**
* @return Collection<int, Canal>
*/
public function getCanals(): Collection
{
return $this->canals ?? $this->canals = new ArrayCollection();
}
public function addCanal(Canal $canal): self
{
if (!$this->getCanals()->contains($canal)) {
$this->getCanals()->add($canal);
$canal->addResource($this);
}
return $this;
}
public function removeCanal(Canal $canal): self
{
if ($this->canals->removeElement($canal)) {
// set the owning side to null (unless already changed)
if ($canal->getResources()->contains($this)) {
$canal->removeResource($this);
}
}
return $this;
}
public function getDtype(): ?string
{
return $this->dtype;
}
public function setDtype(?string $dtype): Resource
{
$this->dtype = $dtype;
return $this;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): Resource
{
$this->channel = $channel;
return $this;
}
}