<?php
namespace App\Entity;
use App\Repository\ScoringSectionRepository;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\Common\Collections\Collection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\HttpFoundation\File\File;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use App\Entity\Scoring;
/**
* @ORM\Entity(repositoryClass=ScoringSectionRepository::class)
* @Vich\Uploadable
*/
class ScoringSection
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\ManyToOne(targetEntity=ScoringQuiz::class, inversedBy="scoringSections")
* @ORM\JoinColumn(nullable=false)
*/
private $scoringQuiz;
/**
* @ORM\Column(type="string", length=255)
*/
private $label;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $description;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $backgroundColor;
/**
* @ORM\Column(type="string", length=255, nullable=false)
*/
private $titleColor;
/**
* @Vich\UploadableField(mapping="scorings_import", fileNameProperty="fileName")
*/
private ?File $importFile = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $fileName = null;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $updatedAt = null;
/**
* @ORM\OneToMany(targetEntity=ScoringQuestion::class, mappedBy="scoringSection", orphanRemoval=true)
*/
private $scoringQuestions;
/**
* @ORM\Column(type="integer")
*/
private $proposition_1_points;
/**
* @ORM\Column(type="integer")
*/
private $proposition_2_points;
/**
* @ORM\Column(type="integer")
*/
private $proposition_3_points;
/**
* @ORM\Column(type="integer")
*/
private $proposition_4_points;
/**
* @ORM\Column(type="integer")
*/
private $proposition_5_points;
/**
* @ORM\Column(type="boolean", options={"default": false})
*/
private $proposition_1_active = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
private $proposition_2_active = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
private $proposition_3_active = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
private $proposition_4_active = true;
/**
* @ORM\Column(type="boolean", options={"default": true})
*/
private $proposition_5_active = true;
/**
* @ORM\Column(type="integer")
*/
private ?int $position;
/**
* @ORM\Column(type="boolean")
*/
private $showLabel1 = true;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $resultLabel1;
/**
* @ORM\Column(type="boolean")
*/
private $showResponseButtons = true;
/**
* @ORM\Column(type="boolean")
*/
private $showLabel2 = true;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $resultLabel2;
/**
* @ORM\Column(type="boolean")
*/
private $showWeightedResult = true;
public function __construct()
{
$this->scoringQuestions = new ArrayCollection();
$this->updatedAt = new \DateTimeImmutable();
}
public function getId(): ?int
{
return $this->id;
}
public function getScoringQuiz(): ?ScoringQuiz
{
return $this->scoringQuiz;
}
public function setScoringQuiz(?ScoringQuiz $scoringQuiz): self
{
$this->scoringQuiz = $scoringQuiz;
return $this;
}
public function getLabel(): ?string
{
return $this->label;
}
public function setLabel(string $label): self
{
$this->label = $label;
return $this;
}
public function getDescription(): ?string
{
return $this->description;
}
public function setDescription(?string $description): self
{
$this->description = $description;
return $this;
}
public function getBackgroundColor(): string
{
return $this->backgroundColor;
}
public function setBackgroundColor(string $backgroundColor): self
{
$this->backgroundColor = $backgroundColor;
return $this;
}
public function getTitleColor(): string
{
return $this->titleColor;
}
public function setTitleColor(string $titleColor): self
{
$this->titleColor = $titleColor;
return $this;
}
/**
* If manually uploading a file (i.e. not using Symfony Form) ensure an instance
* of 'UploadedFile' is injected into this setter to trigger the update. If this
* bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
* must be able to accept an instance of 'File' as the bundle will inject one here
* during Doctrine hydration.
*
* @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $importFile
*/
public function setImportFile(?File $importFile = null): void
{
$this->importFile = $importFile;
if (null !== $importFile) {
// It is required that at least one field changes if you are using doctrine
// otherwise the event listeners won't be called and the file is lost
$this->updatedAt = new \DateTimeImmutable();
}
}
public function getImportFile(): ?File
{
return $this->importFile;
}
public function setFileName(?string $fileName): void
{
$this->fileName = $fileName;
}
public function getFileName(): ?string
{
return $this->fileName;
}
/**
* @return Collection<int, ScoringQuestion>
*/
public function getScoringQuestions(): Collection
{
return $this->scoringQuestions;
}
public function addScoringQuestion(ScoringQuestion $scoringQuestion): self
{
if (!$this->scoringQuestions->contains($scoringQuestion)) {
$this->scoringQuestions[] = $scoringQuestion;
$scoringQuestion->setScoringSection($this);
}
return $this;
}
public function removeScoringQuestion(ScoringQuestion $scoringQuestion): self
{
if ($this->scoringQuestions->removeElement($scoringQuestion)) {
// set the owning side to null (unless already changed)
if ($scoringQuestion->getScoringSection() === $this) {
$scoringQuestion->setScoringSection(null);
}
}
return $this;
}
public function getProposition1Points(): ?int
{
return $this->proposition_1_points;
}
public function setProposition1Points(int $proposition_1_points): self
{
$this->proposition_1_points = $proposition_1_points;
return $this;
}
public function getProposition2Points(): ?int
{
return $this->proposition_2_points;
}
public function setProposition2Points(int $proposition_2_points): self
{
$this->proposition_2_points = $proposition_2_points;
return $this;
}
public function getProposition3Points(): ?int
{
return $this->proposition_3_points;
}
public function setProposition3Points(int $proposition_3_points): self
{
$this->proposition_3_points = $proposition_3_points;
return $this;
}
public function getProposition4Points(): ?int
{
return $this->proposition_4_points;
}
public function setProposition4Points(int $proposition_4_points): self
{
$this->proposition_4_points = $proposition_4_points;
return $this;
}
public function getProposition5Points(): ?int
{
return $this->proposition_5_points;
}
public function setProposition5Points(int $proposition_5_points): self
{
$this->proposition_5_points = $proposition_5_points;
return $this;
}
public function isProposition1Active(): ?bool
{
return $this->proposition_1_active;
}
public function setProposition1Active(bool $proposition_1_active): self
{
$this->proposition_1_active = $proposition_1_active;
return $this;
}
public function isProposition2Active(): ?bool
{
return $this->proposition_2_active;
}
public function setProposition2Active(bool $proposition_2_active): self
{
$this->proposition_2_active = $proposition_2_active;
return $this;
}
public function isProposition3Active(): ?bool
{
return $this->proposition_3_active;
}
public function setProposition3Active(bool $proposition_3_active): self
{
$this->proposition_3_active = $proposition_3_active;
return $this;
}
public function isProposition4Active(): ?bool
{
return $this->proposition_4_active;
}
public function setProposition4Active(bool $proposition_4_active): self
{
$this->proposition_4_active = $proposition_4_active;
return $this;
}
public function isProposition5Active(): ?bool
{
return $this->proposition_5_active;
}
public function setProposition5Active(bool $proposition_5_active): self
{
$this->proposition_5_active = $proposition_5_active;
return $this;
}
private array $computedSums = [];
public function setComputedSums(array $sums): void
{
$this->computedSums = $sums;
}
public function getComputedSums(): array
{
return $this->computedSums;
}
public function getPosition(): ?int
{
return $this->position;
}
public function setPosition(int $position): self
{
$this->position = $position;
return $this;
}
/*public function calculateSectionScore($weighted = true): float
{
$total = 0;
foreach ($this->scoringQuestions as $question) {
$score = $question->calculateQuestionScore($weighted);
if ($score !== null) {
$total += $score;
}
}
return $total;
}*/
public function calculateSectionScore(bool $weighted = true, ?Scoring $scoring = null): float
{
$total = 0;
foreach ($this->scoringQuestions as $question) {
if ($scoring !== null) {
$score = $question->calculateQuestionScoreForScoring($weighted, $scoring);
} else {
$score = $question->calculateQuestionScore($weighted);
}
if ($score !== null) {
$total += $score;
}
}
return $total;
}
public function isShowLabel1(): bool
{
return $this->showLabel1;
}
public function setShowLabel1(bool $showLabel1): self
{
$this->showLabel1 = $showLabel1;
return $this;
}
public function getResultLabel1(): ?string
{
return $this->resultLabel1;
}
public function setResultLabel1(?string $resultLabel1): self
{
$this->resultLabel1 = $resultLabel1;
return $this;
}
public function isShowResponseButtons(): bool
{
return $this->showResponseButtons;
}
public function setShowResponseButtons(bool $showResponseButtons): self
{
$this->showResponseButtons = $showResponseButtons;
return $this;
}
public function isShowLabel2(): bool
{
return $this->showLabel2;
}
public function setShowLabel2(bool $showLabel2): self
{
$this->showLabel2 = $showLabel2;
return $this;
}
public function getResultLabel2(): ?string
{
return $this->resultLabel2;
}
public function setResultLabel2(?string $resultLabel2): self
{
$this->resultLabel2 = $resultLabel2;
return $this;
}
public function isShowWeightedResult(): bool
{
return $this->showWeightedResult;
}
public function setShowWeightedResult(bool $showWeightedResult): self
{
$this->showWeightedResult = $showWeightedResult;
return $this;
}
public function getMaxPossibleScore(): float
{
$max = 0;
foreach ($this->scoringQuestions as $question) {
$max += max(
$this->proposition_1_points,
$this->proposition_2_points,
$this->proposition_3_points,
$this->proposition_4_points,
$this->proposition_5_points
) * $question->getWeight();
}
return $max;
}
public function getCompletionRatio(Scoring $scoring): string
{
return $scoring->getSectionCompletionRatio($this);
}
}