src/Entity/CompanyLabelNRAxe.php line 11
<?php
namespace App\Entity;
use App\Repository\CompanyLabelNRAxeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CompanyLabelNRAxeRepository::class)]
class CompanyLabelNRAxe
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne(fetch: "EAGER")]
#[ORM\JoinColumn(nullable: false)]
private ?LabelNRAxe $axe = null;
#[ORM\ManyToOne(inversedBy: 'companyAxes')]
#[ORM\JoinColumn(nullable: false)]
private ?CompanyLabelNR $companyLabelNR = null;
#[ORM\OneToMany(mappedBy: 'companyAxe', targetEntity: CompanyLabelNRPA::class, orphanRemoval: true, fetch: "EAGER")]
private Collection $companyPAs;
#[ORM\Column(length: 5)]
private ?string $code = null;
public function __construct()
{
$this->companyPAs = new ArrayCollection();
}
public function getId(): ?int
{
return $this->id;
}
public function getAxe(): ?LabelNRAxe
{
return $this->axe;
}
public function setAxe(?LabelNRAxe $axe): self
{
$this->axe = $axe;
return $this;
}
public function getCompanyLabelNR(): ?CompanyLabelNR
{
return $this->companyLabelNR;
}
public function setCompanyLabelNR(?CompanyLabelNR $companyLabelNR): self
{
$this->companyLabelNR = $companyLabelNR;
return $this;
}
/**
* @return Collection<int, CompanyLabelNRPA>
*/
public function getCompanyPAs(): Collection
{
return $this->companyPAs;
}
public function addCompanyPA(CompanyLabelNRPA $companyPA): self
{
if (!$this->companyPAs->contains($companyPA)) {
$this->companyPAs->add($companyPA);
$companyPA->setCompanyAxe($this);
}
return $this;
}
public function removeCompanyPA(CompanyLabelNRPA $companyPA): self
{
if ($this->companyPAs->removeElement($companyPA)) {
// set the owning side to null (unless already changed)
if ($companyPA->getCompanyAxe() === $this) {
$companyPA->setCompanyAxe(null);
}
}
return $this;
}
public function getCode(): ?string
{
return $this->code;
}
public function setCode(string $code): self
{
$this->code = $code;
return $this;
}
public function getScore()
{
$score = 0;
$valid = true;
$weight = 0;
$notCount = 0;
// $scores = [];
foreach ($this->companyPAs as $pa) {
// $scores[] = $pa->getScore();
if ($pa->getScore() == "none") {
$notCount++;
} elseif ($pa->getScore() == false) {
$valid = false;
} else {
$score += round($pa->getScore()["score"], 2) * $pa->getScore()["weight"];
$weight += $pa->getScore()["weight"];
}
}
// if ($this->axe->getName() == "Cycle de vie des services numériques") {
// dd($notCount, count($this->companyPAs), $scores, $score, $weight, $valid);
// }
if ($notCount == count($this->companyPAs)) {
return "none";
} elseif ($valid) {
return [
"score" => $score / $weight,
"weight" => $weight
];
} else {
return false;
}
}
public function getPercentage()
{
// Calculer le pourcentage de TIR complété pour l'axe
$totalTIR = 0;
$completedTIR = 0;
foreach ($this->companyPAs as $pa) {
$totalTIR += count($pa->getCompanyTIRs());
foreach ($pa->getCompanyTIRs() as $tir) {
if ($tir->getEvaluation()) {
$completedTIR++;
}
}
}
if ($totalTIR == 0) {
return 0;
} else {
return round($completedTIR / $totalTIR * 100);
}
}
}