/** * 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 load(ObjectManager $manager) { /* //get user $em = $this->container->get('doctrine')->getEntityManager(); $user = $em->getRepository('ClarolineCoreBundle:User')->findOneById(1); */ $user = $manager->getRepository('ClarolineCoreBundle:User')->findOneById(1); $arr_data = array(array('QuestFIX title1', $this->getReference('category1'), $user), array('QuestFIX title2', $this->getReference('category1'), $user)); $inc = 1; foreach ($arr_data as $data) { $question = new Question(); $question->setTitle($data[0]); $question->setCategory($data[1]); $question->setUser($data[2]); $question->setDateCreate(new \DateTime()); $manager->persist($question); $manager->flush(); $this->addReference('question' . $inc, $question); $inc++; } }
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; }