src/Entity/Section.php line 14

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