src/Entity/CompanyIndicator.php line 9

  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\CompanyIndicatorRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. #[ORM\Entity(repositoryClassCompanyIndicatorRepository::class)]
  6. class CompanyIndicator
  7. {
  8.     #[ORM\Id]
  9.     #[ORM\GeneratedValue]
  10.     #[ORM\Column]
  11.     private ?int $id null;
  12.     #[ORM\ManyToOne]
  13.     #[ORM\JoinColumn(nullablefalse)]
  14.     private ?Indicator $indicator null;
  15.     #[ORM\Column(length20nullabletrue)]
  16.     private ?string $value null;
  17.     #[ORM\Column(length20nullabletrue)]
  18.     private ?string $target null;
  19.     #[ORM\Column(nullabletrue)]
  20.     private ?\DateTimeImmutable $updated null;
  21.     #[ORM\ManyToOne(inversedBy'companyIndicators')]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private ?CompanyIndicatorThematic $companyIndicatorThematic null;
  24.     public function __construct(Indicator $indicator nullCompanyIndicatorThematic $companyIndicatorThematic null)
  25.     {
  26.         $this->indicator $indicator;
  27.         $this->companyIndicatorThematic $companyIndicatorThematic;
  28.     }
  29.     public function getId(): ?int
  30.     {
  31.         return $this->id;
  32.     }
  33.     public function getIndicator(): ?Indicator
  34.     {
  35.         return $this->indicator;
  36.     }
  37.     public function setIndicator(?Indicator $indicator): self
  38.     {
  39.         $this->indicator $indicator;
  40.         return $this;
  41.     }
  42.     public function getValue(): ?string
  43.     {
  44.         return $this->value;
  45.     }
  46.     public function setValue(?string $value): self
  47.     {
  48.         $this->value $value;
  49.         return $this;
  50.     }
  51.     public function getTarget(): ?string
  52.     {
  53.         return $this->target;
  54.     }
  55.     public function setTarget(?string $target): self
  56.     {
  57.         $this->target $target;
  58.         return $this;
  59.     }
  60.     public function getUpdated(): ?\DateTimeImmutable
  61.     {
  62.         return $this->updated;
  63.     }
  64.     public function setUpdated(\DateTimeImmutable $updated): self
  65.     {
  66.         $this->updated $updated;
  67.         return $this;
  68.     }
  69.     public function getCompanyIndicatorThematic(): ?CompanyIndicatorThematic
  70.     {
  71.         return $this->companyIndicatorThematic;
  72.     }
  73.     public function setCompanyIndicatorThematic(?CompanyIndicatorThematic $companyIndicatorThematic): self
  74.     {
  75.         $this->companyIndicatorThematic $companyIndicatorThematic;
  76.         return $this;
  77.     }
  78.     public function getStatus(): array
  79.     {
  80.         if (!$this->target || !$this->value) {
  81.             $color "black";
  82.             $status "notmesured";
  83.         } else if (!$this->indicator->isReverse()) {
  84.             if ($this->value $this->target) {
  85.                 $color "late";
  86.                 $status "notreached";
  87.             } else {
  88.                 $color "terminated";
  89.                 $status "reached";
  90.             }
  91.         } else {
  92.             if ($this->value <= $this->target) {
  93.                 $color "terminated";
  94.                 $status "reached";
  95.             } else {
  96.                 $color "late";
  97.                 $status "notreached";
  98.             }
  99.         }
  100.         return ["status" => $status"color" => $color];
  101.     }
  102. }