src/Entity/Questionnaire.php line 12
<?php
namespace App\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\UX\Chartjs\Model\Chart;
use App\Repository\QuestionnaireRepository;
use Doctrine\Common\Collections\Collection;
use Doctrine\Common\Collections\ArrayCollection;
#[ORM\Entity(repositoryClass: QuestionnaireRepository::class)]
class Questionnaire
{
#[ORM\Id]
#[ORM\GeneratedValue]
#[ORM\Column]
private ?int $id = null;
#[ORM\Column(length: 255)]
private ?string $name = null;
#[ORM\OneToMany(mappedBy: 'questionnaire', targetEntity: SubThematic::class, fetch: "EAGER")]
private Collection $subThematics;
#[ORM\OneToMany(mappedBy: 'questionnaire', targetEntity: Evaluation::class)]
private Collection $evaluations;
#[ORM\ManyToOne(inversedBy: 'questionnaires')]
#[ORM\JoinColumn(nullable: false)]
private ?Thematic $thematic = null;
#[ORM\OneToMany(mappedBy: 'questionnaire', targetEntity: CompanyQuestionnaire::class, orphanRemoval: true)]
private Collection $companyQuestionnaires;
private ?Evaluation $lastEvaluation = null;
private ?array $otherEvaluations = null;
private ?array $actions = null;
private ?Chart $chart = null;
public function __construct()
{
$this->subThematics = new ArrayCollection();
$this->evaluations = new ArrayCollection();
$this->companyQuestionnaires = new ArrayCollection();
}
public function __toString()
{
return $this->name;
}
public function getId(): ?int
{
return $this->id;
}
public function getName(): ?string
{
return $this->name;
}
public function setName(string $name): self
{
$this->name = $name;
return $this;
}
public function getChart(): ?Chart
{
return $this->chart;
}
public function setChart(Chart $chart): self
{
$this->chart = $chart;
return $this;
}
public function getObjectives(): ?array
{
return $this->actions;
}
public function setObjectives(array $actions): self
{
$this->actions = $actions;
return $this;
}
public function getObjectivesCompleted(): ?array
{
$numberOfActions = 0;
$numberOfActionsCompleted = 0;
if ($this->getObjectives()) {
foreach ($this->getObjectives() as $key => $action) {
$numberOfActions = $numberOfActions + $action->getDetailsCompleted()['total'];
$numberOfActionsCompleted = $numberOfActionsCompleted + $action->getDetailsCompleted()['validated'];
}
}
$percentage = 0;
if ($numberOfActions) {
$percentage = round($numberOfActionsCompleted / $numberOfActions * 100);
}
return ['total' => $numberOfActions, "validated" => $numberOfActionsCompleted, "percentage" => $percentage];
}
public function getLastEvaluation(): ?Evaluation
{
return $this->lastEvaluation;
}
public function setLastEvaluation(Evaluation $lastEvaluation): self
{
$this->lastEvaluation = $lastEvaluation;
return $this;
}
public function getOtherEvaluations(): ?array
{
return $this->otherEvaluations;
}
public function setOtherEvaluations(array $otherEvaluations): self
{
$this->otherEvaluations = $otherEvaluations;
return $this;
}
/**
* @return Collection<int, SubThematic>
*/
public function getSubThematics(): Collection
{
return $this->subThematics;
}
public function addSubThematic(SubThematic $subThematic): self
{
if (!$this->subThematics->contains($subThematic)) {
$this->subThematics->add($subThematic);
$subThematic->setQuestionnaire($this);
}
return $this;
}
public function removeSubThematic(SubThematic $subThematic): self
{
if ($this->subThematics->removeElement($subThematic)) {
// set the owning side to null (unless already changed)
if ($subThematic->getQuestionnaire() === $this) {
$subThematic->setQuestionnaire(null);
}
}
return $this;
}
/**
* @return Collection<int, Evaluation>
*/
public function getEvaluations(): Collection
{
return $this->evaluations;
}
public function addEvaluation(Evaluation $evaluation): self
{
if (!$this->evaluations->contains($evaluation)) {
$this->evaluations->add($evaluation);
$evaluation->setQuestionnaire($this);
}
return $this;
}
public function removeEvaluation(Evaluation $evaluation): self
{
if ($this->evaluations->removeElement($evaluation)) {
// set the owning side to null (unless already changed)
if ($evaluation->getQuestionnaire() === $this) {
$evaluation->setQuestionnaire(null);
}
}
return $this;
}
public function getThematic(): ?Thematic
{
return $this->thematic;
}
public function setThematic(?Thematic $thematic): self
{
$this->thematic = $thematic;
return $this;
}
/**
* @return Collection<int, CompanyQuestionnaire>
*/
public function getCompanyQuestionnaires(): Collection
{
return $this->companyQuestionnaires;
}
public function addCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
{
if (!$this->companyQuestionnaires->contains($companyQuestionnaire)) {
$this->companyQuestionnaires->add($companyQuestionnaire);
$companyQuestionnaire->setQuestionnaire($this);
}
return $this;
}
public function removeCompanyQuestionnaire(CompanyQuestionnaire $companyQuestionnaire): self
{
if ($this->companyQuestionnaires->removeElement($companyQuestionnaire)) {
// set the owning side to null (unless already changed)
if ($companyQuestionnaire->getQuestionnaire() === $this) {
$companyQuestionnaire->setQuestionnaire(null);
}
}
return $this;
}
public function getQuestions(): ?array
{
$questions = [];
foreach ($this->subThematics as $key => $subThematic) {
$questions = array_merge($questions, $subThematic->getQuestions()->toArray());
}
return $questions;
}
public function isInvalid(): ?string
{
if (count($this->subThematics) == 0) {
return "subThematics";
}
foreach ($this->subThematics as $key => $subThematic) {
if (count($subThematic->getQuestions()) == 0) {
return "questions";
}
}
return null;
}
}