src/Entity/CompanyAuditNRAxe.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompanyAuditNRAxeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassCompanyAuditNRAxeRepository::class)]
  8. class CompanyAuditNRAxe
  9. {
  10.     #[ORM\Id]
  11.     #[ORM\GeneratedValue]
  12.     #[ORM\Column]
  13.     private ?int $id null;
  14.     #[ORM\ManyToOne(fetch"EAGER")]
  15.     #[ORM\JoinColumn(nullablefalse)]
  16.     private ?LabelNRAxe $axe null;
  17.     #[ORM\ManyToOne(inversedBy'companyAxes')]
  18.     #[ORM\JoinColumn(nullablefalse)]
  19.     private ?CompanyAuditNR $companyAuditNR null;
  20.     #[ORM\OneToMany(mappedBy'companyAxe'targetEntityCompanyAuditNRPA::class, orphanRemovaltruefetch"EAGER")]
  21.     private Collection $companyPAs;
  22.     #[ORM\Column(length5)]
  23.     private ?string $code null;
  24.     public function __construct()
  25.     {
  26.         $this->companyPAs = new ArrayCollection();
  27.     }
  28.     public function getId(): ?int
  29.     {
  30.         return $this->id;
  31.     }
  32.     public function getAxe(): ?LabelNRAxe
  33.     {
  34.         return $this->axe;
  35.     }
  36.     public function setAxe(?LabelNRAxe $axe): self
  37.     {
  38.         $this->axe $axe;
  39.         return $this;
  40.     }
  41.     public function getCompanyAuditNR(): ?CompanyAuditNR
  42.     {
  43.         return $this->companyAuditNR;
  44.     }
  45.     public function setCompanyAuditNR(?CompanyAuditNR $companyAuditNR): self
  46.     {
  47.         $this->companyAuditNR $companyAuditNR;
  48.         return $this;
  49.     }
  50.     /**
  51.      * @return Collection<int, CompanyAuditNRPA>
  52.      */
  53.     public function getCompanyPAs(): Collection
  54.     {
  55.         return $this->companyPAs;
  56.     }
  57.     public function addCompanyPA(CompanyAuditNRPA $companyPA): self
  58.     {
  59.         if (!$this->companyPAs->contains($companyPA)) {
  60.             $this->companyPAs->add($companyPA);
  61.             $companyPA->setCompanyAxe($this);
  62.         }
  63.         return $this;
  64.     }
  65.     public function removeCompanyPA(CompanyAuditNRPA $companyPA): self
  66.     {
  67.         if ($this->companyPAs->removeElement($companyPA)) {
  68.             // set the owning side to null (unless already changed)
  69.             if ($companyPA->getCompanyAxe() === $this) {
  70.                 $companyPA->setCompanyAxe(null);
  71.             }
  72.         }
  73.         return $this;
  74.     }
  75.     public function getCode(): ?string
  76.     {
  77.         return $this->code;
  78.     }
  79.     public function setCode(string $code): self
  80.     {
  81.         $this->code $code;
  82.         return $this;
  83.     }
  84.     // public function getScore()
  85.     // {
  86.     //     $score = 0;
  87.     //     $maxScore = count($this->companyTIRs);
  88.     //     foreach ($this->companyTIRs as $tir) {
  89.     //         if ($tir->getScore() === "none") {
  90.     //             $maxScore--;
  91.     //         } else {
  92.     //             $score += $tir->getScore();
  93.     //         }
  94.     //     }
  95.     //     return [
  96.     //         "score" => $score,
  97.     //         "maxScore" => $maxScore,
  98.     //         "percentage" => round(($score / $maxScore) * 100, 2)
  99.     //     ];
  100.     // }
  101.     public function getScore()
  102.     {
  103.         $score 0;
  104.         $maxScore 0;
  105.         $numberNone 0;
  106.         foreach ($this->companyPAs as $pa) {
  107.             foreach ($pa->getCompanyTIRs() as $key => $tir) {
  108.                 if ($tir->getScore() === "none") {
  109.                     $numberNone++;
  110.                     $maxScore--;
  111.                 } else {
  112.                     $score += $tir->getScore();
  113.                 }
  114.                 $maxScore++;
  115.             }
  116.         }
  117.         if ($maxScore == $numberNone) {
  118.             return "none";
  119.         }
  120.         return [
  121.             "score" => $score,
  122.             "maxScore" => $maxScore,
  123.             "percentage" => round(($score $maxScore) * 1002)
  124.         ];
  125.     }
  126.     public function getPercentage()
  127.     {
  128.         // Calculer le pourcentage de TIR complété pour l'axe
  129.         $totalTIR 0;
  130.         $completedTIR 0;
  131.         foreach ($this->companyPAs as $pa) {
  132.             $totalTIR += count($pa->getCompanyTIRs());
  133.             foreach ($pa->getCompanyTIRs() as $tir) {
  134.                 if ($tir->getEvaluation()) {
  135.                     $completedTIR++;
  136.                 }
  137.             }
  138.         }
  139.         if ($totalTIR == 0) {
  140.             return 0;
  141.         } else {
  142.             return round($completedTIR $totalTIR 100);
  143.         }
  144.     }
  145. }