/** * @param string $title * @param Question[] $questions * @param User $user * * @return Exercise */ public function exercise($title, array $questions = [], User $user = null) { $exercise = new Exercise(); if ($user) { if (!isset($this->exoType)) { $this->exoType = new ResourceType(); $this->exoType->setName('exercise'); $this->om->persist($this->exoType); } $node = new ResourceNode(); $node->setName($title); $node->setCreator($user); $node->setResourceType($this->exoType); $node->setWorkspace($user->getPersonalWorkspace()); $node->setClass('UJM\\ExoBundle\\Entity\\Exercise'); $node->setGuid(time()); $exercise->setResourceNode($node); $this->om->persist($node); } $this->om->persist($exercise); for ($i = 0, $max = count($questions); $i < $max; ++$i) { $step = new Step(); $step->setText('step'); $step->setOrder($i); // Add step to the exercise $exercise->addStep($step); $this->om->persist($step); $stepQuestion = new StepQuestion(); $stepQuestion->setStep($step); $stepQuestion->setQuestion($questions[$i]); $stepQuestion->setOrdre(0); $this->om->persist($stepQuestion); } return $exercise; }
/** * Temporary : Waiting step manager. * * Create a step for one question in the exercise * * @param Exercise $exercise * @param Question $question * @param int $orderStep order of the step in the exercise */ public function createStepForOneQuestion(Exercise $exercise, Question $question, $orderStep) { $em = $this->doctrine->getManager(); $step = $this->createStep($exercise, $orderStep); $sq = new StepQuestion(); $sq->setStep($step); $sq->setQuestion($question); $sq->setOrdre(1); $em->persist($sq); $em->flush(); }
/** * Create a copy of a Step. * * @param Step $step * * @return Step the copy of the Step */ public function copyStep(Step $step) { $newStep = new Step(); // Populate Step properties $newStep->setOrder($step->getOrder()); $newStep->setText($step->getText()); $newStep->setNbQuestion($step->getNbQuestion()); $newStep->setShuffle($step->getShuffle()); $newStep->setDuration($step->getDuration()); $newStep->setMaxAttempts($step->getMaxAttempts()); $newStep->setKeepSameQuestion($step->getKeepSameQuestion()); // Link questions to Step /** @var StepQuestion $stepQuestion */ foreach ($step->getStepQuestions() as $stepQuestion) { $newStepQuestion = new StepQuestion(); $newStepQuestion->setStep($newStep); $newStepQuestion->setQuestion($stepQuestion->getQuestion()); $newStepQuestion->setOrdre($stepQuestion->getOrdre()); } return $newStep; }