<?php
namespace App\Entity;
use App\Repository\ScoringAnswerRepository;
use Doctrine\ORM\Mapping as ORM;
use Vich\UploaderBundle\Mapping\Annotation as Vich;
use Symfony\Component\HttpFoundation\File\File;
/**
* @ORM\Entity(repositoryClass=ScoringAnswerRepository::class)
* @Vich\Uploadable
*/
class ScoringAnswer
{
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(type="integer")
*/
private $id;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $proposition_index;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $proposition_1_points;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $proposition_2_points;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $proposition_3_points;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $proposition_4_points;
/**
* @ORM\Column(type="integer", nullable=true)
*/
private $proposition_5_points;
/**
* @ORM\ManyToOne(targetEntity=Scoring::class, inversedBy="scoringAnswers")
* @ORM\JoinColumn(nullable=false, onDelete="cascade")
*/
private $scoring;
/**
* @ORM\ManyToOne(targetEntity=ScoringQuestion::class, inversedBy="scoringAnswers")
* @ORM\JoinColumn(nullable=false)
*/
private $scoringQuestion;
/**
* @ORM\Column(type="string", length=255, nullable=true)
*/
private $comment;
/**
* @Vich\UploadableField(mapping="scorings_image", fileNameProperty="fileName")
*/
private ?File $importFile = null;
/**
* @ORM\Column(type="datetime")
*/
private ?\DateTimeInterface $updatedAt = null;
/**
* @ORM\Column(type="string", nullable=true)
*/
private ?string $fileName = null;
public function getId(): ?int
{
return $this->id;
}
public function __construct()
{
$this->updatedAt = new \DateTimeImmutable();
}
public function getPropositionIndex(): ?int
{
return $this->proposition_index;
}
public function setPropositionIndex(?int $proposition_index): self
{
$this->proposition_index = $proposition_index;
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 getScoring(): ?Scoring
{
return $this->scoring;
}
public function setScoring(?Scoring $scoring): self
{
$this->scoring = $scoring;
return $this;
}
public function getScoringQuestion(): ?ScoringQuestion
{
return $this->scoringQuestion;
}
public function setScoringQuestion(?ScoringQuestion $scoringQuestion): self
{
$this->scoringQuestion = $scoringQuestion;
return $this;
}
public function setPropositionPointsForIndex(int $index): void
{
$this->setProposition1Points(null);
$this->setProposition2Points(null);
$this->setProposition3Points(null);
$this->setProposition4Points(null);
$this->setProposition5Points(null);
if ($index == 1)
$this->setProposition1Points($this->getScoringQuestion()->getScoringSection()->getProposition1Points());
else if ($index == 2)
$this->setProposition2Points($this->getScoringQuestion()->getScoringSection()->getProposition2Points());
else if ($index == 3)
$this->setProposition3Points($this->getScoringQuestion()->getScoringSection()->getProposition3Points());
else if ($index == 4)
$this->setProposition4Points($this->getScoringQuestion()->getScoringSection()->getProposition4Points());
else if ($index == 5)
$this->setProposition5Points($this->getScoringQuestion()->getScoringSection()->getProposition5Points());
}
public function getComment(): ?string
{
return $this->comment;
}
public function setComment(?string $comment): self
{
$this->comment = $comment;
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;
}
public function getSelectedPropositionPoints(): ?int
{
if (!$this->proposition_index) {
return null;
}
return match ($this->proposition_index) {
1 => $this->proposition_1_points,
2 => $this->proposition_2_points,
3 => $this->proposition_3_points,
4 => $this->proposition_4_points,
5 => $this->proposition_5_points,
default => null
};
}
public function getCalculatedValue($weighted = true): ?float
{
if (!$this->proposition_index || !$this->scoringQuestion) {
return null;
}
$selectedPoints = $this->getSelectedPropositionPoints();
if ($selectedPoints === null) {
return null;
}
if ($weighted)
return $selectedPoints * $this->scoringQuestion->getWeight();
else
return $selectedPoints;
}
public function getUpdatedAt(): ?\DateTimeInterface
{
return $this->updatedAt;
}
public function setUpdatedAt(\DateTimeInterface $updatedAt): self
{
$this->updatedAt = $updatedAt;
return $this;
}
//gestion reco : méthode pour récupérer les points de la proposition choisie
public function getSelectedPoints(): ?int
{
$index = $this->getPropositionIndex();
if (!$index || $index < 1 || $index > 5) {
return null;
}
$getter = 'getProposition' . $index . 'Points';
if (method_exists(object_or_class: $this, method: $getter)) {
return $this->$getter();
}
return null;
}
}