<?phpnamespace App\Entity\Training;use ApiPlatform\Core\Annotation\ApiResource;use App\Repository\Training\NoteassignRepository;use App\Traits\Actions;use App\Entity\Training\Assignation;use App\Entity\Training\Note;use App\Entity\Training\Notemodule;use DateTime;use Doctrine\Common\Collections\ArrayCollection;use Doctrine\Common\Collections\Collection;use Doctrine\ORM\Mapping as ORM;#[ORM\Entity(repositoryClass: NoteassignRepository::class)]#[ORM\Table(name: 'hs_tc_training_noteassign')]#[ApiResource]class Noteassign{ use Actions; #[ORM\ManyToOne(targetEntity: "Assignation", inversedBy: "notes")] #[ORM\JoinColumn(nullable: false)] private Assignation $assignation; #[ORM\ManyToOne(targetEntity: "Notemodule", inversedBy: "lines")] #[ORM\JoinColumn(nullable: false)] private Notemodule $notemodule; #[ORM\OneToMany(mappedBy: "noteassign", targetEntity: "Note", cascade: ["persist"], orphanRemoval: true)] private Collection $notes; #[ORM\Column(type: "datetime", nullable: true)] private ?DateTime $carriedOutAt=null; /** * Noteassign constructor. */ public function __construct() { // date_default_timezone_set('Africa/Casablanca'); $this->createAt=new \DateTime('now'); $this->published=false; } /** * @return Notemodule */ public function getNotemodule(): ?Notemodule { return $this->notemodule; } /** * @param Notemodule $notemodule */ public function setNotemodule(?Notemodule $notemodule): Noteassign { $this->notemodule = $notemodule; return $this; } /** * @return Assignation */ public function getAssignation(): ?Assignation { return $this->assignation; } /** * @param Assignation $assignation */ public function setAssignation(?Assignation $assignation): Noteassign { $this->assignation = $assignation; return $this; } /** * Add note * * * @return Noteassign */ public function addNote(Note $note) { $note->setNoteassign($this); $this->notes[] = $note; return $this; } /** * Remove note */ public function removeNote(Note $note) { $this->notes->removeElement($note); } /** * Get notes * * @return Collection */ public function getNotes() { return $this->notes; } public function getCarriedOutAt(): ?DateTime { return $this->carriedOutAt; } public function setCarriedOutAt(?DateTime $carriedOutAt): void { $this->carriedOutAt = $carriedOutAt; } public function getPCInput(Groupe $groupe){ if($groupe->getTrainees()->count()==0) return 0; $i=0; foreach ($this->getNotes() as $line){ if($line->getAssignation()->getGroupe()===$groupe && $line->getVal()!== null) $i++; } return floor($i/$groupe->getTrainees()->count()); } public function getNotesEncoure() { $items=new ArrayCollection(); /** @var Note $line */ foreach ($this->getNotes() as $line){ if($line->getTrainee()->getStatus()=='En cours') $items->add($line); } return $items; }}