src/Entity/CompanyLabelNRAxe.php line 11

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompanyLabelNRAxeRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. #[ORM\Entity(repositoryClassCompanyLabelNRAxeRepository::class)]
  8. class CompanyLabelNRAxe
  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 ?CompanyLabelNR $companyLabelNR null;
  20.     #[ORM\OneToMany(mappedBy'companyAxe'targetEntityCompanyLabelNRPA::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 getCompanyLabelNR(): ?CompanyLabelNR
  42.     {
  43.         return $this->companyLabelNR;
  44.     }
  45.     public function setCompanyLabelNR(?CompanyLabelNR $companyLabelNR): self
  46.     {
  47.         $this->companyLabelNR $companyLabelNR;
  48.         return $this;
  49.     }
  50.     /**
  51.      * @return Collection<int, CompanyLabelNRPA>
  52.      */
  53.     public function getCompanyPAs(): Collection
  54.     {
  55.         return $this->companyPAs;
  56.     }
  57.     public function addCompanyPA(CompanyLabelNRPA $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(CompanyLabelNRPA $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.         $valid true;
  88.         $weight 0;
  89.         $notCount 0;
  90.         // $scores = [];
  91.         foreach ($this->companyPAs as $pa) {
  92.             // $scores[] = $pa->getScore();
  93.             if ($pa->getScore() == "none") {
  94.                 $notCount++;
  95.             } elseif ($pa->getScore() == false) {
  96.                 $valid false;
  97.             } else {
  98.                 $score += round($pa->getScore()["score"], 2) * $pa->getScore()["weight"];
  99.                 $weight += $pa->getScore()["weight"];
  100.             }
  101.         }
  102.         // if ($this->axe->getName() == "Cycle de vie des services numériques") {
  103.         //     dd($notCount, count($this->companyPAs), $scores, $score, $weight, $valid);
  104.         // }
  105.         if ($notCount == count($this->companyPAs)) {
  106.             return "none";
  107.         } elseif ($valid) {
  108.             return [
  109.                 "score" => $score $weight,
  110.                 "weight" => $weight
  111.             ];
  112.         } else {
  113.             return false;
  114.         }
  115.     }
  116.     public function getPercentage()
  117.     {
  118.         // Calculer le pourcentage de TIR complété pour l'axe
  119.         $totalTIR 0;
  120.         $completedTIR 0;
  121.         foreach ($this->companyPAs as $pa) {
  122.             $totalTIR += count($pa->getCompanyTIRs());
  123.             foreach ($pa->getCompanyTIRs() as $tir) {
  124.                 if ($tir->getEvaluation()) {
  125.                     $completedTIR++;
  126.                 }
  127.             }
  128.         }
  129.         if ($totalTIR == 0) {
  130.             return 0;
  131.         } else {
  132.             return round($completedTIR $totalTIR 100);
  133.         }
  134.     }
  135. }