src/Entity/CompanyAuditNRAxe.php line 11
<?php
namespace App\Entity;
use App\Repository\CompanyAuditNRAxeRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CompanyAuditNRAxeRepository::class)]
class CompanyAuditNRAxe
{
#[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 ?CompanyAuditNR $companyAuditNR = null;
#[ORM\OneToMany(mappedBy: 'companyAxe', targetEntity: CompanyAuditNRPA::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 getCompanyAuditNR(): ?CompanyAuditNR
{
return $this->companyAuditNR;
}
public function setCompanyAuditNR(?CompanyAuditNR $companyAuditNR): self
{
$this->companyAuditNR = $companyAuditNR;
return $this;
}
/**
* @return Collection<int, CompanyAuditNRPA>
*/
public function getCompanyPAs(): Collection
{
return $this->companyPAs;
}
public function addCompanyPA(CompanyAuditNRPA $companyPA): self
{
if (!$this->companyPAs->contains($companyPA)) {
$this->companyPAs->add($companyPA);
$companyPA->setCompanyAxe($this);
}
return $this;
}
public function removeCompanyPA(CompanyAuditNRPA $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;
// $maxScore = count($this->companyTIRs);
// foreach ($this->companyTIRs as $tir) {
// if ($tir->getScore() === "none") {
// $maxScore--;
// } else {
// $score += $tir->getScore();
// }
// }
// return [
// "score" => $score,
// "maxScore" => $maxScore,
// "percentage" => round(($score / $maxScore) * 100, 2)
// ];
// }
public function getScore()
{
$score = 0;
$maxScore = 0;
$numberNone = 0;
foreach ($this->companyPAs as $pa) {
foreach ($pa->getCompanyTIRs() as $key => $tir) {
if ($tir->getScore() === "none") {
$numberNone++;
$maxScore--;
} else {
$score += $tir->getScore();
}
$maxScore++;
}
}
if ($maxScore == $numberNone) {
return "none";
}
return [
"score" => $score,
"maxScore" => $maxScore,
"percentage" => round(($score / $maxScore) * 100, 2)
];
}
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);
}
}
}