src/Entity/Objective.php line 13

  1. <?php
  2. namespace App\Entity;
  3. use DateTimeImmutable;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use App\Repository\ObjectiveRepository;
  8. use DateTime;
  9. #[ORM\Entity(repositoryClassObjectiveRepository::class)]
  10. class Objective
  11. {
  12.     #[ORM\Id]
  13.     #[ORM\GeneratedValue]
  14.     #[ORM\Column]
  15.     private ?int $id null;
  16.     #[ORM\Column(length1000)]
  17.     private ?string $title null;
  18.     #[ORM\Column]
  19.     private ?\DateTimeImmutable $createdAt null;
  20.     #[ORM\Column]
  21.     private ?\DateTimeImmutable $targetAt null;
  22.     #[ORM\Column(nullabletrue)]
  23.     private ?\DateTimeImmutable $doneAt null;
  24.     #[ORM\ManyToOne]
  25.     #[ORM\JoinColumn(nullabletrue)]
  26.     private ?User $author null;
  27.     #[ORM\ManyToOne(inversedBy'actions')]
  28.     #[ORM\JoinColumn(nullablefalse)]
  29.     private ?Company $company null;
  30.     #[ORM\Column(length500nullabletrue)]
  31.     private ?string $resource null;
  32.     #[ORM\Column(length500nullabletrue)]
  33.     private ?string $kpi null;
  34.     #[ORM\OneToMany(mappedBy'objective'targetEntityAction::class, orphanRemovaltruefetch'EAGER')]
  35.     private Collection $actions;
  36.     #[ORM\Column(nullabletrue)]
  37.     private ?bool $paused null;
  38.     #[ORM\Column(nullabletrue)]
  39.     private ?\DateTimeImmutable $startAt null;
  40.     #[ORM\ManyToOne(inversedBy'objectives')]
  41.     private ?User $stakeholder null;
  42.     #[ORM\Column(length100nullabletrue)]
  43.     private ?string $stakeholderText null;
  44.     #[ORM\Column(length100nullabletrue)]
  45.     private ?string $type null;
  46.     #[ORM\Column(length100nullabletrue)]
  47.     private ?string $priority null;
  48.     public function __construct()
  49.     {
  50.         $this->createdAt = new DateTimeImmutable();
  51.         $this->actions = new ArrayCollection();
  52.     }
  53.     public function getStatus()
  54.     {
  55.         $now = new DateTimeImmutable();
  56.         if ($this->paused) {
  57.             $value = ["status" => "paused""date" => $this->targetAt->format('d/m/Y'), "dateNotFormatted" => $this->targetAt"text" => "En pause, la date cible est le ""textShort" => "En pause"];
  58.         } elseif ($this->startAt $now) {
  59.             $value = ["status" => "notstarted""date" => $this->targetAt->format('d/m/Y'), "dateNotFormatted" => $this->targetAt"text" => "Débute le ""textShort" => "Débute le "];
  60.         } elseif ($this->targetAt $now && !$this->doneAt) {
  61.             $value = ["status" => "late""date" => $this->targetAt->format('d/m/Y'), "dateNotFormatted" => $this->targetAt"text" => "En retard, la date cible Ã©tait le ""textShort" => "En retard depuis le"];
  62.         } elseif ($this->doneAt) {
  63.             $value = ["status" => "terminated""date" => $this->doneAt->format('d/m/Y'), "dateNotFormatted" => $this->doneAt,  "text" => "Terminé le ""textShort" => "Terminé le "];
  64.         } elseif ($this->targetAt $now) {
  65.             $value = ["status" => "ongoing""date" => $this->targetAt->format('d/m/Y'), "dateNotFormatted" => $this->targetAt"text" => "En cours, la date cible est le ""textShort" => "En cours pour le"];
  66.         }
  67.         return $value;
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getTitle(): ?string
  74.     {
  75.         return $this->title;
  76.     }
  77.     public function setTitle(string $title): self
  78.     {
  79.         $this->title $title;
  80.         return $this;
  81.     }
  82.     public function getCreatedAt(): ?\DateTimeImmutable
  83.     {
  84.         return $this->createdAt;
  85.     }
  86.     public function setCreatedAt(\DateTimeImmutable $createdAt): self
  87.     {
  88.         $this->createdAt $createdAt;
  89.         return $this;
  90.     }
  91.     public function getTargetAt(): ?\DateTimeImmutable
  92.     {
  93.         return $this->targetAt;
  94.     }
  95.     public function setTargetAt(\DateTimeImmutable $targetAt): self
  96.     {
  97.         $this->targetAt $targetAt;
  98.         return $this;
  99.     }
  100.     public function getDoneAt(): ?\DateTimeImmutable
  101.     {
  102.         return $this->doneAt;
  103.     }
  104.     public function setDoneAt(?\DateTimeImmutable $doneAt): self
  105.     {
  106.         $this->doneAt $doneAt;
  107.         return $this;
  108.     }
  109.     public function getAuthor(): ?User
  110.     {
  111.         return $this->author;
  112.     }
  113.     public function setAuthor(?User $author): self
  114.     {
  115.         $this->author $author;
  116.         return $this;
  117.     }
  118.     public function getCompany(): ?Company
  119.     {
  120.         return $this->company;
  121.     }
  122.     public function setCompany(?Company $company): self
  123.     {
  124.         $this->company $company;
  125.         return $this;
  126.     }
  127.     public function getResource(): ?string
  128.     {
  129.         return $this->resource;
  130.     }
  131.     public function setResource(?string $resource): self
  132.     {
  133.         $this->resource $resource;
  134.         return $this;
  135.     }
  136.     public function getKpi(): ?string
  137.     {
  138.         return $this->kpi;
  139.     }
  140.     public function setKpi(?string $kpi): self
  141.     {
  142.         $this->kpi $kpi;
  143.         return $this;
  144.     }
  145.     /**
  146.      * @return Collection<int, Action>
  147.      */
  148.     public function getActions(): Collection
  149.     {
  150.         return $this->actions;
  151.     }
  152.     public function addAction(Action $actionDetail): self
  153.     {
  154.         if (!$this->actions->contains($actionDetail)) {
  155.             $this->actions->add($actionDetail);
  156.             $actionDetail->setObjective($this);
  157.         }
  158.         return $this;
  159.     }
  160.     public function removeAction(Action $actionDetail): self
  161.     {
  162.         if ($this->actions->removeElement($actionDetail)) {
  163.             // set the owning side to null (unless already changed)
  164.             if ($actionDetail->getObjective() === $this) {
  165.                 $actionDetail->setObjective(null);
  166.             }
  167.         }
  168.         return $this;
  169.     }
  170.     public function getDetailsCompleted()
  171.     {
  172.         if (count($this->actions) == 0) {
  173.             $value = ['percentage' => 0"percentageColor" => "paused""validated" => 0"total" => 0];
  174.         } else {
  175.             $validated 0;
  176.             $notValidated 0;
  177.             foreach ($this->actions as $key => $detail) {
  178.                 if ($detail->isStatus()) {
  179.                     $validated++;
  180.                 } else {
  181.                     $notValidated++;
  182.                 }
  183.             }
  184.             $percentage round($validated count($this->actions) * 100);
  185.             // dd($percentage);
  186.             if ($percentage == 0) {
  187.                 $percentageColor "paused";
  188.             } elseif ($percentage 33) {
  189.                 $percentageColor "late";
  190.             } elseif ($percentage 100) {
  191.                 $percentageColor "ongoing";
  192.             } else {
  193.                 $percentageColor "terminated";
  194.             }
  195.             $value = ['percentage' => $percentage"percentageColor" => $percentageColor"validated" => $validated"total" => count($this->actions)];
  196.         }
  197.         return $value;
  198.     }
  199.     public function isPaused(): ?bool
  200.     {
  201.         return $this->paused;
  202.     }
  203.     public function setPaused(?bool $paused): self
  204.     {
  205.         $this->paused $paused;
  206.         return $this;
  207.     }
  208.     public function getStartAt(): ?\DateTimeImmutable
  209.     {
  210.         return $this->startAt;
  211.     }
  212.     public function setStartAt(?\DateTimeImmutable $startAt): self
  213.     {
  214.         $this->startAt $startAt;
  215.         return $this;
  216.     }
  217.     public function getStakeholderLabel()
  218.     {
  219.         if ($this->stakeholder && $this->stakeholderText) {
  220.             return $this->stakeholder->getName() . ", " $this->stakeholderText;
  221.         } else if ($this->stakeholder) {
  222.             return $this->stakeholder->getName();
  223.         } else if ($this->stakeholderText) {
  224.             return $this->stakeholderText;
  225.         } else {
  226.             return "-";
  227.         }
  228.     }
  229.     public function getStakeholder(): ?User
  230.     {
  231.         return $this->stakeholder;
  232.     }
  233.     public function setStakeholder(?User $stakeholder): self
  234.     {
  235.         $this->stakeholder $stakeholder;
  236.         return $this;
  237.     }
  238.     public function getStakeholderText(): ?string
  239.     {
  240.         return $this->stakeholderText;
  241.     }
  242.     public function setStakeholderText(?string $stakeholderText): self
  243.     {
  244.         $this->stakeholderText $stakeholderText;
  245.         return $this;
  246.     }
  247.     public function getType(): ?string
  248.     {
  249.         return $this->type;
  250.     }
  251.     public function setType(string $type): static
  252.     {
  253.         $this->type $type;
  254.         return $this;
  255.     }
  256.     public function getTypeLabel()
  257.     {
  258.         if ($this->type == "label_nr") {
  259.             return "Label NR";
  260.         } elseif ($this->type == "bilan_carbone") {
  261.             return "Bilan Carbone";
  262.         } else if ($this->type == "audit_nr") {
  263.             return "Audit NR";
  264.         } else {
  265.             return "Autre";
  266.         }
  267.     }
  268.     public function getPriority(): ?string
  269.     {
  270.         return $this->priority;
  271.     }
  272.     public function setPriority(?string $priority): static
  273.     {
  274.         $this->priority $priority;
  275.         return $this;
  276.     }
  277. }