/** * Imports a question in a JSON-decoded format. * * @param \stdClass $data * * @throws ValidationException if the question is not valid * @throws \Exception if the question type import is not implemented */ public function importQuestion(\stdClass $data) { if (count($errors = $this->validator->validateQuestion($data)) > 0) { throw new ValidationException('Question is not valid', $errors); } $handler = $this->handlerCollector->getHandlerForMimeType($data->type); $question = new Question(); $question->setTitle($data->title); $question->setInvite($data->title); if (isset($data->hints)) { foreach ($data->hints as $hintData) { $hint = new Hint(); $hint->setValue($hintData->text); $hint->setPenalty($hintData->penalty); $question->addHint($hint); $this->om->persist($hint); } } if (isset($data->feedback)) { $question->setFeedback($data->feedback); } $handler->persistInteractionDetails($question, $data); $this->om->persist($question); $this->om->flush(); }
/** * Returns the contents of a hint and records a log asserting that the hint * has been consulted for a given paper. * * @param Paper $paper * @param Hint $hint * * @return string */ public function viewHint(Paper $paper, Hint $hint) { $log = $this->om->getRepository('UJMExoBundle:LinkHintPaper')->findOneBy(['paper' => $paper, 'hint' => $hint]); if (!$log) { $log = new LinkHintPaper($hint, $paper); $this->om->persist($log); $this->om->flush(); } return $hint->getValue(); }
/** * Returns whether a hint is related to a paper. * * @param Paper $paper * @param Hint $hint * * @return bool */ public function hasHint(Paper $paper, Hint $hint) { $qb = $this->createQueryBuilder('p'); $count = $qb->select('COUNT(p)')->join('p.exercise', 'e')->join('e.steps', 's')->join('s.stepQuestions', 'sq')->where('e = :exercise')->andWhere('sq.question = :question')->setParameters(['question' => $hint->getQuestion(), 'exercise' => $paper->getExercise()])->getQuery()->getSingleScalarResult(); return 0 < $count; }
public function hint(Question $question, $text, $penalty = 1) { $hint = new Hint(); $hint->setValue($text); $hint->setPenalty($penalty); $hint->setQuestion($question); $this->om->persist($hint); return $hint; }
public function addHint(\UJM\ExoBundle\Entity\Hint $hint) { $this->hints[] = $hint; //le choix est bien lié à l'entité interactionqcm, mais dans l'entité choice il faut //aussi lier l'interactionqcm double travail avec les relations bidirectionnelles avec //lesquelles il faut bien faire attention à garder les données cohérentes dans un autre //script il faudra exécuter $interaction->addHint() qui garde la cohérence entre les //deux entités, il ne faudra pas exécuter $hint->setInteraction(), car lui ne garde pas // la cohérence $hint->setInteraction($this); }