src/Entity/Domain.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\User;
  4. use App\Entity\Course;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use App\Repository\DomainRepository;
  7. use Doctrine\Common\Collections\Collection;
  8. use Doctrine\Common\Collections\ArrayCollection;
  9. /**
  10. * @ORM\Entity(repositoryClass=DomainRepository::class)
  11. */
  12. class Domain
  13. {
  14. /**
  15. * @ORM\Id
  16. * @ORM\GeneratedValue
  17. * @ORM\Column(type="integer")
  18. */
  19. private $id;
  20. /**
  21. * @ORM\Column(type="string", length=255)
  22. */
  23. private $name;
  24. /**
  25. * @ORM\OneToMany(targetEntity=Course::class, mappedBy="domain")
  26. */
  27. private $courses;
  28. /**
  29. * @ORM\ManyToOne(targetEntity=User::class,inversedBy="headOfDepartementOf")
  30. * @ORM\JoinColumn(name="headOfDepartmentId", referencedColumnName="id", nullable=true)
  31. */
  32. private $headOfDepartment;
  33. /**
  34. * @ORM\OneToMany(targetEntity=User::class, mappedBy="domain")
  35. */
  36. private $teachers;
  37. public function __construct()
  38. {
  39. $this->courses = new ArrayCollection();
  40. $this->teachers = new ArrayCollection();
  41. }
  42. public function getId(): ?int
  43. {
  44. return $this->id;
  45. }
  46. public function getName(): ?string
  47. {
  48. return $this->name;
  49. }
  50. public function setName(string $name): self
  51. {
  52. $this->name = $name;
  53. return $this;
  54. }
  55. public function __toString() {
  56. $name = ( is_null($this->getName())) ? "" : $this->getName();
  57. return (string) ($name );
  58. }
  59. /**
  60. * @return Collection|Course[]
  61. */
  62. public function getCourses(): Collection
  63. {
  64. return $this->courses;
  65. }
  66. public function addCourse(Course $course): self
  67. {
  68. if (!$this->courses->contains($course)) {
  69. $this->courses[] = $course;
  70. $course->setDomain($this);
  71. }
  72. return $this;
  73. }
  74. public function removeCourse(Course $course): self
  75. {
  76. if ($this->courses->removeElement($course)) {
  77. // set the owning side to null (unless already changed)
  78. if ($course->getDomain() === $this) {
  79. $course->setDomain(null);
  80. }
  81. }
  82. return $this;
  83. }
  84. /**
  85. * @return Collection|User[]
  86. */
  87. public function getTeachers(): Collection
  88. {
  89. return $this->teachers;
  90. }
  91. public function addTeacher(User $teacher): self
  92. {
  93. if (!$this->teachers->contains($teacher)) {
  94. $this->teachers[] = $teacher;
  95. $teacher->setDomain($this);
  96. }
  97. return $this;
  98. }
  99. public function removeTeacher(User $teacher): self
  100. {
  101. if ($this->teachers->removeElement($teacher)) {
  102. // set the owning side to null (unless already changed)
  103. if ($teacher->getDomain() === $this) {
  104. $teacher->setDomain(null);
  105. }
  106. }
  107. return $this;
  108. }
  109. public function getHeadOfDepartment(): ?User
  110. {
  111. return $this->headOfDepartment;
  112. }
  113. public function setHeadOfDepartment(?User $headOfDepartment): self
  114. {
  115. $this->headOfDepartment = $headOfDepartment;
  116. return $this;
  117. }
  118. }