src/Entity/Training/Noteassign.php line 19

Open in your IDE?
  1. <?php
  2. namespace App\Entity\Training;
  3. use ApiPlatform\Core\Annotation\ApiResource;
  4. use App\Repository\Training\NoteassignRepository;
  5. use App\Traits\Actions;
  6. use App\Entity\Training\Assignation;
  7. use App\Entity\Training\Note;
  8. use App\Entity\Training\Notemodule;
  9. use DateTime;
  10. use Doctrine\Common\Collections\ArrayCollection;
  11. use Doctrine\Common\Collections\Collection;
  12. use Doctrine\ORM\Mapping as ORM;
  13. #[ORM\Entity(repositoryClassNoteassignRepository::class)]
  14. #[ORM\Table(name'hs_tc_training_noteassign')]
  15. #[ApiResource]
  16. class Noteassign
  17. {
  18.     use Actions;
  19.     #[ORM\ManyToOne(targetEntity"Assignation"inversedBy"notes")]
  20.     #[ORM\JoinColumn(nullablefalse)]
  21.     private Assignation $assignation;
  22.     #[ORM\ManyToOne(targetEntity"Notemodule"inversedBy"lines")]
  23.     #[ORM\JoinColumn(nullablefalse)]
  24.     private Notemodule $notemodule;
  25.     #[ORM\OneToMany(mappedBy"noteassign"targetEntity"Note"cascade: ["persist"], orphanRemovaltrue)]
  26.     private Collection $notes;
  27.     #[ORM\Column(type"datetime"nullabletrue)]
  28.     private ?DateTime $carriedOutAt=null;
  29.     /**
  30.      * Noteassign constructor.
  31.      */
  32.     public function __construct()
  33.     {
  34.         // date_default_timezone_set('Africa/Casablanca');
  35.         $this->createAt=new \DateTime('now');
  36.         $this->published=false;
  37.     }
  38.     /**
  39.      * @return Notemodule
  40.      */
  41.     public function getNotemodule(): ?Notemodule
  42.     {
  43.         return $this->notemodule;
  44.     }
  45.     /**
  46.      * @param Notemodule $notemodule
  47.      */
  48.     public function setNotemodule(?Notemodule $notemodule): Noteassign
  49.     {
  50.         $this->notemodule $notemodule;
  51.         return $this;
  52.     }
  53.     /**
  54.      * @return Assignation
  55.      */
  56.     public function getAssignation(): ?Assignation
  57.     {
  58.         return $this->assignation;
  59.     }
  60.     /**
  61.      * @param Assignation $assignation
  62.      */
  63.     public function setAssignation(?Assignation $assignation): Noteassign
  64.     {
  65.         $this->assignation $assignation;
  66.         return $this;
  67.     }
  68.     /**
  69.      * Add note
  70.      *
  71.      *
  72.      * @return Noteassign
  73.      */
  74.     public function addNote(Note $note)
  75.     {
  76.         $note->setNoteassign($this);
  77.         $this->notes[] = $note;
  78.         return $this;
  79.     }
  80.     /**
  81.      * Remove note
  82.      */
  83.     public function removeNote(Note $note)
  84.     {
  85.         $this->notes->removeElement($note);
  86.     }
  87.     /**
  88.      * Get notes
  89.      *
  90.      * @return Collection
  91.      */
  92.     public function getNotes()
  93.     {
  94.         return $this->notes;
  95.     }
  96.     public function getCarriedOutAt(): ?DateTime
  97.     {
  98.         return $this->carriedOutAt;
  99.     }
  100.     public function setCarriedOutAt(?DateTime $carriedOutAt): void
  101.     {
  102.         $this->carriedOutAt $carriedOutAt;
  103.     }
  104.     public function getPCInput(Groupe $groupe){
  105.         if($groupe->getTrainees()->count()==0) return 0;
  106.         $i=0;
  107.         foreach ($this->getNotes() as $line){
  108.             if($line->getAssignation()->getGroupe()===$groupe && $line->getVal()!== null$i++;
  109.         }
  110.         return floor($i/$groupe->getTrainees()->count());
  111.     }
  112.     public function getNotesEncoure()
  113.     {
  114.         $items=new ArrayCollection();
  115.         /** @var Note $line */
  116.         foreach ($this->getNotes() as $line){
  117.             if($line->getTrainee()->getStatus()=='En cours'$items->add($line);
  118.         }
  119.         return $items;
  120.     }
  121. }