src/Entity/CompanyLabelNR.php line 12
<?php
namespace App\Entity;
use App\Repository\CompanyLabelNRRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\DBAL\Types\Types;
use Doctrine\ORM\Mapping as ORM;
#[ORM\Entity(repositoryClass: CompanyLabelNRRepository::class)]
class CompanyLabelNR
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\ManyToOne]
#[ORM\JoinColumn(nullable: false)]
private ?LabelNR $LabelNR = null;
#[ORM\OneToMany(mappedBy: 'companyLabelNR', targetEntity: CompanyLabelNRAxe::class, orphanRemoval: true, fetch: "EAGER")]
private Collection $companyAxes;
#[ORM\Column]
private ?bool $active = null;
#[ORM\Column(type: Types::SMALLINT)]
private ?int $type = null;
#[ORM\Column]
private ?\DateTimeImmutable $createdAt = null;
#[ORM\ManyToOne(inversedBy: 'companyLabelNR')]
#[ORM\JoinColumn(nullable: false)]
private ?Company $company = null;
public function __construct()
{
$this->companyAxes = new ArrayCollection();
$this->active = true;
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getCompany(): ?Company
{
return $this->company;
}
public function setCompany(?Company $company): self
{
$this->company = $company;
return $this;
}
public function getLabelNR(): ?LabelNR
{
return $this->LabelNR;
}
public function setLabelNR(?LabelNR $LabelNR): self
{
$this->LabelNR = $LabelNR;
return $this;
}
/**
* @return Collection<int, CompanyLabelNRAxe>
*/
public function getCompanyAxes(): Collection
{
return $this->companyAxes;
}
public function addCompanyAxe(CompanyLabelNRAxe $companyAxe): self
{
if (!$this->companyAxes->contains($companyAxe)) {
$this->companyAxes->add($companyAxe);
$companyAxe->setCompanyLabelNR($this);
}
return $this;
}
public function removeCompanyAxe(CompanyLabelNRAxe $companyAxe): self
{
if ($this->companyAxes->removeElement($companyAxe)) {
// set the owning side to null (unless already changed)
if ($companyAxe->getCompanyLabelNR() === $this) {
$companyAxe->setCompanyLabelNR(null);
}
}
return $this;
}
public function isActive(): ?bool
{
return $this->active;
}
public function setActive(bool $active): self
{
$this->active = $active;
return $this;
}
public function getType(): ?int
{
return $this->type;
}
public function setType(int $type): self
{
$this->type = $type;
return $this;
}
public function getScore()
{
$score = 0;
$valid = true;
$weight = 0;
$notCount = 0;
// $scores = [];
foreach ($this->companyAxes as $axe) {
// $scores[] = $pa->getScore();
if ($axe->getScore() == "none") {
$notCount++;
} elseif ($axe->getScore() == false) {
$valid = false;
} else {
$score += round($axe->getScore()["score"], 2) * $axe->getScore()["weight"];
$weight += $axe->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->companyAxes)) {
return "none";
} elseif ($valid) {
return [
"score" => $score / $weight,
"weight" => $weight
];
} else {
return [
"score" => "-",
"weight" => $weight
];
}
}
public function getCreatedAt(): ?\DateTimeImmutable
{
return $this->createdAt;
}
public function setCreatedAt(\DateTimeImmutable $createdAt): static
{
$this->createdAt = $createdAt;
return $this;
}
}