/**
  * Create and add a new Step to an Exercise.
  *
  * @param Exercise $exercise
  *
  * @return Step
  */
 public function addStep(Exercise $exercise)
 {
     $step = new Step();
     $step->setOrder($exercise->getSteps()->count() + 1);
     // Link the Step to the Exercise
     $exercise->addStep($step);
     $this->om->persist($step);
     $this->om->flush();
     return $step;
 }
示例#2
0
 /**
  * create the exercise.
  *
  * @param array    $step     - properties of the step
  * @param Exercise $exercise
  *
  * @return Step
  */
 private function createStep(array $step, Exercise $exercise)
 {
     $newStep = new Step();
     $newStep->setText($step['text']);
     $newStep->setOrder($step['order']);
     $newStep->setShuffle($step['shuffle']);
     $newStep->setNbQuestion($step['nbQuestion']);
     $newStep->setKeepSameQuestion($step['keepSameQuestion']);
     $newStep->setDuration($step['duration']);
     $newStep->setMaxAttempts($step['maxAttempts']);
     $newStep->setExercise($exercise);
     $this->om->persist($newStep);
     $this->om->flush();
     return $newStep;
 }
示例#3
0
 /**
  * @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;
 }
 /**
  * @param Exercise $exercise
  * @param int      $orderStep
  *
  * @return Step
  */
 public function createStep(Exercise $exercise, $orderStep)
 {
     $em = $this->doctrine->getManager();
     //Creating a step by question
     $step = new Step();
     $step->setText(' ');
     $step->setExercise($exercise);
     $step->setNbQuestion(0);
     $step->setDuration(0);
     $step->setMaxAttempts(0);
     $step->setOrder($orderStep);
     $em->persist($step);
     return $step;
 }
示例#5
0
 /**
  * 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;
 }