src/Entity/CompanyLabelNR.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompanyLabelNRRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. #[ORM\Entity(repositoryClassCompanyLabelNRRepository::class)]
  9. class CompanyLabelNR
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\ManyToOne]
  16.     #[ORM\JoinColumn(nullablefalse)]
  17.     private ?LabelNR $LabelNR null;
  18.     #[ORM\OneToMany(mappedBy'companyLabelNR'targetEntityCompanyLabelNRAxe::class, orphanRemovaltruefetch"EAGER")]
  19.     private Collection $companyAxes;
  20.     #[ORM\Column]
  21.     private ?bool $active null;
  22.     #[ORM\Column(typeTypes::SMALLINT)]
  23.     private ?int $type null;
  24.     #[ORM\Column]
  25.     private ?\DateTimeImmutable $createdAt null;
  26.     #[ORM\ManyToOne(inversedBy'companyLabelNR')]
  27.     #[ORM\JoinColumn(nullablefalse)]
  28.     private ?Company $company null;
  29.     public function __construct()
  30.     {
  31.         $this->companyAxes = new ArrayCollection();
  32.         $this->active true;
  33.         $this->createdAt = new \DateTimeImmutable();
  34.     }
  35.     public function getId(): ?int
  36.     {
  37.         return $this->id;
  38.     }
  39.     public function getCompany(): ?Company
  40.     {
  41.         return $this->company;
  42.     }
  43.     public function setCompany(?Company $company): self
  44.     {
  45.         $this->company $company;
  46.         return $this;
  47.     }
  48.     public function getLabelNR(): ?LabelNR
  49.     {
  50.         return $this->LabelNR;
  51.     }
  52.     public function setLabelNR(?LabelNR $LabelNR): self
  53.     {
  54.         $this->LabelNR $LabelNR;
  55.         return $this;
  56.     }
  57.     /**
  58.      * @return Collection<int, CompanyLabelNRAxe>
  59.      */
  60.     public function getCompanyAxes(): Collection
  61.     {
  62.         return $this->companyAxes;
  63.     }
  64.     public function addCompanyAxe(CompanyLabelNRAxe $companyAxe): self
  65.     {
  66.         if (!$this->companyAxes->contains($companyAxe)) {
  67.             $this->companyAxes->add($companyAxe);
  68.             $companyAxe->setCompanyLabelNR($this);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeCompanyAxe(CompanyLabelNRAxe $companyAxe): self
  73.     {
  74.         if ($this->companyAxes->removeElement($companyAxe)) {
  75.             // set the owning side to null (unless already changed)
  76.             if ($companyAxe->getCompanyLabelNR() === $this) {
  77.                 $companyAxe->setCompanyLabelNR(null);
  78.             }
  79.         }
  80.         return $this;
  81.     }
  82.     public function isActive(): ?bool
  83.     {
  84.         return $this->active;
  85.     }
  86.     public function setActive(bool $active): self
  87.     {
  88.         $this->active $active;
  89.         return $this;
  90.     }
  91.     public function getType(): ?int
  92.     {
  93.         return $this->type;
  94.     }
  95.     public function setType(int $type): self
  96.     {
  97.         $this->type $type;
  98.         return $this;
  99.     }
  100.     public function getScore()
  101.     {
  102.         $score 0;
  103.         $valid true;
  104.         $weight 0;
  105.         $notCount 0;
  106.         // $scores = [];
  107.         foreach ($this->companyAxes as $axe) {
  108.             // $scores[] = $pa->getScore();
  109.             if ($axe->getScore() == "none") {
  110.                 $notCount++;
  111.             } elseif ($axe->getScore() == false) {
  112.                 $valid false;
  113.             } else {
  114.                 $score += round($axe->getScore()["score"], 2) * $axe->getScore()["weight"];
  115.                 $weight += $axe->getScore()["weight"];
  116.             }
  117.         }
  118.         // if ($this->axe->getName() == "Cycle de vie des services numériques") {
  119.         //     dd($notCount, count($this->companyPAs), $scores, $score, $weight, $valid);
  120.         // }
  121.         if ($notCount == count($this->companyAxes)) {
  122.             return "none";
  123.         } elseif ($valid) {
  124.             return [
  125.                 "score" => $score $weight,
  126.                 "weight" => $weight
  127.             ];
  128.         } else {
  129.             return [
  130.                 "score" => "-",
  131.                 "weight" => $weight
  132.             ];
  133.         }
  134.     }
  135.     public function getCreatedAt(): ?\DateTimeImmutable
  136.     {
  137.         return $this->createdAt;
  138.     }
  139.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  140.     {
  141.         $this->createdAt $createdAt;
  142.         return $this;
  143.     }
  144. }