public function load(ObjectManager $manager)
 {
     $typeQCM = $manager->getRepository('UJMExoBundle:TypeQCM')->findOneById(2);
     //QCU
     $interactionqcm = new InteractionQCM();
     $interactionqcm->setTypeQCM($typeQCM);
     $interactionqcm->setInteraction($this->getReference('interaction1'));
     $manager->persist($interactionqcm);
     $manager->flush();
     $this->addReference('interactionqcm1', $interactionqcm);
     $interactionqcm = new InteractionQCM();
     $interactionqcm->setTypeQCM($typeQCM);
     $interactionqcm->setInteraction($this->getReference('interaction2'));
     $manager->persist($interactionqcm);
     $manager->flush();
     $this->addReference('interactionqcm2', $interactionqcm);
 }
 /**
  * Implements the abstract method
  *
  * @access public
  *
  * @param \UJM\ExoBundle\Entity\InteractionQCM $originalInterQCM
  *
  * Return boolean
  */
 public function processUpdate($originalInterQCM)
 {
     $originalChoices = array();
     $originalHints = array();
     // Create an array of the current Choice objects in the database
     foreach ($originalInterQCM->getChoices() as $choice) {
         $originalChoices[] = $choice;
     }
     foreach ($originalInterQCM->getInteraction()->getHints() as $hint) {
         $originalHints[] = $hint;
     }
     if ($this->request->getMethod() == 'POST') {
         $this->form->handleRequest($this->request);
         if ($this->form->isValid()) {
             $this->onSuccessUpdate($this->form->getData(), $originalChoices, $originalHints);
             return true;
         }
     }
     return false;
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function persistInteractionDetails(Question $question, \stdClass $importData)
 {
     $interaction = new InteractionQCM();
     if ($importData->score->type === 'sum') {
         $interaction->setWeightResponse(true);
         //weighted true
     } elseif ($importData->score->type === 'fixed') {
         $interaction->setWeightResponse(false);
         //no weighted false
         $interaction->setScoreRightResponse($importData->score->success);
         $interaction->setScoreFalseResponse($importData->score->failure);
     }
     for ($i = 0, $max = count($importData->choices); $i < $max; ++$i) {
         // temporary limitation
         if ($importData->choices[$i]->type !== 'text/html') {
             throw new \Exception("Import not implemented for MIME type {$importData->choices[$i]->type}");
         }
         $choice = new Choice();
         $choice->setLabel($importData->choices[$i]->data);
         $choice->setOrdre($i);
         foreach ($importData->solutions as $solution) {
             if ($solution->id === $importData->choices[$i]->id) {
                 $choice->setWeight($solution->score);
                 if (0 < $solution->score) {
                     $choice->setRightResponse(true);
                 }
                 if (isset($solution->feedback)) {
                     $choice->setFeedback($solution->feedback);
                 }
             }
         }
         $choice->setInteractionQCM($interaction);
         $interaction->addChoice($choice);
         $this->om->persist($choice);
     }
     $subTypeCode = $importData->multiple ? 1 : 2;
     $subType = $this->om->getRepository('UJMExoBundle:TypeQCM')->findOneByCode($subTypeCode);
     $interaction->setTypeQCM($subType);
     $interaction->setShuffle($importData->random);
     $interaction->setQuestion($question);
     $this->om->persist($interaction);
 }
Beispiel #4
0
 /**
  * @param string   $title
  * @param Choice[] $choices
  * @param string   $description
  *
  * @return Question
  */
 public function qcmQuestion($title, array $choices = [], $description = '')
 {
     $question = new Question();
     $question->setTitle($title);
     $question->setInvite('Invite...');
     $question->setDescription($description);
     if (!$this->multipleChoiceType) {
         $this->multipleChoiceType = $this->om->getRepository('UJMExoBundle:TypeQCM')->findOneByValue('Multiple response');
     }
     $interactionQcm = new InteractionQCM();
     $interactionQcm->setQuestion($question);
     $interactionQcm->setTypeQCM($this->multipleChoiceType);
     $interactionQcm->setWeightResponse(true);
     for ($i = 0, $max = count($choices); $i < $max; ++$i) {
         $choices[$i]->setOrdre($i);
         $interactionQcm->addChoice($choices[$i]);
     }
     $this->om->persist($interactionQcm);
     $this->om->persist($question);
     return $question;
 }
Beispiel #5
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;
 }