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. use App\Entity\Scoring;
  8. /**
  9.  * @ORM\Entity(repositoryClass=ScoringQuestionRepository::class)
  10.  */
  11. class ScoringQuestion
  12. {
  13.     /**
  14.      * @ORM\Id
  15.      * @ORM\GeneratedValue
  16.      * @ORM\Column(type="integer")
  17.      */
  18.     private $id;
  19.     /**
  20.      * @ORM\Column(type="string", length=255)
  21.      */
  22.     private $label;
  23.     /**
  24.      * @ORM\Column(type="string", length=255, nullable=true)
  25.      */
  26.     private $description;
  27.     /**
  28.      * @ORM\Column(type="string", length=255, nullable=true)
  29.      */
  30.     private $subDescription;
  31.     /**
  32.      * @ORM\Column(type="string", length=255, nullable=true)
  33.      */
  34.     private $imageUrl;
  35.     /**
  36.      * @ORM\ManyToOne(targetEntity=ScoringSection::class, inversedBy="scoringQuestions")
  37.      * @ORM\JoinColumn(nullable=false)
  38.      */
  39.     private $scoringSection;
  40.     /**
  41.      * @ORM\OneToMany(targetEntity=ScoringAnswer::class, mappedBy="scoringQuestion", orphanRemoval=true)
  42.      */
  43.     private $scoringAnswers;
  44.     /**
  45.      * @ORM\Column(type="integer")
  46.      */
  47.     private $sort;
  48.     /**
  49.      * @ORM\Column(type="boolean")
  50.      */
  51.     private $image_active false;
  52.     /**
  53.      * @ORM\Column(type="boolean")
  54.      */
  55.     private $comment_active false;
  56.     /**
  57.      * @ORM\Column(type="float", options={"default": 1.0})
  58.      */
  59.     private $weight 1.0;
  60.     
  61.      /**
  62.      * @ORM\Column(type="text", nullable=true)
  63.      */
  64.     private $reco;
  65.     public function __construct()
  66.     {
  67.         $this->scoringAnswers = new ArrayCollection();
  68.     }
  69.     public function getId(): ?int
  70.     {
  71.         return $this->id;
  72.     }
  73.     public function getLabel(): ?string
  74.     {
  75.         return $this->label;
  76.     }
  77.     public function setLabel(string $label): self
  78.     {
  79.         $this->label $label;
  80.         return $this;
  81.     }
  82.     public function getDescription(): ?string
  83.     {
  84.         return $this->description;
  85.     }
  86.     public function setDescription(?string $description): self
  87.     {
  88.         $this->description $description;
  89.         return $this;
  90.     }
  91.     public function getSubDescription(): ?string
  92.     {
  93.         return $this->subDescription;
  94.     }
  95.     public function setSubDescription(?string $subDescription): self
  96.     {
  97.         $this->subDescription $subDescription;
  98.         return $this;
  99.     }
  100.     public function getImageUrl(): ?string
  101.     {
  102.         return $this->imageUrl;
  103.     }
  104.     public function setImageUrl(?string $imageUrl): self
  105.     {
  106.         $this->imageUrl $imageUrl;
  107.         return $this;
  108.     }
  109.     public function getScoringSection(): ?ScoringSection
  110.     {
  111.         return $this->scoringSection;
  112.     }
  113.     public function setScoringSection(?ScoringSection $scoringSection): self
  114.     {
  115.         $this->scoringSection $scoringSection;
  116.         return $this;
  117.     }
  118.     /**
  119.      * @return Collection<int, ScoringAnswer>
  120.      */
  121.     public function getScoringAnswers(): Collection
  122.     {
  123.         return $this->scoringAnswers;
  124.     }
  125.     public function addScoringAnswer(ScoringAnswer $scoringAnswer): self
  126.     {
  127.         if (!$this->scoringAnswers->contains($scoringAnswer)) {
  128.             $this->scoringAnswers[] = $scoringAnswer;
  129.             $scoringAnswer->setScoringQuestion($this);
  130.         }
  131.         return $this;
  132.     }
  133.     public function removeScoringAnswer(ScoringAnswer $scoringAnswer): self
  134.     {
  135.         if ($this->scoringAnswers->removeElement($scoringAnswer)) {
  136.             // set the owning side to null (unless already changed)
  137.             if ($scoringAnswer->getScoringQuestion() === $this) {
  138.                 $scoringAnswer->setScoringQuestion(null);
  139.             }
  140.         }
  141.         return $this;
  142.     }
  143.     public function getSort(): ?int
  144.     {
  145.         return $this->sort;
  146.     }
  147.     public function setSort(int $sort): self
  148.     {
  149.         $this->sort $sort;
  150.         return $this;
  151.     }
  152.     public function isImageActive(): ?bool
  153.     {
  154.         return $this->image_active;
  155.     }
  156.     public function setImageActive(bool $image_active): self
  157.     {
  158.         $this->image_active $image_active;
  159.         return $this;
  160.     }
  161.     public function isCommentActive(): ?bool
  162.     {
  163.         return $this->comment_active;
  164.     }
  165.     public function setCommentActive(bool $comment_active): self
  166.     {
  167.         $this->comment_active $comment_active;
  168.         return $this;
  169.     }
  170.     public function getWeight(): float
  171.     {
  172.         return $this->weight;
  173.     }
  174.     public function setWeight(float $weight): self
  175.     {
  176.         $this->weight $weight;
  177.         return $this;
  178.     }
  179.     /*public function calculateQuestionScore($weighted = true): ?float
  180.     {
  181.         $answer = $this->scoringAnswers->first();
  182.         
  183.         if (!$answer) {
  184.             return null;
  185.         }
  186.         
  187.         return $answer->getCalculatedValue($weighted);
  188.     }*/
  189.    
  190.     public function calculateQuestionScore(bool $weighted true, ?Scoring $scoring null): ?float
  191.     {
  192.         $answer null;
  193.         if ($scoring !== null) {
  194.             // on cherche la réponse qui appartient à CE scoring
  195.             foreach ($this->scoringAnswers as $a) {
  196.                 if ($a->getScoring() && $a->getScoring()->getId() === $scoring->getId()) {
  197.                     $answer $a;
  198.                     break;
  199.                 }
  200.             }
  201.         } else {
  202.             // fallback ancien comportement
  203.             $answer $this->scoringAnswers->first() ?: null;
  204.         }
  205.         if (!$answer) {
  206.             return null;
  207.         }
  208.         return $answer->getCalculatedValue($weighted);
  209.     }
  210.     public function calculateQuestionScoreForScoring(bool $weighted true, ?Scoring $scoring null): ?float
  211.     {
  212.         // si pas de scoring passé, on retombe sur le comportement historique
  213.         if ($scoring === null) {
  214.             return $this->calculateQuestionScore($weighted);
  215.         }
  216.         // on cherche la réponse qui appartient à CE scoring
  217.         $answer null;
  218.         foreach ($this->scoringAnswers as $a) {
  219.             if ($a->getScoring() && $a->getScoring()->getId() === $scoring->getId()) {
  220.                 $answer $a;
  221.                 break;
  222.             }
  223.         }
  224.         if (!$answer) {
  225.             return null;
  226.         }
  227.         return $answer->getCalculatedValue($weighted);
  228.     }
  229.     /**
  230.      * @return mixed
  231.      */
  232.     public function getReco() {
  233.         return $this->reco;
  234.     }
  235.     
  236.     /**
  237.      * @param mixed $reco 
  238.      * @return self
  239.      */
  240.     public function setReco($reco): self {
  241.         $this->reco $reco;
  242.         return $this;
  243.     }
  244. }