src/CoreBundle/Entity/NoteTestStudent.php line 21

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\DBAL\Types\Types;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\Validator\Constraints as Assert;
  8. use TheCodingMachine\GraphQLite\Annotations\Field;
  9. use TheCodingMachine\GraphQLite\Annotations\Type;
  10. /**
  11.  * NoteTestStudent
  12.  *
  13.  * @ORM\Table(name="note_test_student")
  14.  * @ORM\Entity(repositoryClass="CoreBundle\Repository\NoteTestStudentRepository")
  15.  * @Assert\Callback({"CoreBundle\Validator\NoteTestStudentValidator", "validate"})
  16.  */
  17. #[Type]
  18. class NoteTestStudent implements \JsonSerializable
  19. {
  20.     /**
  21.      * @var int
  22.      *
  23.      * @ORM\Column(name="id", type="integer")
  24.      * @ORM\Id
  25.      * @ORM\GeneratedValue(strategy="IDENTITY")
  26.      */
  27.     private $id;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity="NoteTest", inversedBy="noteTestStudents")
  30.      * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE", nullable=false)
  31.      */
  32.     private ?NoteTest $test;
  33.     /**
  34.      * @ORM\ManyToOne(targetEntity="Student", inversedBy="noteTestStudents")
  35.      * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE", nullable=false)
  36.      */
  37.     private ?Student $student;
  38.     /**
  39.      * @ORM\Column(type="float", nullable=true)
  40.      * @var float
  41.      */
  42.     private $note;
  43.     /**
  44.      * @ORM\Column(type="string", length=1, options={"default" : "p"})
  45.      * @var string
  46.      */
  47.     private $absence;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity="Tutor", inversedBy="noteTestStudents")
  50.      * @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE", nullable=true)
  51.      */
  52.     private ?Tutor $tutor;
  53.     /**
  54.      * @ORM\Column(type="datetime", nullable=true)
  55.      * @var \DateTime
  56.      */
  57.     private $createdOn;
  58.     /**
  59.      * @ORM\Column(type="datetime", nullable=true)
  60.      * @var \DateTime
  61.      */
  62.     private $updatedOn;
  63.     /**
  64.      * @ORM\OneToMany(targetEntity="NoteTestStudentLog", mappedBy="noteTestStudent")
  65.      * @ORM\OrderBy({"date": "desc"})
  66.      */
  67.     private $logs;
  68.     public function __construct()
  69.     {
  70.         $this->logs = new ArrayCollection();
  71.     }
  72.     #[Field]
  73.     public function getId(): ?int
  74.     {
  75.         return $this->id;
  76.     }
  77.     public function setNote(?float $note): self
  78.     {
  79.         $this->note $note;
  80.         return $this;
  81.     }
  82.     #[Field]
  83.     public function getNote(): ?float
  84.     {
  85.         return $this->note;
  86.     }
  87.     public function setAbsence(string $absence): self
  88.     {
  89.         $this->absence $absence;
  90.         return $this;
  91.     }
  92.     #[Field]
  93.     public function getAbsence(): string
  94.     {
  95.         return $this->absence;
  96.     }
  97.     public function setTest(NoteTest $test): self
  98.     {
  99.         $this->test $test;
  100.         return $this;
  101.     }
  102.     #[Field]
  103.     public function getTest(): NoteTest
  104.     {
  105.         return $this->test;
  106.     }
  107.     public function setStudent(Student $student): self
  108.     {
  109.         $this->student $student;
  110.         return $this;
  111.     }
  112.     public function getStudent(): Student
  113.     {
  114.         return $this->student;
  115.     }
  116.     public function isEmpty()
  117.     {
  118.         return empty($this->absence) && empty($this->note);
  119.     }
  120.     public function getCreatedOn(): ?\DateTimeInterface
  121.     {
  122.         return $this->createdOn;
  123.     }
  124.     public function setCreatedOn(?\DateTimeInterface $createdOn): self
  125.     {
  126.         $this->createdOn $createdOn;
  127.         return $this;
  128.     }
  129.     public function getUpdatedOn(): ?\DateTimeInterface
  130.     {
  131.         return $this->updatedOn;
  132.     }
  133.     public function setUpdatedOn(?\DateTimeInterface $updatedOn): self
  134.     {
  135.         $this->updatedOn $updatedOn;
  136.         return $this;
  137.     }
  138.     public function getTutor(): ?Tutor
  139.     {
  140.         return $this->tutor;
  141.     }
  142.     public function setTutor(?Tutor $tutor): self
  143.     {
  144.         $this->tutor $tutor;
  145.         return $this;
  146.     }
  147.     public function jsonSerialize()
  148.     {
  149.         return [
  150.             'id' => $this->id,
  151.             'student' => null !== $this->student ? [
  152.                 'id' => $this->student->getId(),
  153.                 'name' => $this->student->getName(),
  154.             ] : null,
  155.             'test' => null !== $this->test ? [
  156.                 'id' => $this->test->getId(),
  157.                 'module' => null !== $this->test->getModule() ? [
  158.                     'id' => $this->test->getModule()->getId(),
  159.                     'name' => $this->test->getModule()->getName(),
  160.                 ] : null,
  161.                 'branche' => null !== $this->test->getBranche() ? [
  162.                     'id' => $this->test->getBranche()->getId(),
  163.                     'name' => $this->test->getBranche()->getName(),
  164.                 ] : null
  165.             ] : null,
  166.             'note' => $this->note,
  167.             'absence' => $this->absence,
  168.             'tutor' => null !== $this->tutor ? [
  169.                 'id' => $this->tutor->getId(),
  170.                 'name' => $this->tutor->getName(),
  171.             ]: null
  172.         ];
  173.     }
  174.     /**
  175.      * @return Collection<int, NoteTestStudentLog>
  176.      */
  177.     public function getLogs(): Collection
  178.     {
  179.         return $this->logs;
  180.     }
  181.     public function addLog(NoteTestStudentLog $log): self
  182.     {
  183.         if (!$this->logs->contains($log)) {
  184.             $this->logs->add($log);
  185.             $log->setNoteTestStudent($this);
  186.         }
  187.         return $this;
  188.     }
  189.     public function removeLog(NoteTestStudentLog $log): self
  190.     {
  191.         if ($this->logs->removeElement($log)) {
  192.             // set the owning side to null (unless already changed)
  193.             if ($log->getNoteTestStudent() === $this) {
  194.                 $log->setNoteTestStudent(null);
  195.             }
  196.         }
  197.         return $this;
  198.     }
  199. }