src/CoreBundle/Entity/PeerUnit.php line 14

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\Common\Collections\ArrayCollection;
  4. use Doctrine\Common\Collections\Collection;
  5. use Doctrine\ORM\Mapping as ORM;
  6. use UserBundle\Entity\User;
  7. /**
  8. * @ORM\Table("peer_unit")
  9. * @ORM\Entity(repositoryClass="CoreBundle\Entity\PeerUnitRepository")
  10. */
  11. class PeerUnit
  12. {
  13. /**
  14. * @var int
  15. *
  16. * @ORM\Column(name="id", type="integer")
  17. * @ORM\Id
  18. * @ORM\GeneratedValue(strategy="AUTO")
  19. */
  20. private $id;
  21. /**
  22. * @var string
  23. *
  24. * @ORM\Column(name="name", type="string", nullable=true)
  25. */
  26. private $name;
  27. /**
  28. * @var PeerGroup
  29. *
  30. * @ORM\ManyToOne(targetEntity="CoreBundle\Entity\PeerGroup", inversedBy="peerUnits")
  31. * @ORM\JoinColumn(name="id_group", referencedColumnName="id", onDelete="CASCADE")
  32. */
  33. private $peerGroup;
  34. /**
  35. * @var PeerMathproblem
  36. *
  37. * @ORM\ManyToOne(targetEntity="CoreBundle\Entity\PeerMathproblem", inversedBy="peerUnits")
  38. * @ORM\JoinColumn(name="id_mathproblem", referencedColumnName="id", onDelete="CASCADE")
  39. */
  40. private $peerMathproblem;
  41. /**
  42. * @var ClassroomStudent[]
  43. *
  44. * @ORM\ManyToMany(targetEntity="ClassroomStudent", inversedBy="peerUnits")
  45. * @ORM\JoinTable(name="peer_rel_unit_student",
  46. * joinColumns={@ORM\JoinColumn(name="peer_unit_id", referencedColumnName="id")})
  47. * inverseJoinColumns={@ORM\JoinColumn(name="student_id", referencedColumnName="id")},
  48. */
  49. private $students;
  50. /**
  51. * @ORM\OneToMany(targetEntity="PeerStudent", mappedBy="peerUnit", cascade={"persist"})
  52. */
  53. private Collection $peerStudents;
  54. /**
  55. * @var ArrayCollection PeerFeedback
  56. *
  57. * @ORM\OneToMany(targetEntity="CoreBundle\Entity\PeerFeedback", mappedBy="peerUnit", cascade={"persist"})
  58. */
  59. private $peerFeedbacks;
  60. /**
  61. * @ORM\OneToOne(targetEntity="PeerSolution", mappedBy="peerUnit", cascade={"persist"})
  62. */
  63. private PeerSolution $peerSolution;
  64. /**
  65. * PeerUnit constructor.
  66. */
  67. public function __construct()
  68. {
  69. $this->peerFeedbacks = new ArrayCollection();
  70. $this->students = new ArrayCollection();
  71. $this->peerStudents = new ArrayCollection();
  72. }
  73. /**
  74. * @return int
  75. */
  76. public function getId(): int
  77. {
  78. return $this->id;
  79. }
  80. public function getName()
  81. {
  82. return $this->name;
  83. }
  84. public function setName(string $name)
  85. {
  86. $this->name = $name;
  87. }
  88. /**
  89. * @return PeerGroup
  90. */
  91. public function getPeerGroup(): PeerGroup
  92. {
  93. return $this->peerGroup;
  94. }
  95. /**
  96. * @param PeerGroup $peerGroup
  97. */
  98. public function setPeerGroup(PeerGroup $peerGroup)
  99. {
  100. $this->peerGroup = $peerGroup;
  101. }
  102. /**
  103. * @return PeerMathproblem
  104. */
  105. public function getPeerMathproblem(): PeerMathproblem
  106. {
  107. return $this->peerMathproblem;
  108. }
  109. /**
  110. * @param PeerMathproblem $peerMathproblem
  111. */
  112. public function setPeerMathproblem(PeerMathproblem $peerMathproblem)
  113. {
  114. $this->peerMathproblem = $peerMathproblem;
  115. }
  116. /**
  117. * @return ClassroomStudent[]|ArrayCollection
  118. */
  119. public function getStudents()
  120. {
  121. return $this->students;
  122. }
  123. public function addStudent(ClassroomStudent $student)
  124. {
  125. $this->students->add($student);
  126. }
  127. /**
  128. * @return ArrayCollection
  129. */
  130. public function getPeerFeedbacks(): ArrayCollection
  131. {
  132. return $this->peerFeedbacks;
  133. }
  134. public function addPeerFeedback(PeerFeedback $peerFeedback)
  135. {
  136. $peerFeedback->setPeerUnit($this);
  137. $this->peerFeedbacks->add($peerFeedback);
  138. }
  139. public function setPeerSolution(PeerSolution $peerSolution) : PeerUnit
  140. {
  141. $this->peerSolution = $peerSolution;
  142. return $this;
  143. }
  144. public function getPeerSolution(): PeerSolution
  145. {
  146. return $this->peerSolution;
  147. }
  148. public function addPeerStudent(PeerStudent $student)
  149. {
  150. $this->peerStudents->add($student);
  151. }
  152. /**
  153. * @return Collection|ArrayCollection|PeerStudent[]
  154. */
  155. public function getPeerStudents(): Collection
  156. {
  157. return $this->peerStudents;
  158. }
  159. public function getTeamleader(): ?User
  160. {
  161. foreach ($this->peerStudents as $peerStudent) {
  162. if ($peerStudent->getIsTeamLeader()) {
  163. return $peerStudent->getStudent();
  164. }
  165. }
  166. return null;
  167. }
  168. public function getSiblings()
  169. {
  170. $allUnits = $this->getPeerGroup()->getPeerUnits();
  171. $otherUnits = [];
  172. foreach ($allUnits as $unit) {
  173. if ($unit != $this) {
  174. $otherUnits[] = $unit;
  175. }
  176. }
  177. return $otherUnits;
  178. }
  179. }