/**
  * Implements the abstract method
  *
  * @access protected
  *
  * @param \UJM\ExoBundle\Entity\InteractionQCM $interQCM
  */
 protected function onSuccessAdd($interQCM)
 {
     // \ pour instancier un objet du namespace global et non pas de l'actuel
     $interQCM->getInteraction()->getQuestion()->setDateCreate(new \Datetime());
     $interQCM->getInteraction()->getQuestion()->setUser($this->user);
     $interQCM->getInteraction()->setType('InteractionQCM');
     $pointsWrong = str_replace(',', '.', $interQCM->getScoreFalseResponse());
     $pointsRight = str_replace(',', '.', $interQCM->getScoreRightResponse());
     $interQCM->setScoreFalseResponse($pointsWrong);
     $interQCM->setScoreRightResponse($pointsRight);
     $this->em->persist($interQCM);
     $this->em->persist($interQCM->getInteraction()->getQuestion());
     $this->em->persist($interQCM->getInteraction());
     // On persiste tous les choices de l'interaction QCM.
     $ord = 1;
     foreach ($interQCM->getChoices() as $choice) {
         $choice->setOrdre($ord);
         $choice->setInteractionQCM($interQCM);
         $this->em->persist($choice);
         $ord = $ord + 1;
     }
     $this->persistHints($interQCM);
     $this->em->flush();
     $this->addAnExercise($interQCM);
     $this->duplicateInter($interQCM);
 }
 /**
  * Implements the abstract method.
  *
  *
  * @param \UJM\ExoBundle\Entity\InteractionQCM $interQCM
  */
 protected function onSuccessAdd($interQCM)
 {
     $interQCM->getQuestion()->setDateCreate(new \Datetime());
     $interQCM->getQuestion()->setUser($this->user);
     $pointsWrong = floatval($interQCM->getScoreFalseResponse());
     $pointsRight = floatval($interQCM->getScoreRightResponse());
     $interQCM->setScoreFalseResponse($pointsWrong);
     $interQCM->setScoreRightResponse($pointsRight);
     $this->em->persist($interQCM->getQuestion());
     $this->em->persist($interQCM);
     // On persiste tous les choices de l'interaction QCM.
     $ord = 1;
     foreach ($interQCM->getChoices() as $choice) {
         $choice->setOrdre($ord);
         $choice->setInteractionQCM($interQCM);
         $this->em->persist($choice);
         $ord = $ord + 1;
     }
     $this->persistHints($interQCM);
     $this->em->flush();
     $this->addAnExercise($interQCM);
     $this->duplicateInter($interQCM);
 }
Exemple #3
0
 /**
  * Calculate the score with global mark.
  *
  *
  * @param array [\UJM\ExoBundle\Entity\Choice] $allChoices choices linked at the QCM
  * @param array [integer]                      $response   array of id Choice selected
  * @param \UJM\ExoBundle\Entity\InteractionQCM $interQCM
  * @param float                                $penalty    penalty if the user showed hints
  *
  * @return float
  */
 private function markGlobal($allChoices, $response, $interQCM, $penalty)
 {
     $score = 0;
     $rightChoices = array();
     foreach ($allChoices as $choice) {
         if ($choice->getRightResponse()) {
             $rightChoices[] = (string) $choice->getId();
         }
     }
     $result = array_diff($response, $rightChoices);
     $resultBis = array_diff($rightChoices, $response);
     if (count($result) == 0 && count($resultBis) == 0) {
         $score = $interQCM->getScoreRightResponse() - $penalty;
     } else {
         $score = $interQCM->getScoreFalseResponse() - $penalty;
     }
     if ($score < 0) {
         $score = 0;
     }
     return $score;
 }