/** * 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(); }
public function matchQuestion($title, $labels = [], $proposals = []) { $question = new Question(); $question->setTitle($title); $question->setInvite('Invite...'); if (!$this->matchType) { $this->matchType = $this->om->getRepository('UJMExoBundle:TypeMatching')->findOneByCode(1); } $interactionMatching = new InteractionMatching(); $interactionMatching->setQuestion($question); $interactionMatching->setShuffle(false); $interactionMatching->setTypeMatching($this->matchType); for ($i = 0, $max = count($labels); $i < $max; ++$i) { $labels[$i]->setOrdre($i); $interactionMatching->addLabel($labels[$i]); } for ($i = 0, $max = count($proposals); $i < $max; ++$i) { $proposals[$i]->setOrdre($i + 1); $interactionMatching->addProposal($proposals[$i]); } $this->om->persist($interactionMatching); $this->om->persist($question); return $question; }