/** * Export exercise with steps with questions. * * @param Exercise $exercise * @param bool $withSolutions * * @return array */ public function exportSteps(Exercise $exercise, $withSolutions = true) { $steps = $exercise->getSteps(); $data = []; foreach ($steps as $step) { $data[] = $this->stepManager->exportStep($step, $withSolutions); } return $data; }
/** * return steps of an exercise in an array. * * @param Exercise $object * @param string $exoTitle * @param array $files * * @return array */ private function getStepsToExport(Exercise $object, $exoTitle, array &$files) { /** @var \UJM\ExoBundle\Repository\QuestionRepository $questionRepo */ $questionRepo = $this->om->getRepository('UJMExoBundle:Question'); $steps = []; foreach ($object->getSteps() as $step) { $s = ['text' => $step->getText(), 'order' => $step->getOrder(), 'shuffle' => $step->getShuffle(), 'nbQuestion' => $step->getNbQuestion(), 'keepSameQuestion' => $step->getKeepSameQuestion(), 'duration' => $step->getDuration(), 'maxAttempts' => $step->getMaxAttempts()]; $steps[] = $s; // TODO : do not load the Questions from DB they already are in `$step->getStepQuestions()` $questions = $questionRepo->findByStep($step); $this->qtiService->createQuestionsDirectory($questions, $step->getOrder()); $dirs = $this->qtiService->sortPathOfQuestions($this->qtiRepository, $step->getOrder()); $i = 'a'; foreach ($dirs as $dir) { $iterator = new \DirectoryIterator($dir); /** @var \DirectoryIterator $element */ foreach ($iterator as $element) { if (!$element->isDot() && $element->isFile()) { $localPath = 'qti/' . $exoTitle . '/' . $step->getOrder() . '/' . $step->getOrder() . '_question_' . $i . '/' . $element->getFilename(); $files[$localPath] = $element->getPathname(); } } $i .= 'a'; } } return $steps; }
/** * Returns a step list according to the *shuffle* and * nbStep* parameters of an exercise, i.e. filtered * and/or randomized if needed. * * @param Exercise $exercise * * @return array */ public function pickSteps(Exercise $exercise) { $steps = $exercise->getSteps()->toArray(); if ($exercise->getShuffle()) { shuffle($steps); } if (($stepToPick = $exercise->getPickSteps()) > 0) { $steps = $this->pickItem($stepToPick, $steps); } return $steps; }
private function getStepsToExport(Exercise $exercise, $title, $zip) { $em = $this->getDoctrine()->getManager(); $questionRepo = $em->getRepository('UJMExoBundle:Question'); $qtiSer = $this->container->get('ujm.exo_qti'); $qtiRepo = $this->container->get('ujm.exo_qti_repository'); foreach ($exercise->getSteps() as $step) { // TODO : do not load the Questions from DB they already are in `$step->getStepQuestions()` $questions = $questionRepo->findByStep($step); $qtiSer->createQuestionsDirectory($questions, $step->getOrder()); $dirs = $qtiSer->sortPathOfQuestions($qtiRepo, $step->getOrder()); $i = 'a'; foreach ($dirs as $dir) { $iterator = new \DirectoryIterator($dir); /** @var \DirectoryIterator $element */ foreach ($iterator as $element) { if (!$element->isDot() && $element->isFile()) { $partDirectory = $title . '/' . $step->getOrder() . '/' . $step->getOrder() . '_question_' . $i . '/' . $element->getFilename(); $zip->addFile($element->getPathname(), $partDirectory); } } $i .= 'a'; } } }