<?php
namespace CoreBundle\Entity;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use TheCodingMachine\GraphQLite\Annotations\Field;
use TheCodingMachine\GraphQLite\Annotations\Type;
/**
* NoteTestStudent
*
* @ORM\Table(name="note_test_student")
* @ORM\Entity(repositoryClass="CoreBundle\Repository\NoteTestStudentRepository")
* @Assert\Callback({"CoreBundle\Validator\NoteTestStudentValidator", "validate"})
*/
#[Type]
class NoteTestStudent implements \JsonSerializable
{
/**
* @var int
*
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity="NoteTest", inversedBy="noteTestStudents")
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private ?NoteTest $test;
/**
* @ORM\ManyToOne(targetEntity="Student", inversedBy="noteTestStudents")
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE", nullable=false)
*/
private ?Student $student;
/**
* @ORM\Column(type="float", nullable=true)
* @var float
*/
private $note;
/**
* @ORM\Column(type="string", length=1, options={"default" : "p"})
* @var string
*/
private $absence;
/**
* @ORM\ManyToOne(targetEntity="Tutor", inversedBy="noteTestStudents")
* @ORM\JoinColumn(referencedColumnName="id", onDelete="CASCADE", nullable=true)
*/
private ?Tutor $tutor;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
*/
private $createdOn;
/**
* @ORM\Column(type="datetime", nullable=true)
* @var \DateTime
*/
private $updatedOn;
/**
* @ORM\OneToMany(targetEntity="NoteTestStudentLog", mappedBy="noteTestStudent")
* @ORM\OrderBy({"date": "desc"})
*/
private $logs;
public function __construct()
{
$this->logs = new ArrayCollection();
}
#[Field]
public function getId(): ?int
{
return $this->id;
}
public function setNote(?float $note): self
{
$this->note = $note;
return $this;
}
#[Field]
public function getNote(): ?float
{
return $this->note;
}
public function setAbsence(string $absence): self
{
$this->absence = $absence;
return $this;
}
#[Field]
public function getAbsence(): string
{
return $this->absence;
}
public function setTest(NoteTest $test): self
{
$this->test = $test;
return $this;
}
#[Field]
public function getTest(): NoteTest
{
return $this->test;
}
public function setStudent(Student $student): self
{
$this->student = $student;
return $this;
}
public function getStudent(): Student
{
return $this->student;
}
public function isEmpty()
{
return empty($this->absence) && empty($this->note);
}
public function getCreatedOn(): ?\DateTimeInterface
{
return $this->createdOn;
}
public function setCreatedOn(?\DateTimeInterface $createdOn): self
{
$this->createdOn = $createdOn;
return $this;
}
public function getUpdatedOn(): ?\DateTimeInterface
{
return $this->updatedOn;
}
public function setUpdatedOn(?\DateTimeInterface $updatedOn): self
{
$this->updatedOn = $updatedOn;
return $this;
}
public function getTutor(): ?Tutor
{
return $this->tutor;
}
public function setTutor(?Tutor $tutor): self
{
$this->tutor = $tutor;
return $this;
}
public function jsonSerialize()
{
return [
'id' => $this->id,
'student' => null !== $this->student ? [
'id' => $this->student->getId(),
'name' => $this->student->getName(),
] : null,
'test' => null !== $this->test ? [
'id' => $this->test->getId(),
'module' => null !== $this->test->getModule() ? [
'id' => $this->test->getModule()->getId(),
'name' => $this->test->getModule()->getName(),
] : null,
'branche' => null !== $this->test->getBranche() ? [
'id' => $this->test->getBranche()->getId(),
'name' => $this->test->getBranche()->getName(),
] : null
] : null,
'note' => $this->note,
'absence' => $this->absence,
'tutor' => null !== $this->tutor ? [
'id' => $this->tutor->getId(),
'name' => $this->tutor->getName(),
]: null
];
}
/**
* @return Collection<int, NoteTestStudentLog>
*/
public function getLogs(): Collection
{
return $this->logs;
}
public function addLog(NoteTestStudentLog $log): self
{
if (!$this->logs->contains($log)) {
$this->logs->add($log);
$log->setNoteTestStudent($this);
}
return $this;
}
public function removeLog(NoteTestStudentLog $log): self
{
if ($this->logs->removeElement($log)) {
// set the owning side to null (unless already changed)
if ($log->getNoteTestStudent() === $this) {
$log->setNoteTestStudent(null);
}
}
return $this;
}
}