src/Entity/CompanyAuditNR.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompanyAuditNRRepository;
  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(repositoryClassCompanyAuditNRRepository::class)]
  9. class CompanyAuditNR
  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'companyAuditNR'targetEntityCompanyAuditNRAxe::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'companyAuditNR')]
  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, CompanyAuditNRAxe>
  59.      */
  60.     public function getCompanyAxes(): Collection
  61.     {
  62.         return $this->companyAxes;
  63.     }
  64.     public function addCompanyAxe(CompanyAuditNRAxe $companyAxe): self
  65.     {
  66.         if (!$this->companyAxes->contains($companyAxe)) {
  67.             $this->companyAxes->add($companyAxe);
  68.             $companyAxe->setCompanyAuditNR($this);
  69.         }
  70.         return $this;
  71.     }
  72.     public function removeCompanyAxe(CompanyAuditNRAxe $companyAxe): self
  73.     {
  74.         if ($this->companyAxes->removeElement($companyAxe)) {
  75.             // set the owning side to null (unless already changed)
  76.             if ($companyAxe->getCompanyAuditNR() === $this) {
  77.                 $companyAxe->setCompanyAuditNR(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.         $maxScore 0;
  104.         $numberNone 0;
  105.         foreach ($this->companyAxes as $key => $axe) {
  106.             foreach ($axe->getCompanyPAs() 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.         }
  118.         if ($maxScore == $numberNone) {
  119.             return "none";
  120.         }
  121.         return [
  122.             "score" => $score,
  123.             "maxScore" => $maxScore,
  124.             "percentage" => round(($score $maxScore) * 1002)
  125.         ];
  126.     }
  127.     public function getCreatedAt(): ?\DateTimeImmutable
  128.     {
  129.         return $this->createdAt;
  130.     }
  131.     public function setCreatedAt(\DateTimeImmutable $createdAt): static
  132.     {
  133.         $this->createdAt $createdAt;
  134.         return $this;
  135.     }
  136.     public function getInfosAdvancement()
  137.     {
  138.         $infosAdvancement = [
  139.             "tir" => [
  140.                 "evaluated" => 0,
  141.                 "total" => 0,
  142.                 "percentage" => 0,
  143.             ],
  144.             "pa" => [
  145.                 "finished" => 0,
  146.                 "total" => 0,
  147.                 "percentage" => 0,
  148.             ],
  149.             "na" => 0,
  150.         ];
  151.         foreach ($this->companyAxes as $key => $axe) {
  152.             foreach ($axe->getCompanyPAs() as $pa) {
  153.                 $infosAdvancement["pa"]["total"]++;
  154.                 if ($pa->isTerminated()) {
  155.                     $infosAdvancement["pa"]["finished"]++;
  156.                 }
  157.                 foreach ($pa->getCompanyTIRs() as $tir) {
  158.                     $infosAdvancement["tir"]["total"]++;
  159.                     if ($tir->getEvaluation()) {
  160.                         $infosAdvancement["tir"]["evaluated"]++;
  161.                     }
  162.                     if ($tir->getEvaluation() === "Non applicable") {
  163.                         $infosAdvancement["na"]++;
  164.                     }
  165.                 }
  166.             }
  167.         }
  168.         $infosAdvancement["tir"]["percentage"] = round(($infosAdvancement["tir"]["evaluated"] / $infosAdvancement["tir"]["total"]) * 100);
  169.         $infosAdvancement["pa"]["percentage"] = round(($infosAdvancement["pa"]["finished"] / $infosAdvancement["pa"]["total"]) * 100);
  170.         return $infosAdvancement;
  171.     }
  172.     public function getInfosAmelioration()
  173.     {
  174.         $PAs = [];
  175.         foreach ($this->companyAxes as $axe) {
  176.             foreach ($axe->getCompanyPAs() as $pa) {
  177.                 $score $pa->getScore();
  178.                 if ($score !== "none" && $score["percentage"] < 50) {
  179.                     $PAs[] = [
  180.                         "name" => $pa->getPA()->getName(),
  181.                         "percentage" => $score["percentage"],
  182.                         "color" => $axe->getAxe()->getColor(),
  183.                         "code" => $axe->getCode()
  184.                     ];
  185.                 }
  186.             }
  187.         }
  188.         usort($PAs, function ($a$b) {
  189.             return $a["percentage"] <=> $b["percentage"];
  190.         });
  191.         return array_slice($PAs05);
  192.     }
  193.     public function getInfosComparison($before)
  194.     {
  195.         $comparison = [
  196.             "scoreNow" => 0,
  197.             "scoreBefore" => 0,
  198.             "evolution" => 0,
  199.             "axes" => []
  200.         ];
  201.         $comparison["scoreNow"] = $this->getScore()["percentage"];
  202.         $comparison["scoreBefore"] = $before->getScore()["percentage"];
  203.         $comparison["evolution"] = $comparison["scoreNow"] - $comparison["scoreBefore"];
  204.         foreach ($this->companyAxes as $key => $axe) {
  205.             $axeInfos = [
  206.                 "name" => $axe->getAxe()->getName(),
  207.                 "scoreNow" => 0,
  208.                 "scoreBefore" => 0,
  209.                 "evolution" => 0,
  210.                 "color" => $axe->getAxe()->getColor(),
  211.                 "code" => $axe->getCode()
  212.             ];
  213.             $axeInfos["scoreNow"] = $axe->getScore()["percentage"];
  214.             $beforeAxeScore null;
  215.             foreach ($before->getCompanyAxes() as $key => $beforeAxe) {
  216.                 if ($beforeAxe->getAxe()->getId() === $axe->getAxe()->getId()) {
  217.                     $beforeAxeScore $beforeAxe->getScore()["percentage"];
  218.                     break;
  219.                 }
  220.             }
  221.             $axeInfos["scoreBefore"] = $beforeAxeScore;
  222.             $axeInfos["evolution"] = $axeInfos["scoreNow"] - $axeInfos["scoreBefore"];
  223.             $comparison["axes"][] = $axeInfos;
  224.         }
  225.         return $comparison;
  226.     }
  227. }