/** * Control if the user is the owner of the category * If no, the default category of user will be used. * * @param \UJM\ExoBundle\Entity\Question $question */ public function ctrlCategory($question) { $user = $this->tokenStorage->getToken()->getUser(); $category = $question->getCategory(); if ($category->getUser()->getId() !== $user->getId()) { $userDefaultCategory = $this->doctrine->getManager()->getRepository('UJMExoBundle:Category')->findOneBy(['user' => $user, 'locker' => true]); if (!$userDefaultCategory) { $default = $this->translator->trans('default', [], 'ujm_exo'); $userDefaultCategory = $this->createCategoryDefault($default, $user); } $question->setCategory($userDefaultCategory); } }
/** * Get penalty for an interaction and a paper. * * @param \UJM\ExoBundle\Entity\Question $question * @param int $paperID * * @return float */ private function getPenaltyPaper($question, $paperID) { $em = $this->doctrine->getManager(); $penalty = 0; $hints = $question->getHints(); foreach ($hints as $hint) { $lhp = $em->getRepository('UJMExoBundle:LinkHintPaper')->getLHP($hint->getId(), $paperID); if (count($lhp) > 0) { $signe = substr($hint->getPenalty(), 0, 1); if ($signe === '-') { $penalty += substr($hint->getPenalty(), 1); } else { $penalty += $hint->getPenalty(); } } } return $penalty; }
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++; } }
/** * Ensures the format of the answer is correct and returns a list of * validation errors, if any. * * @param Question $question * @param mixed $data * * @return array * * @throws \UJM\ExoBundle\Transfer\Json\UnregisteredHandlerException */ public function validateAnswerFormat(Question $question, $data) { $handler = $this->handlerCollector->getHandlerForInteractionType($question->getType()); return $handler->validateAnswerFormat($question, $data); }
/** * Export submitted answers for one Question of the Paper. * * @param Question $question * @param Paper $paper * @param bool $withScore Do we need to export the score of the Paper ? * * @return array * * @throws \UJM\ExoBundle\Transfer\Json\UnregisteredHandlerException */ public function exportPaperAnswer(Question $question, Paper $paper, $withScore = false) { $responseRepo = $this->om->getRepository('UJMExoBundle:Response'); $handler = $this->handlerCollector->getHandlerForInteractionType($question->getType()); // TODO: these two queries must be moved out of the loop $response = $responseRepo->findOneBy(['paper' => $paper, 'question' => $question]); $usedHints = $this->hintManager->getUsedHints($paper, $question); $hints = array_map(function ($hint) { return $this->hintManager->exportHint($hint, true); // We always grab hint value for used hints }, $usedHints); $answer = $response ? $handler->convertAnswerDetails($response) : null; $answerScore = $response ? $response->getMark() : 0; $nbTries = $response ? $response->getNbTries() : 0; $paperQuestion = null; if ($response || count($hints) > 0) { $paperQuestion = ['id' => $question->getId(), 'answer' => $answer, 'hints' => $hints, 'nbTries' => $nbTries, 'score' => $withScore ? $answerScore : null]; } return $paperQuestion; }
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; }
/** * call method to export a question. * * @param \UJM\ExoBundle\Entity\Question $question */ public function export($question) { if ($question->getType() !== InteractionOpen::TYPE) { $service = 'ujm.exo_qti_export_' . $question->getType(); $qtiExport = $this->container->get($service); } else { $qtiExport = $this->serviceOpenQuestion($question->getId()); } return $qtiExport->export($question, $this); }
/** * @param Question $question */ public final function setQuestion(Question $question) { $this->question = $question; $question->setType(static::getQuestionType()); }