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