<?php
namespace App\Entity\Channel;
use App\Repository\Channel\MaterialRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\JoinTable;
use Symfony\Component\Validator\Constraints as Assert;
#[
ORM\Entity(repositoryClass: MaterialRepository::class),
ORM\Table(name: 'channel_materials')
]
class Material
{
#[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
private ?int $id = null;
#[ORM\Column(type: 'string', length: 255, nullable: false)]
#[
Assert\NotBlank(message: 'material.name.NotBlank'),
Assert\Length(
min: 2,
max: 255,
minMessage: 'material.length.min',
maxMessage: 'material.length.max'
)
]
private ?string $name = null;
#[ORM\ManyToMany(targetEntity: Room::class, inversedBy: 'materials')]
#[JoinTable(name: 'channel_rooms_materials')]
private ?Collection $rooms;
#[ORM\ManyToOne(targetEntity: Channel::class)]
#[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
private ?Channel $channel;
public function __construct()
{
$this->rooms = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(?string $name): self
{
$this->name = $name;
return $this;
}
public function getRooms(): Collection
{
return $this->rooms;
}
public function addRoom(Room $room): self
{
if (!$this->rooms->contains($room)) {
$this->rooms[] = $room;
}
return $this;
}
public function removeRoom(Room $room): self
{
if ($this->rooms->contains($room)) {
$this->rooms->removeElement($room);
}
return $this;
}
public function getChannel(): ?Channel
{
return $this->channel;
}
public function setChannel(?Channel $channel): self
{
$this->channel = $channel;
return $this;
}
}