Example #1
0
 /**
  * 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;
 }
 /**
  * Export metadata of the Exercise in a JSON-encodable format.
  *
  * @param Exercise $exercise
  *
  * @return array
  */
 private function exportMetadata(Exercise $exercise)
 {
     $node = $exercise->getResourceNode();
     $creator = $node->getCreator();
     $authorName = sprintf('%s %s', $creator->getFirstName(), $creator->getLastName());
     // Accessibility dates
     $startDate = $node->getAccessibleFrom() ? $node->getAccessibleFrom()->format('Y-m-d\\TH:i:s') : null;
     $endDate = $node->getAccessibleUntil() ? $node->getAccessibleUntil()->format('Y-m-d\\TH:i:s') : null;
     $correctionDate = $exercise->getDateCorrection() ? $exercise->getDateCorrection()->format('Y-m-d\\TH:i:s') : null;
     return ['authors' => [['name' => $authorName]], 'created' => $node->getCreationDate()->format('Y-m-d\\TH:i:s'), 'title' => $node->getName(), 'description' => $exercise->getDescription(), 'type' => $exercise->getType(), 'pick' => $exercise->getPickSteps(), 'random' => $exercise->getShuffle(), 'keepSteps' => $exercise->getKeepSteps(), 'maxAttempts' => $exercise->getMaxAttempts(), 'lockAttempt' => $exercise->getLockAttempt(), 'dispButtonInterrupt' => $exercise->getDispButtonInterrupt(), 'metadataVisible' => $exercise->isMetadataVisible(), 'statistics' => $exercise->hasStatistics(), 'anonymous' => $exercise->getAnonymous(), 'duration' => $exercise->getDuration(), 'markMode' => $exercise->getMarkMode(), 'correctionMode' => $exercise->getCorrectionMode(), 'correctionDate' => $correctionDate, 'startDate' => $startDate, 'endDate' => $endDate, 'published' => $node->isPublished(), 'publishedOnce' => $exercise->wasPublishedOnce(), 'minimalCorrection' => $exercise->isMinimalCorrection()];
 }
 /**
  * To create new paper
  *
  * @access private
  *
  * @param integer $id id of exercise
  * @param \UJM\ExoBundle\Entity\Exercise $exercise
  *
  * @return array
  */
 private function prepareInteractionsPaper($id, $exercise)
 {
     $em = $this->getDoctrine()->getManager();
     $orderInter = '';
     $tabOrderInter = array();
     $tab = array();
     $interactions = $this->getDoctrine()->getManager()->getRepository('UJMExoBundle:Interaction')->getExerciseInteraction($this->getDoctrine()->getManager(), $id, $exercise->getShuffle(), $exercise->getNbQuestion());
     foreach ($interactions as $interaction) {
         $orderInter = $orderInter . $interaction->getId() . ';';
         $tabOrderInter[] = $interaction->getId();
     }
     $tab['interactions'] = $interactions;
     $tab['orderInter'] = $orderInter;
     $tab['tabOrderInter'] = $tabOrderInter;
     return $tab;
 }