src/CoreBundle/Entity/ClassroomStudent.php line 19

Open in your IDE?
  1. <?php
  2. namespace CoreBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
  5. use JsonSerializable;
  6. use UserBundle\Entity\User;
  7. /**
  8. * @ORM\Table("classroom_student")
  9. * @ORM\Entity(repositoryClass="CoreBundle\Entity\ClassroomStudentRepository")
  10. * @UniqueEntity(
  11. * fields={"student", "classroom"},
  12. * errorPath="classroom",
  13. * message="Student is already in the classroom"
  14. * )
  15. */
  16. class ClassroomStudent implements JsonSerializable
  17. {
  18. /**
  19. * @var int
  20. *
  21. * @ORM\Column(name="id", type="integer")
  22. * @ORM\Id
  23. * @ORM\GeneratedValue(strategy="AUTO")
  24. */
  25. private $id;
  26. /**
  27. * @var User
  28. *
  29. * @ORM\ManyToOne(targetEntity="UserBundle\Entity\User",fetch="EAGER", cascade={"persist"})
  30. * @ORM\JoinColumn(name="user_id", referencedColumnName="id")
  31. */
  32. private $student;
  33. /**
  34. * @var Classroom
  35. *
  36. * @ORM\ManyToOne(targetEntity="Classroom", inversedBy="members")
  37. * @ORM\JoinColumn(name="classroom_id", referencedColumnName="id", onDelete="CASCADE")
  38. */
  39. private $classroom;
  40. /**
  41. * @ORM\ManyToMany(targetEntity="CoreBundle\Entity\PeerUnit", mappedBy="students")
  42. */
  43. private $peerUnits;
  44. /**
  45. * Get id.
  46. *
  47. * @return int
  48. */
  49. public function getId()
  50. {
  51. return $this->id;
  52. }
  53. /**
  54. * Set student.
  55. *
  56. * @param User $student
  57. *
  58. * @return ClassroomStudent
  59. */
  60. public function setStudent($student)
  61. {
  62. $this->student = $student;
  63. return $this;
  64. }
  65. /**
  66. * Get student.
  67. *
  68. * @return User
  69. */
  70. public function getStudent()
  71. {
  72. return $this->student;
  73. }
  74. /**
  75. * Set classroom.
  76. *
  77. * @param Classroom $classroom
  78. *
  79. * @return ClassroomStudent
  80. */
  81. public function setClassroom($classroom)
  82. {
  83. $this->classroom = $classroom;
  84. return $this;
  85. }
  86. public function getPeerUnits()
  87. {
  88. return $this->peerUnits;
  89. }
  90. /**
  91. * @return Classroom
  92. */
  93. public function getClassroom()
  94. {
  95. return $this->classroom;
  96. }
  97. public function jsonSerialize(): mixed
  98. {
  99. return [
  100. "id" => $this->getId(),
  101. "student" => $this->getStudent(),
  102. "peerUnits" => $this->getPeerUnits()
  103. ];
  104. }
  105. }