<?php
namespace App\Entity;
use App\Repository\StudentYearRepository;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use App\Entity\Traits\Timestampable;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Doctrine\ORM\Mapping\HasLifecycleCallbacks;
use JMS\Serializer\Annotation\Groups;
#[ORM\HasLifecycleCallbacks]
#[Vich\Uploadable]
#[ORM\Entity(repositoryClass: StudentYearRepository::class)]
class StudentYear
{
use Timestampable;
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
#[Groups(['getStudents'])]
private ?int $id = null;
#[ORM\ManyToOne(inversedBy: 'studentYears', cascade: ["persist"])]
#[Groups(['getStudents'])]
private ?SchoolYear $year = null;
#[ORM\ManyToOne(inversedBy: 'studentYears', cascade: ["persist"])]
#[Groups(['getStudents','getExamStudent'])]
private ?Student $student = null;
/**
* NOTE: This is not a mapped field of entity metadata, just a simple property.
*
*/
#[Vich\UploadableField(mapping: 'student_profile', fileNameProperty: 'imageName')]
private ?File $imageFile = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $imageName = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'studentYears')]
#[ORM\JoinColumn(nullable: false)]
#[Groups(['getStudents','getExamStudent'])]
private ?TheClass $classe = null;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'studentYears')]
#[Groups(['getStudents'])]
private ?School $school = null;
#[ORM\OneToMany(mappedBy: 'student', targetEntity: StudentScolarity::class)]
private Collection $studentScolarities;
#[ORM\ManyToOne(cascade: ["persist"], inversedBy: 'students')]
private ?Scolarity $scolarity = null;
#[ORM\OneToMany(mappedBy: 'student', targetEntity: ScolarityHistory::class)]
private Collection $scolarityHistories;
#[ORM\Column(length: 255, nullable: true)]
private ?string $slug = null;
#[ORM\Column(length: 255, nullable: true)]
private ?string $lastSchoolName = null;
#[ORM\Column(nullable: true)]
private ?bool $repeater = null;
#[ORM\Column(type: 'boolean', options: ['default' => true])]
private ?bool $active = null;
public function __construct()
{
$this->studentScolarities = new ArrayCollection();
$this->scolarityHystories = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getYear(): ?SchoolYear
{
return $this->year;
}
public function setYear(?SchoolYear $year): static
{
$this->year = $year;
return $this;
}
public function getStudent(): ?Student
{
return $this->student;
}
public function setStudent(?Student $student): static
{
$this->student = $student;
return $this;
}
public function getClasse(): ?TheClass
{
return $this->classe;
}
public function setClasse(?TheClass $classe): static
{
$this->classe = $classe;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $imageFile
*/
public function setImageFile(?File $imageFile = null): void
{
$this->imageFile = $imageFile;
if (null !== $imageFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->setUpdatedAt(new \DateTime());
}
}
public function getImageFile(): ?File
{
return $this->imageFile;
}
public function getImageName(): ?string
{
return $this->imageName;
}
public function setImageName(?string $imageName): static
{
$this->imageName = $imageName;
return $this;
}
/**
* @return Collection<int, StudentScolarity>
*/
public function getStudentScolarities(): Collection
{
return $this->studentScolarities;
}
public function addStudentScolarity(StudentScolarity $studentScolarity): static
{
if (!$this->studentScolarities->contains($studentScolarity)) {
$this->studentScolarities->add($studentScolarity);
$studentScolarity->setStudent($this);
}
return $this;
}
public function removeStudentScolarity(StudentScolarity $studentScolarity): static
{
if ($this->studentScolarities->removeElement($studentScolarity)) {
// set the owning side to null (unless already changed)
if ($studentScolarity->getStudent() === $this) {
$studentScolarity->setStudent(null);
}
}
return $this;
}
public function getScolarity(): ?Scolarity
{
return $this->scolarity;
}
public function setScolarity(?Scolarity $scolarity): static
{
$this->scolarity = $scolarity;
return $this;
}
/**
* @return Collection<int, ScolarityHystory>
*/
public function getScolarityHistories(): Collection
{
return $this->scolarityHistories;
}
public function addScolarityHistory(ScolarityHistory $scolarityHistory): static
{
if (!$this->scolarityHistories->contains($scolarityHistory)) {
$this->scolarityHistories->add($scolarityHistory);
$scolarityHistory->setStudent($this);
}
return $this;
}
public function removeScolarityHistory(ScolarityHistory $scolarityHistory): static
{
if ($this->scolarityHistories->removeElement($scolarityHistory)) {
// set the owning side to null (unless already changed)
if ($scolarityHistory->getStudent() === $this) {
$scolarityHistory->setStudent(null);
}
}
return $this;
}
public function getSchool(): ?School
{
return $this->school;
}
public function setSchool(?School $school): static
{
$this->school = $school;
return $this;
}
public function getSlug(): ?string
{
return $this->slug;
}
public function setSlug(?string $slug): static
{
$this->slug = $slug;
return $this;
}
public function getLastSchoolName(): ?string
{
return $this->lastSchoolName;
}
public function setLastSchoolName(?string $lastSchoolName): static
{
$this->lastSchoolName = $lastSchoolName;
return $this;
}
public function isRepeater(): ?bool
{
return $this->repeater;
}
public function setRepeater(?bool $repeater): static
{
$this->repeater = $repeater;
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): static
{
$this->active = $active;
return $this;
}
}