src/Entity/ScoringAnswer.php line 14

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ScoringAnswerRepository;
  4. use Doctrine\ORM\Mapping as ORM;
  5. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  6. use Symfony\Component\HttpFoundation\File\File;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ScoringAnswerRepository::class)
  9.  * @Vich\Uploadable
  10.  */
  11. class ScoringAnswer
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="integer", nullable=true)
  21.      */
  22.     private $proposition_index;
  23.     /**
  24.      * @ORM\Column(type="integer", nullable=true)
  25.      */
  26.     private $proposition_1_points;
  27.     /**
  28.      * @ORM\Column(type="integer", nullable=true)
  29.      */
  30.     private $proposition_2_points;
  31.     /**
  32.      * @ORM\Column(type="integer", nullable=true)
  33.      */
  34.     private $proposition_3_points;
  35.     /**
  36.      * @ORM\Column(type="integer", nullable=true)
  37.      */
  38.     private $proposition_4_points;
  39.     /**
  40.      * @ORM\Column(type="integer", nullable=true)
  41.      */
  42.     private $proposition_5_points;
  43.     /**
  44.      * @ORM\ManyToOne(targetEntity=Scoring::class, inversedBy="scoringAnswers")
  45.      * @ORM\JoinColumn(nullable=false, onDelete="cascade")
  46.      */
  47.     private $scoring;
  48.     /**
  49.      * @ORM\ManyToOne(targetEntity=ScoringQuestion::class, inversedBy="scoringAnswers")
  50.      * @ORM\JoinColumn(nullable=false)
  51.      */
  52.     private $scoringQuestion;
  53.     /**
  54.      * @ORM\Column(type="string", length=255, nullable=true)
  55.      */
  56.     private $comment;
  57.     /**
  58.      * @Vich\UploadableField(mapping="scorings_image", fileNameProperty="fileName")
  59.      */
  60.     private ?File $importFile null;
  61.     /**
  62.      * @ORM\Column(type="datetime")
  63.      */
  64.     private ?\DateTimeInterface $updatedAt null;
  65.     /**
  66.      * @ORM\Column(type="string", nullable=true)
  67.      */
  68.     private ?string $fileName null;
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function __construct()
  74.     {
  75.         $this->updatedAt = new \DateTimeImmutable();
  76.     }
  77.     public function getPropositionIndex(): ?int
  78.     {
  79.         return $this->proposition_index;
  80.     }
  81.     public function setPropositionIndex(?int $proposition_index): self
  82.     {
  83.         $this->proposition_index $proposition_index;
  84.         return $this;
  85.     }
  86.     public function getProposition1Points(): ?int
  87.     {
  88.         return $this->proposition_1_points;
  89.     }
  90.     public function setProposition1Points(?int $proposition_1_points): self
  91.     {
  92.         $this->proposition_1_points $proposition_1_points;
  93.         return $this;
  94.     }
  95.     public function getProposition2Points(): ?int
  96.     {
  97.         return $this->proposition_2_points;
  98.     }
  99.     public function setProposition2Points(?int $proposition_2_points): self
  100.     {
  101.         $this->proposition_2_points $proposition_2_points;
  102.         return $this;
  103.     }
  104.     public function getProposition3Points(): ?int
  105.     {
  106.         return $this->proposition_3_points;
  107.     }
  108.     public function setProposition3Points(?int $proposition_3_points): self
  109.     {
  110.         $this->proposition_3_points $proposition_3_points;
  111.         return $this;
  112.     }
  113.     public function getProposition4Points(): ?int
  114.     {
  115.         return $this->proposition_4_points;
  116.     }
  117.     public function setProposition4Points(?int $proposition_4_points): self
  118.     {
  119.         $this->proposition_4_points $proposition_4_points;
  120.         return $this;
  121.     }
  122.     public function getProposition5Points(): ?int
  123.     {
  124.         return $this->proposition_5_points;
  125.     }
  126.     public function setProposition5Points(?int $proposition_5_points): self
  127.     {
  128.         $this->proposition_5_points $proposition_5_points;
  129.         return $this;
  130.     }
  131.     public function getScoring(): ?Scoring
  132.     {
  133.         return $this->scoring;
  134.     }
  135.     public function setScoring(?Scoring $scoring): self
  136.     {
  137.         $this->scoring $scoring;
  138.         return $this;
  139.     }
  140.     public function getScoringQuestion(): ?ScoringQuestion
  141.     {
  142.         return $this->scoringQuestion;
  143.     }
  144.     public function setScoringQuestion(?ScoringQuestion $scoringQuestion): self
  145.     {
  146.         $this->scoringQuestion $scoringQuestion;
  147.         return $this;
  148.     }
  149.     public function setPropositionPointsForIndex(int $index): void
  150.     {
  151.         $this->setProposition1Points(null);
  152.         $this->setProposition2Points(null);
  153.         $this->setProposition3Points(null);
  154.         $this->setProposition4Points(null);
  155.         $this->setProposition5Points(null);
  156.         if ($index == 1)
  157.             $this->setProposition1Points($this->getScoringQuestion()->getScoringSection()->getProposition1Points());
  158.         else if ($index == 2)
  159.             $this->setProposition2Points($this->getScoringQuestion()->getScoringSection()->getProposition2Points());
  160.         else if ($index == 3)
  161.             $this->setProposition3Points($this->getScoringQuestion()->getScoringSection()->getProposition3Points());
  162.         else if ($index == 4)
  163.             $this->setProposition4Points($this->getScoringQuestion()->getScoringSection()->getProposition4Points());
  164.         else if ($index == 5)
  165.             $this->setProposition5Points($this->getScoringQuestion()->getScoringSection()->getProposition5Points());
  166.     }
  167.     public function getComment(): ?string
  168.     {
  169.         return $this->comment;
  170.     }
  171.     public function setComment(?string $comment): self
  172.     {
  173.         $this->comment $comment;
  174.         return $this;
  175.     }
  176.     /**
  177.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  178.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  179.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  180.      * must be able to accept an instance of 'File' as the bundle will inject one here
  181.      * during Doctrine hydration.
  182.      *
  183.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $importFile
  184.      */
  185.     public function setImportFile(?File $importFile null): void
  186.     {
  187.         $this->importFile $importFile;
  188.         if (null !== $importFile) {
  189.             // It is required that at least one field changes if you are using doctrine
  190.             // otherwise the event listeners won't be called and the file is lost
  191.             $this->updatedAt = new \DateTimeImmutable();
  192.         }
  193.     }
  194.     public function getImportFile(): ?File
  195.     {
  196.         return $this->importFile;
  197.     }
  198.     public function setFileName(?string $fileName): void
  199.     {
  200.         $this->fileName $fileName;
  201.     }
  202.     public function getFileName(): ?string
  203.     {
  204.         return $this->fileName;
  205.     }
  206.     public function getSelectedPropositionPoints(): ?int
  207.     {
  208.         if (!$this->proposition_index) {
  209.             return null;
  210.         }
  211.         return match ($this->proposition_index) {
  212.             => $this->proposition_1_points,
  213.             => $this->proposition_2_points,
  214.             => $this->proposition_3_points,
  215.             => $this->proposition_4_points,
  216.             => $this->proposition_5_points,
  217.             default => null
  218.         };
  219.     }
  220.     public function getCalculatedValue($weighted true): ?float
  221.     {
  222.         if (!$this->proposition_index || !$this->scoringQuestion) {
  223.             return null;
  224.         }
  225.         $selectedPoints $this->getSelectedPropositionPoints();
  226.         if ($selectedPoints === null) {
  227.             return null;
  228.         }
  229.         if ($weighted)
  230.             return $selectedPoints $this->scoringQuestion->getWeight();
  231.         else
  232.             return $selectedPoints;
  233.     }
  234.     public function getUpdatedAt(): ?\DateTimeInterface
  235.     {
  236.         return $this->updatedAt;
  237.     }
  238.     public function setUpdatedAt(\DateTimeInterface $updatedAt): self
  239.     {
  240.         $this->updatedAt $updatedAt;
  241.         return $this;
  242.     }
  243.     //gestion reco : méthode pour récupérer les points de la proposition choisie
  244.     public function getSelectedPoints(): ?int
  245.     {
  246.         $index $this->getPropositionIndex();
  247.         if (!$index || $index || $index 5) {
  248.             return null;
  249.         }
  250.         $getter 'getProposition' $index 'Points';
  251.         if (method_exists(object_or_class$thismethod$getter)) {
  252.             return $this->$getter();
  253.         }
  254.         return null;
  255.     }
  256. }