src/Entity/Cycle.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CycleRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  8. /**
  9. * @ORM\Entity(repositoryClass=CycleRepository::class)
  10. * @UniqueEntity(
  11. * fields={"name"},
  12. * message="Un cycle porte deja ce nom."
  13. * )
  14. */
  15. class Cycle
  16. {
  17. /**
  18. * @ORM\Id
  19. * @ORM\GeneratedValue
  20. * @ORM\Column(type="integer")
  21. */
  22. private $id;
  23. /**
  24. * @ORM\ManyToOne(targetEntity=Section::class, inversedBy="cycles")
  25. * @ORM\JoinColumn(nullable=false)
  26. */
  27. private $section;
  28. /**
  29. * @ORM\Column(type="string", length=255)
  30. */
  31. private $name;
  32. /**
  33. * @ORM\OneToMany(targetEntity=Level::class, mappedBy="cycle")
  34. */
  35. private $levels;
  36. public function __construct()
  37. {
  38. $this->levels = new ArrayCollection();
  39. }
  40. public function getId(): ?int
  41. {
  42. return $this->id;
  43. }
  44. public function getSection(): ?Section
  45. {
  46. return $this->section;
  47. }
  48. public function setSection(?Section $section): self
  49. {
  50. $this->section = $section;
  51. return $this;
  52. }
  53. public function getName(): ?string
  54. {
  55. return $this->name;
  56. }
  57. public function setName(string $name): self
  58. {
  59. $this->name = $name;
  60. return $this;
  61. }
  62. public function __toString()
  63. {
  64. $name = (is_null($this->getName())) ? "" : $this->getName();
  65. $section = (is_null($this->getSection())) ? "" : $this->getSection();
  66. return (string) ($section . "/" . $name);
  67. }
  68. /**
  69. * @return Collection|Level[]
  70. */
  71. public function getLevels(): Collection
  72. {
  73. return $this->levels;
  74. }
  75. public function addLevel(Level $level): self
  76. {
  77. if (!$this->levels->contains($level)) {
  78. $this->levels[] = $level;
  79. $level->setCycle($this);
  80. }
  81. return $this;
  82. }
  83. public function removeLevel(Level $level): self
  84. {
  85. if ($this->levels->removeElement($level)) {
  86. // set the owning side to null (unless already changed)
  87. if ($level->getCycle() === $this) {
  88. $level->setCycle(null);
  89. }
  90. }
  91. return $this;
  92. }
  93. }