src/Entity/ScoringQuestion.php line 13

Open in your IDE?
  1. <?php
  2. namespace App\Entity;
  3. use App\Repository\ScoringQuestionRepository;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Collection;
  6. use Doctrine\ORM\Mapping as ORM;
  7. /**
  8.  * @ORM\Entity(repositoryClass=ScoringQuestionRepository::class)
  9.  */
  10. class ScoringQuestion
  11. {
  12.     /**
  13.      * @ORM\Id
  14.      * @ORM\GeneratedValue
  15.      * @ORM\Column(type="integer")
  16.      */
  17.     private $id;
  18.     /**
  19.      * @ORM\Column(type="string", length=255)
  20.      */
  21.     private $label;
  22.     /**
  23.      * @ORM\Column(type="string", length=255, nullable=true)
  24.      */
  25.     private $description;
  26.     /**
  27.      * @ORM\Column(type="string", length=255, nullable=true)
  28.      */
  29.     private $subDescription;
  30.     /**
  31.      * @ORM\Column(type="string", length=255, nullable=true)
  32.      */
  33.     private $imageUrl;
  34.     /**
  35.      * @ORM\ManyToOne(targetEntity=ScoringSection::class, inversedBy="scoringQuestions")
  36.      * @ORM\JoinColumn(nullable=false)
  37.      */
  38.     private $scoringSection;
  39.     /**
  40.      * @ORM\OneToMany(targetEntity=ScoringAnswer::class, mappedBy="scoringQuestion", orphanRemoval=true)
  41.      */
  42.     private $scoringAnswers;
  43.     /**
  44.      * @ORM\Column(type="integer")
  45.      */
  46.     private $sort;
  47.     /**
  48.      * @ORM\Column(type="boolean")
  49.      */
  50.     private $image_active false;
  51.     /**
  52.      * @ORM\Column(type="boolean")
  53.      */
  54.     private $comment_active false;
  55.     /**
  56.      * @ORM\Column(type="float", options={"default": 1.0})
  57.      */
  58.     private $weight 1.0;
  59.     public function __construct()
  60.     {
  61.         $this->scoringAnswers = new ArrayCollection();
  62.     }
  63.     public function getId(): ?int
  64.     {
  65.         return $this->id;
  66.     }
  67.     public function getLabel(): ?string
  68.     {
  69.         return $this->label;
  70.     }
  71.     public function setLabel(string $label): self
  72.     {
  73.         $this->label $label;
  74.         return $this;
  75.     }
  76.     public function getDescription(): ?string
  77.     {
  78.         return $this->description;
  79.     }
  80.     public function setDescription(?string $description): self
  81.     {
  82.         $this->description $description;
  83.         return $this;
  84.     }
  85.     public function getSubDescription(): ?string
  86.     {
  87.         return $this->subDescription;
  88.     }
  89.     public function setSubDescription(?string $subDescription): self
  90.     {
  91.         $this->subDescription $subDescription;
  92.         return $this;
  93.     }
  94.     public function getImageUrl(): ?string
  95.     {
  96.         return $this->imageUrl;
  97.     }
  98.     public function setImageUrl(?string $imageUrl): self
  99.     {
  100.         $this->imageUrl $imageUrl;
  101.         return $this;
  102.     }
  103.     public function getScoringSection(): ?ScoringSection
  104.     {
  105.         return $this->scoringSection;
  106.     }
  107.     public function setScoringSection(?ScoringSection $scoringSection): self
  108.     {
  109.         $this->scoringSection $scoringSection;
  110.         return $this;
  111.     }
  112.     /**
  113.      * @return Collection<int, ScoringAnswer>
  114.      */
  115.     public function getScoringAnswers(): Collection
  116.     {
  117.         return $this->scoringAnswers;
  118.     }
  119.     public function addScoringAnswer(ScoringAnswer $scoringAnswer): self
  120.     {
  121.         if (!$this->scoringAnswers->contains($scoringAnswer)) {
  122.             $this->scoringAnswers[] = $scoringAnswer;
  123.             $scoringAnswer->setScoringQuestion($this);
  124.         }
  125.         return $this;
  126.     }
  127.     public function removeScoringAnswer(ScoringAnswer $scoringAnswer): self
  128.     {
  129.         if ($this->scoringAnswers->removeElement($scoringAnswer)) {
  130.             // set the owning side to null (unless already changed)
  131.             if ($scoringAnswer->getScoringQuestion() === $this) {
  132.                 $scoringAnswer->setScoringQuestion(null);
  133.             }
  134.         }
  135.         return $this;
  136.     }
  137.     public function getSort(): ?int
  138.     {
  139.         return $this->sort;
  140.     }
  141.     public function setSort(int $sort): self
  142.     {
  143.         $this->sort $sort;
  144.         return $this;
  145.     }
  146.     public function isImageActive(): ?bool
  147.     {
  148.         return $this->image_active;
  149.     }
  150.     public function setImageActive(bool $image_active): self
  151.     {
  152.         $this->image_active $image_active;
  153.         return $this;
  154.     }
  155.     public function isCommentActive(): ?bool
  156.     {
  157.         return $this->comment_active;
  158.     }
  159.     public function setCommentActive(bool $comment_active): self
  160.     {
  161.         $this->comment_active $comment_active;
  162.         return $this;
  163.     }
  164.     public function getWeight(): float
  165.     {
  166.         return $this->weight;
  167.     }
  168.     public function setWeight(float $weight): self
  169.     {
  170.         $this->weight $weight;
  171.         return $this;
  172.     }
  173.     public function calculateQuestionScore($weighted true): ?float
  174.     {
  175.         $answer $this->scoringAnswers->first();
  176.         
  177.         if (!$answer) {
  178.             return null;
  179.         }
  180.         
  181.         return $answer->getCalculatedValue($weighted);
  182.     }
  183. }