src/Entity/ScoringSection.php line 16

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ScoringSectionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Symfony\Component\HttpFoundation\File\File;
  8. use Vich\UploaderBundle\Mapping\Annotation as Vich;
  9. /**
  10.  * @ORM\Entity(repositoryClass=ScoringSectionRepository::class)
  11.  * @Vich\Uploadable
  12.  */
  13. class ScoringSection
  14. {
  15.     /**
  16.      * @ORM\Id
  17.      * @ORM\GeneratedValue
  18.      * @ORM\Column(type="integer")
  19.      */
  20.     private $id;
  21.     /**
  22.      * @ORM\ManyToOne(targetEntity=ScoringQuiz::class, inversedBy="scoringSections")
  23.      * @ORM\JoinColumn(nullable=false)
  24.      */
  25.     private $scoringQuiz;
  26.     /**
  27.      * @ORM\Column(type="string", length=255)
  28.      */
  29.     private $label;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $description;
  34.     /**
  35.      * @ORM\Column(type="string", length=255, nullable=false)
  36.      */
  37.     private $backgroundColor;
  38.     /**
  39.      * @ORM\Column(type="string", length=255, nullable=false)
  40.      */
  41.     private $titleColor;
  42.     /**
  43.      * @Vich\UploadableField(mapping="scorings_import", fileNameProperty="fileName")
  44.      */
  45.     private ?File $importFile null;
  46.     /**
  47.      * @ORM\Column(type="string", nullable=true)
  48.      */
  49.     private ?string $fileName null;
  50.     /**
  51.      * @ORM\Column(type="datetime")
  52.      */
  53.     private ?\DateTimeInterface $updatedAt null;
  54.     /**
  55.      * @ORM\OneToMany(targetEntity=ScoringQuestion::class, mappedBy="scoringSection", orphanRemoval=true)
  56.      */
  57.     private $scoringQuestions;
  58.     /**
  59.      * @ORM\Column(type="integer")
  60.      */
  61.     private $proposition_1_points;
  62.     /**
  63.      * @ORM\Column(type="integer")
  64.      */
  65.     private $proposition_2_points;
  66.     /**
  67.      * @ORM\Column(type="integer")
  68.      */
  69.     private $proposition_3_points;
  70.     /**
  71.      * @ORM\Column(type="integer")
  72.      */
  73.     private $proposition_4_points;
  74.     /**
  75.      * @ORM\Column(type="integer")
  76.      */
  77.     private $proposition_5_points;
  78.     /**
  79.      * @ORM\Column(type="boolean", options={"default": false})
  80.      */
  81.     private $proposition_1_active true;
  82.     /**
  83.      * @ORM\Column(type="boolean", options={"default": true})
  84.      */
  85.     private $proposition_2_active true;
  86.     /**
  87.      * @ORM\Column(type="boolean", options={"default": true})
  88.      */
  89.     private $proposition_3_active true;
  90.     /**
  91.      * @ORM\Column(type="boolean", options={"default": true})
  92.      */
  93.     private $proposition_4_active true;
  94.     /**
  95.      * @ORM\Column(type="boolean", options={"default": true})
  96.      */
  97.     private $proposition_5_active true;
  98.     /**
  99.      * @ORM\Column(type="integer")
  100.      */
  101.     private ?int $position;
  102.     /**
  103.      * @ORM\Column(type="boolean")
  104.      */
  105.     private $showLabel1 true;
  106.     /**
  107.      * @ORM\Column(type="string", length=255, nullable=true)
  108.      */
  109.     private $resultLabel1;
  110.     /**
  111.      * @ORM\Column(type="boolean")
  112.      */
  113.     private $showResponseButtons true;
  114.     /**
  115.      * @ORM\Column(type="boolean")
  116.      */
  117.     private $showLabel2 true;
  118.     /**
  119.      * @ORM\Column(type="string", length=255, nullable=true)
  120.      */
  121.     private $resultLabel2;
  122.     /**
  123.      * @ORM\Column(type="boolean")
  124.      */
  125.     private $showWeightedResult true;
  126.     public function __construct()
  127.     {
  128.         $this->scoringQuestions = new ArrayCollection();
  129.         $this->updatedAt = new \DateTimeImmutable();
  130.     }
  131.     public function getId(): ?int
  132.     {
  133.         return $this->id;
  134.     }
  135.     public function getScoringQuiz(): ?ScoringQuiz
  136.     {
  137.         return $this->scoringQuiz;
  138.     }
  139.     public function setScoringQuiz(?ScoringQuiz $scoringQuiz): self
  140.     {
  141.         $this->scoringQuiz $scoringQuiz;
  142.         return $this;
  143.     }
  144.     public function getLabel(): ?string
  145.     {
  146.         return $this->label;
  147.     }
  148.     public function setLabel(string $label): self
  149.     {
  150.         $this->label $label;
  151.         return $this;
  152.     }
  153.     public function getDescription(): ?string
  154.     {
  155.         return $this->description;
  156.     }
  157.     public function setDescription(?string $description): self
  158.     {
  159.         $this->description $description;
  160.         return $this;
  161.     }
  162.     public function getBackgroundColor(): string
  163.     {
  164.         return $this->backgroundColor;
  165.     }
  166.     public function setBackgroundColor(string $backgroundColor): self
  167.     {
  168.         $this->backgroundColor $backgroundColor;
  169.         return $this;
  170.     }
  171.     public function getTitleColor(): string
  172.     {
  173.         return $this->titleColor;
  174.     }
  175.     public function setTitleColor(string $titleColor): self
  176.     {
  177.         $this->titleColor $titleColor;
  178.         return $this;
  179.     }
  180.     /**
  181.      * If manually uploading a file (i.e. not using Symfony Form) ensure an instance
  182.      * of 'UploadedFile' is injected into this setter to trigger the update. If this
  183.      * bundle's configuration parameter 'inject_on_load' is set to 'true' this setter
  184.      * must be able to accept an instance of 'File' as the bundle will inject one here
  185.      * during Doctrine hydration.
  186.      *
  187.      * @param File|\Symfony\Component\HttpFoundation\File\UploadedFile|null $importFile
  188.      */
  189.     public function setImportFile(?File $importFile null): void
  190.     {
  191.         $this->importFile $importFile;
  192.         if (null !== $importFile) {
  193.             // It is required that at least one field changes if you are using doctrine
  194.             // otherwise the event listeners won't be called and the file is lost
  195.             $this->updatedAt = new \DateTimeImmutable();
  196.         }
  197.     }
  198.     public function getImportFile(): ?File
  199.     {
  200.         return $this->importFile;
  201.     }
  202.     public function setFileName(?string $fileName): void
  203.     {
  204.         $this->fileName $fileName;
  205.     }
  206.     public function getFileName(): ?string
  207.     {
  208.         return $this->fileName;
  209.     }
  210.     /**
  211.      * @return Collection<int, ScoringQuestion>
  212.      */
  213.     public function getScoringQuestions(): Collection
  214.     {
  215.         return $this->scoringQuestions;
  216.     }
  217.     public function addScoringQuestion(ScoringQuestion $scoringQuestion): self
  218.     {
  219.         if (!$this->scoringQuestions->contains($scoringQuestion)) {
  220.             $this->scoringQuestions[] = $scoringQuestion;
  221.             $scoringQuestion->setScoringSection($this);
  222.         }
  223.         return $this;
  224.     }
  225.     public function removeScoringQuestion(ScoringQuestion $scoringQuestion): self
  226.     {
  227.         if ($this->scoringQuestions->removeElement($scoringQuestion)) {
  228.             // set the owning side to null (unless already changed)
  229.             if ($scoringQuestion->getScoringSection() === $this) {
  230.                 $scoringQuestion->setScoringSection(null);
  231.             }
  232.         }
  233.         return $this;
  234.     }
  235.     public function getProposition1Points(): ?int
  236.     {
  237.         return $this->proposition_1_points;
  238.     }
  239.     public function setProposition1Points(int $proposition_1_points): self
  240.     {
  241.         $this->proposition_1_points $proposition_1_points;
  242.         return $this;
  243.     }
  244.     public function getProposition2Points(): ?int
  245.     {
  246.         return $this->proposition_2_points;
  247.     }
  248.     public function setProposition2Points(int $proposition_2_points): self
  249.     {
  250.         $this->proposition_2_points $proposition_2_points;
  251.         return $this;
  252.     }
  253.     public function getProposition3Points(): ?int
  254.     {
  255.         return $this->proposition_3_points;
  256.     }
  257.     public function setProposition3Points(int $proposition_3_points): self
  258.     {
  259.         $this->proposition_3_points $proposition_3_points;
  260.         return $this;
  261.     }
  262.     public function getProposition4Points(): ?int
  263.     {
  264.         return $this->proposition_4_points;
  265.     }
  266.     public function setProposition4Points(int $proposition_4_points): self
  267.     {
  268.         $this->proposition_4_points $proposition_4_points;
  269.         return $this;
  270.     }
  271.     public function getProposition5Points(): ?int
  272.     {
  273.         return $this->proposition_5_points;
  274.     }
  275.     public function setProposition5Points(int $proposition_5_points): self
  276.     {
  277.         $this->proposition_5_points $proposition_5_points;
  278.         return $this;
  279.     }
  280.     public function isProposition1Active(): ?bool
  281.     {
  282.         return $this->proposition_1_active;
  283.     }
  284.     public function setProposition1Active(bool $proposition_1_active): self
  285.     {
  286.         $this->proposition_1_active $proposition_1_active;
  287.         return $this;
  288.     }
  289.     public function isProposition2Active(): ?bool
  290.     {
  291.         return $this->proposition_2_active;
  292.     }
  293.     public function setProposition2Active(bool $proposition_2_active): self
  294.     {
  295.         $this->proposition_2_active $proposition_2_active;
  296.         return $this;
  297.     }
  298.     public function isProposition3Active(): ?bool
  299.     {
  300.         return $this->proposition_3_active;
  301.     }
  302.     public function setProposition3Active(bool $proposition_3_active): self
  303.     {
  304.         $this->proposition_3_active $proposition_3_active;
  305.         return $this;
  306.     }
  307.     public function isProposition4Active(): ?bool
  308.     {
  309.         return $this->proposition_4_active;
  310.     }
  311.     public function setProposition4Active(bool $proposition_4_active): self
  312.     {
  313.         $this->proposition_4_active $proposition_4_active;
  314.         return $this;
  315.     }
  316.     public function isProposition5Active(): ?bool
  317.     {
  318.         return $this->proposition_5_active;
  319.     }
  320.     public function setProposition5Active(bool $proposition_5_active): self
  321.     {
  322.         $this->proposition_5_active $proposition_5_active;
  323.         return $this;
  324.     }
  325.     private array $computedSums = [];
  326.     public function setComputedSums(array $sums): void
  327.     {
  328.         $this->computedSums $sums;
  329.     }
  330.     public function getComputedSums(): array
  331.     {
  332.         return $this->computedSums;
  333.     }
  334.     public function getPosition(): ?int
  335.     {
  336.         return $this->position;
  337.     }
  338.     public function setPosition(int $position): self
  339.     {
  340.         $this->position $position;
  341.         return $this;
  342.     }
  343.     public function calculateSectionScore($weighted true): float
  344.     {
  345.         $total 0;
  346.         foreach ($this->scoringQuestions as $question) {
  347.             $score $question->calculateQuestionScore($weighted);
  348.             if ($score !== null) {
  349.                 $total += $score;
  350.             }
  351.         }
  352.         return $total;
  353.     }
  354.     public function isShowLabel1(): bool
  355.     {
  356.         return $this->showLabel1;
  357.     }
  358.     public function setShowLabel1(bool $showLabel1): self
  359.     {
  360.         $this->showLabel1 $showLabel1;
  361.         return $this;
  362.     }
  363.     public function getResultLabel1(): ?string
  364.     {
  365.         return $this->resultLabel1;
  366.     }
  367.     public function setResultLabel1(?string $resultLabel1): self
  368.     {
  369.         $this->resultLabel1 $resultLabel1;
  370.         return $this;
  371.     }
  372.     public function isShowResponseButtons(): bool
  373.     {
  374.         return $this->showResponseButtons;
  375.     }
  376.     public function setShowResponseButtons(bool $showResponseButtons): self
  377.     {
  378.         $this->showResponseButtons $showResponseButtons;
  379.         return $this;
  380.     }
  381.     public function isShowLabel2(): bool
  382.     {
  383.         return $this->showLabel2;
  384.     }
  385.     public function setShowLabel2(bool $showLabel2): self
  386.     {
  387.         $this->showLabel2 $showLabel2;
  388.         return $this;
  389.     }
  390.     public function getResultLabel2(): ?string
  391.     {
  392.         return $this->resultLabel2;
  393.     }
  394.     public function setResultLabel2(?string $resultLabel2): self
  395.     {
  396.         $this->resultLabel2 $resultLabel2;
  397.         return $this;
  398.     }
  399.     public function isShowWeightedResult(): bool
  400.     {
  401.         return $this->showWeightedResult;
  402.     }
  403.     public function setShowWeightedResult(bool $showWeightedResult): self
  404.     {
  405.         $this->showWeightedResult $showWeightedResult;
  406.         return $this;
  407.     }
  408.     public function getMaxPossibleScore(): float
  409.     {
  410.         $max 0;
  411.         foreach ($this->scoringQuestions as $question) {
  412.             $max += max(
  413.                 $this->proposition_1_points,
  414.                 $this->proposition_2_points,
  415.                 $this->proposition_3_points,
  416.                 $this->proposition_4_points,
  417.                 $this->proposition_5_points
  418.             ) * $question->getWeight();
  419.         }
  420.         return $max;
  421.     }
  422.     public function getCompletionRatio(Scoring $scoring): string
  423.     {
  424.         return $scoring->getSectionCompletionRatio($this);
  425.     }
  426. }