/** * 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); }
/** * {@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); }