src/Entity/AbscenceSheet.php line 15

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Entity\Traits\TimeStampable;
  4. use App\Repository\AbscenceSheetRepository;
  5. use Doctrine\Common\Collections\ArrayCollection;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\DBAL\Types\Types;
  8. use Doctrine\ORM\Mapping as ORM;
  9. /**
  10.  * @ORM\Entity(repositoryClass=AbscenceSheetRepository::class)
  11.  */ class AbscenceSheet
  12. {
  13.     use TimeStampable;
  14.     public const NUM_ITEMS_PER_PAGE 20;
  15.     /**
  16.      * @var int
  17.      *
  18.      * @ORM\Column(name="id", type="integer")
  19.      * @ORM\Id
  20.      * @ORM\GeneratedValue(strategy="AUTO")
  21.      */
  22.     private $id;
  23.     /**
  24.      * @ORM\ManyToOne(targetEntity=Sequence::class, inversedBy="abscenceSheets")
  25.      * @ORM\JoinColumn(nullable=true)
  26.      */
  27.     private $sequence;
  28.     /**
  29.      * @ORM\ManyToOne(targetEntity=ClassRoom::class, inversedBy="abscenceSheets")
  30.      * @ORM\JoinColumn(nullable=false)
  31.      */
  32.     private $classRoom;
  33.     /**
  34.      * @ORM\OneToMany(targetEntity=Abscence::class, mappedBy="abscenceSheet", orphanRemoval=true)
  35.      */
  36.     private $abscences;
  37.     /**
  38.      * @ORM\Column(type="date")
  39.      */
  40.     private $startDate;
  41.     /**
  42.      * @ORM\Column(type="date")
  43.      */
  44.     private $endDate;
  45.     public function __construct()
  46.     {
  47.         $this->abscences = new ArrayCollection();
  48.         $this->updateTimestamp();
  49.     }
  50.     public function getId(): ?int
  51.     {
  52.         return $this->id;
  53.     }
  54.     public function addAbscence(Abscence $abscence): self
  55.     {
  56.         if (!$this->abscences->contains($abscence)) {
  57.             $this->abscences[] = $abscence;
  58.             $abscence->setAbscenceSheet($this);
  59.         }
  60.         return $this;
  61.     }
  62.     public function removeAbscence(Abscence $abscence): self
  63.     {
  64.         if ($this->abscences->removeElement($abscence)) {
  65.             // set the owning side to null (unless already changed)
  66.             if ($abscence->getAbscenceSheet() === $this) {
  67.                 $abscence->setAbscenceSheet(null);
  68.             }
  69.         }
  70.         return $this;
  71.     }
  72.     /**
  73.      * @return Collection|Abscence[]
  74.      */
  75.     public function getAbscences(): Collection
  76.     {
  77.         return $this->abscences;
  78.     }
  79.     public function getTotalAbscence(): int
  80.     {
  81.         return count($this->abscences);
  82.     }
  83.     public function getTotalAbscenceHourByStudent(Student $student): int
  84.     {
  85.         $total 0;
  86.         foreach ($this->abscences as $abscence) {
  87.             if ($abscence->getStudent() === $student) {
  88.                 $total += $abscence->getHour();
  89.             }
  90.         }
  91.         return $total;
  92.     }
  93.     public function getTotalAbscenceHour(): int
  94.     {
  95.         $total 0;
  96.         foreach ($this->abscences as $abscence) {
  97.             $total += $abscence->getHour();
  98.         }
  99.         return $total;
  100.     }
  101.     public function getStartDate(): ?\DateTimeInterface
  102.     {
  103.         return $this->startDate;
  104.     }
  105.     public function setStartDate(\DateTimeInterface $startDate): self
  106.     {
  107.         $this->startDate $startDate;
  108.         return $this;
  109.     }
  110.     public function getEndDate(): ?\DateTimeInterface
  111.     {
  112.         return $this->endDate;
  113.     }
  114.     public function setEndDate(\DateTimeInterface $endDate): self
  115.     {
  116.         $this->endDate $endDate;
  117.         return $this;
  118.     }
  119.     public function getSequence(): ?Sequence
  120.     {
  121.         return $this->sequence;
  122.     }
  123.     public function setSequence(?Sequence $sequence): static
  124.     {
  125.         $this->sequence $sequence;
  126.         return $this;
  127.     }
  128.     public function getClassRoom(): ?ClassRoom
  129.     {
  130.         return $this->classRoom;
  131.     }
  132.     public function setClassRoom(?ClassRoom $classRoom): static
  133.     {
  134.         $this->classRoom $classRoom;
  135.         return $this;
  136.     }
  137. }