src/Entity/Questionnaire.php line 12

  1. <?php
  2. namespace App\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Symfony\UX\Chartjs\Model\Chart;
  5. use App\Repository\QuestionnaireRepository;
  6. use Doctrine\Common\Collections\Collection;
  7. use Doctrine\Common\Collections\ArrayCollection;
  8. #[ORM\Entity(repositoryClassQuestionnaireRepository::class)]
  9. class Questionnaire
  10. {
  11.     #[ORM\Id]
  12.     #[ORM\GeneratedValue]
  13.     #[ORM\Column]
  14.     private ?int $id null;
  15.     #[ORM\Column(length255)]
  16.     private ?string $name null;
  17.     #[ORM\OneToMany(mappedBy'questionnaire'targetEntitySubThematic::class, fetch"EAGER")]
  18.     private Collection $subThematics;
  19.     #[ORM\OneToMany(mappedBy'questionnaire'targetEntityEvaluation::class)]
  20.     private Collection $evaluations;
  21.     #[ORM\ManyToOne(inversedBy'questionnaires')]
  22.     #[ORM\JoinColumn(nullablefalse)]
  23.     private ?Thematic $thematic null;
  24.     #[ORM\OneToMany(mappedBy'questionnaire'targetEntityCompanyQuestionnaire::class, orphanRemovaltrue)]
  25.     private Collection $companyQuestionnaires;
  26.     private ?Evaluation $lastEvaluation null;
  27.     private ?array $otherEvaluations null;
  28.     private ?array $actions null;
  29.     private ?Chart $chart null;
  30.     public function __construct()
  31.     {
  32.         $this->subThematics = new ArrayCollection();
  33.         $this->evaluations = new ArrayCollection();
  34.         $this->companyQuestionnaires = new ArrayCollection();
  35.     }
  36.     public function __toString()
  37.     {
  38.         return $this->name;
  39.     }
  40.     public function getId(): ?int
  41.     {
  42.         return $this->id;
  43.     }
  44.     public function getName(): ?string
  45.     {
  46.         return $this->name;
  47.     }
  48.     public function setName(string $name): self
  49.     {
  50.         $this->name $name;
  51.         return $this;
  52.     }
  53.     public function getChart(): ?Chart
  54.     {
  55.         return $this->chart;
  56.     }
  57.     public function setChart(Chart $chart): self
  58.     {
  59.         $this->chart $chart;
  60.         return $this;
  61.     }
  62.     public function getObjectives(): ?array
  63.     {
  64.         return $this->actions;
  65.     }
  66.     public function setObjectives(array $actions): self
  67.     {
  68.         $this->actions $actions;
  69.         return $this;
  70.     }
  71.     public function getObjectivesCompleted(): ?array
  72.     {
  73.         $numberOfActions 0;
  74.         $numberOfActionsCompleted 0;
  75.         if ($this->getObjectives()) {
  76.             foreach ($this->getObjectives() as $key => $action) {
  77.                 $numberOfActions $numberOfActions $action->getDetailsCompleted()['total'];
  78.                 $numberOfActionsCompleted $numberOfActionsCompleted $action->getDetailsCompleted()['validated'];
  79.             }
  80.         }
  81.         $percentage 0;
  82.         if ($numberOfActions) {
  83.             $percentage round($numberOfActionsCompleted $numberOfActions 100);
  84.         }
  85.         return ['total' => $numberOfActions"validated" => $numberOfActionsCompleted"percentage" => $percentage];
  86.     }
  87.     public function getLastEvaluation(): ?Evaluation
  88.     {
  89.         return $this->lastEvaluation;
  90.     }
  91.     public function setLastEvaluation(Evaluation $lastEvaluation): self
  92.     {
  93.         $this->lastEvaluation $lastEvaluation;
  94.         return $this;
  95.     }
  96.     public function getOtherEvaluations(): ?array
  97.     {
  98.         return $this->otherEvaluations;
  99.     }
  100.     public function setOtherEvaluations(array $otherEvaluations): self
  101.     {
  102.         $this->otherEvaluations $otherEvaluations;
  103.         return $this;
  104.     }
  105.     /**
  106.      * @return Collection<int, SubThematic>
  107.      */
  108.     public function getSubThematics(): Collection
  109.     {
  110.         return $this->subThematics;
  111.     }
  112.     public function addSubThematic(SubThematic $subThematic): self
  113.     {
  114.         if (!$this->subThematics->contains($subThematic)) {
  115.             $this->subThematics->add($subThematic);
  116.             $subThematic->setQuestionnaire($this);
  117.         }
  118.         return $this;
  119.     }
  120.     public function removeSubThematic(SubThematic $subThematic): self
  121.     {
  122.         if ($this->subThematics->removeElement($subThematic)) {
  123.             // set the owning side to null (unless already changed)
  124.             if ($subThematic->getQuestionnaire() === $this) {
  125.                 $subThematic->setQuestionnaire(null);
  126.             }
  127.         }
  128.         return $this;
  129.     }
  130.     /**
  131.      * @return Collection<int, Evaluation>
  132.      */
  133.     public function getEvaluations(): Collection
  134.     {
  135.         return $this->evaluations;
  136.     }
  137.     public function addEvaluation(Evaluation $evaluation): self
  138.     {
  139.         if (!$this->evaluations->contains($evaluation)) {
  140.             $this->evaluations->add($evaluation);
  141.             $evaluation->setQuestionnaire($this);
  142.         }
  143.         return $this;
  144.     }
  145.     public function removeEvaluation(Evaluation $evaluation): self
  146.     {
  147.         if ($this->evaluations->removeElement($evaluation)) {
  148.             // set the owning side to null (unless already changed)
  149.             if ($evaluation->getQuestionnaire() === $this) {
  150.                 $evaluation->setQuestionnaire(null);
  151.             }
  152.         }
  153.         return $this;
  154.     }
  155.     public function getThematic(): ?Thematic
  156.     {
  157.         return $this->thematic;
  158.     }
  159.     public function setThematic(?Thematic $thematic): self
  160.     {
  161.         $this->thematic $thematic;
  162.         return $this;
  163.     }
  164.     /**
  165.      * @return Collection<int, CompanyQuestionnaire>
  166.      */
  167.     public function getCompanyQuestionnaires(): Collection
  168.     {
  169.         return $this->companyQuestionnaires;
  170.     }
  171.     public function addCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
  172.     {
  173.         if (!$this->companyQuestionnaires->contains($companyQuestionnaire)) {
  174.             $this->companyQuestionnaires->add($companyQuestionnaire);
  175.             $companyQuestionnaire->setQuestionnaire($this);
  176.         }
  177.         return $this;
  178.     }
  179.     public function removeCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
  180.     {
  181.         if ($this->companyQuestionnaires->removeElement($companyQuestionnaire)) {
  182.             // set the owning side to null (unless already changed)
  183.             if ($companyQuestionnaire->getQuestionnaire() === $this) {
  184.                 $companyQuestionnaire->setQuestionnaire(null);
  185.             }
  186.         }
  187.         return $this;
  188.     }
  189.     public function getQuestions(): ?array
  190.     {
  191.         $questions = [];
  192.         foreach ($this->subThematics as $key => $subThematic) {
  193.             $questions array_merge($questions$subThematic->getQuestions()->toArray());
  194.         }
  195.         return $questions;
  196.     }
  197.     public function isInvalid(): ?string
  198.     {
  199.         if (count($this->subThematics) == 0) {
  200.             return "subThematics";
  201.         }
  202.         foreach ($this->subThematics as $key => $subThematic) {
  203.             if (count($subThematic->getQuestions()) == 0) {
  204.                 return "questions";
  205.             }
  206.         }
  207.         return null;
  208.     }
  209. }