src/Entity/Channel/Material.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Channel;
  3. use App\Repository\Channel\MaterialRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\JoinTable;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. #[
  10. ORM\Entity(repositoryClass: MaterialRepository::class),
  11. ORM\Table(name: 'channel_materials')
  12. ]
  13. class Material
  14. {
  15. #[ORM\Id, ORM\GeneratedValue, ORM\Column(type: 'integer')]
  16. private ?int $id = null;
  17. #[ORM\Column(type: 'string', length: 255, nullable: false)]
  18. #[
  19. Assert\NotBlank(message: 'material.name.NotBlank'),
  20. Assert\Length(
  21. min: 2,
  22. max: 255,
  23. minMessage: 'material.length.min',
  24. maxMessage: 'material.length.max'
  25. )
  26. ]
  27. private ?string $name = null;
  28. #[ORM\ManyToMany(targetEntity: Room::class, inversedBy: 'materials')]
  29. #[JoinTable(name: 'channel_rooms_materials')]
  30. private ?Collection $rooms;
  31. #[ORM\ManyToOne(targetEntity: Channel::class)]
  32. #[ORM\JoinColumn(nullable: false, onDelete: 'CASCADE')]
  33. private ?Channel $channel;
  34. public function __construct()
  35. {
  36. $this->rooms = new ArrayCollection();
  37. }
  38. public function getId(): ?int
  39. {
  40. return $this->id;
  41. }
  42. public function getName(): ?string
  43. {
  44. return $this->name;
  45. }
  46. public function setName(?string $name): self
  47. {
  48. $this->name = $name;
  49. return $this;
  50. }
  51. public function getRooms(): Collection
  52. {
  53. return $this->rooms;
  54. }
  55. public function addRoom(Room $room): self
  56. {
  57. if (!$this->rooms->contains($room)) {
  58. $this->rooms[] = $room;
  59. }
  60. return $this;
  61. }
  62. public function removeRoom(Room $room): self
  63. {
  64. if ($this->rooms->contains($room)) {
  65. $this->rooms->removeElement($room);
  66. }
  67. return $this;
  68. }
  69. public function getChannel(): ?Channel
  70. {
  71. return $this->channel;
  72. }
  73. public function setChannel(?Channel $channel): self
  74. {
  75. $this->channel = $channel;
  76. return $this;
  77. }
  78. }