/**
  * Init tracker if in exam mode
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  *
  * @return json
  */
 public function getDictationAudioAction($exercise)
 {
     $audioFiles = array();
     foreach ($exercise->getSnippets() as $snippet) {
         if ($snippet->getAudio() && $snippet->getAudio()->getOriginalResource()) {
             $audioFiles[] = array('src' => base64_encode($this->resourcePublisher->getPersistentResourceWebUri($snippet->getAudio()->getOriginalResource())));
         }
     }
     if ($this->studentQuizSession) {
         $tracker = $this->trackStudentAudioPlaybackRepository->findBySessionAndExercise($this->studentQuizSession, $exercise)->getFirst();
         if (!is_a($tracker, '\\_OurBrand_\\Quiz\\Domain\\Model\\TrackStudentAudioPlayback')) {
             $tracker = new TrackStudentAudioPlayback();
             $tracker->setExercise($exercise);
             $tracker->setStudentQuizSession($this->studentQuizSession);
             $tracker->setTimeElapsed(0);
             $tracker->setStatus(0);
             $this->trackStudentAudioPlaybackRepository->add($tracker);
             $this->persistenceManager->persistAll();
         }
         return json_encode(array('elapsedTime' => $tracker->getTimeElapsed(), 'status' => $tracker->getStatus(), 'trackerId' => $this->persistenceManager->getIdentifierByObject($tracker), 'audioFiles' => $audioFiles));
     }
     return json_encode(array('status' => 0, 'audioFiles' => $audioFiles));
 }
Example #2
0
 /**
  * @param $numberOfExercises
  *
  * @return Quiz
  */
 private function makeQuizWithExercises($numberOfExercises)
 {
     $quiz = new Quiz();
     for ($i = 0; $i < $numberOfExercises; $i++) {
         $exercise = new Exercise();
         $exercise->setTitle('Exercise: ' . $i);
         $quiz->addExercise($exercise);
     }
     return $quiz;
 }
 /**
  * Main preview by creator of exercise.
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  */
 private function previewAssignment($exercise)
 {
     $possibleAnswers = null;
     $question = $exercise->getQuestions()->first();
     if (is_a($question, '\\_OurBrand_\\Quiz\\Domain\\Model\\Exercises\\MultipleChoiceQuestion')) {
         $possibleAnswers = $question->getPossibleAnswers();
     }
     // Select the explanation translation text
     $this->view->assign('explanationTranslateKey', 'exercise.multipleChoice.sameAnswer.explanation.selectOne');
     $this->view->assign('currentExercise', $exercise);
     $this->view->assign('possibleAnswers', $possibleAnswers);
     $this->view->assign('quiz', $exercise->getQuiz());
 }
 /**
  * Register answer.
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @return void
  */
 public function registerAnswerAction($exercise)
 {
     $answers = $this->request->hasArgument('question') ? $this->request->getArgument('question') : array();
     $score = $exercise->calculateScoreForAnswers($answers);
     $status = $exercise->isCompleted($answers);
     $orderedAnswers = $this->request->hasArgument('answers') ? $this->request->getArgument('answers') : array();
     $identifier = $this->persistenceManager->getIdentifierByObject($exercise);
     $this->loginSession->setData('answers-' . $identifier, array_unique($orderedAnswers));
     // Save the score, for the given answers, on this exercise, during this quiz.
     $this->exerciseService->registerAnswer($score, $status, $answers, $exercise, $this->studentQuizSession);
     $this->studentQuizSessionService->updateProgress($this->studentQuizSession);
     $this->view->assign('value', array('timeRemaining' => $this->studentQuizSession->getTimeRemaining()));
     if (!$this->isJson) {
         $this->redirect('studentnavigate', 'quiz', $this->request->hasArgument('goto') ? $this->request->getArgument('goto') : 'next');
     }
 }
 /**
  * Implementation of clone magic method.
  */
 public function postClone()
 {
     // Clone common parent objects.
     parent::postClone();
     $tempQuestions = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($this->questions as $question) {
         $newQuestion = clone $question;
         $newQuestion->setExercise($this);
         $tempQuestions->add($newQuestion);
     }
     $this->questions = $tempQuestions;
 }
 /**
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @return array
  */
 protected function getExerciseCategories(\_OurBrand_\Quiz\Domain\Model\Exercise $exercise)
 {
     $out = array();
     $quiz = $exercise->getQuiz();
     if (is_a($quiz, '\\_OurBrand_\\Quiz\\Domain\\Model\\Quiz')) {
         $subjects = $this->resolveSubjectObjectsIntoArrayByQuiz($quiz);
         if (is_array($subjects) && count($subjects) > 0) {
             foreach ($subjects as $subject) {
                 if (is_array($subject['categories']) && count($subject['categories']) > 0) {
                     foreach ($subject['categories'] as $category) {
                         $out[] = array('label' => $category['title'] . ' (' . $subject['title'] . ')', 'children' => $category['skills']);
                     }
                 }
             }
         }
     }
     return $out;
 }
 /**
  * Review answers.
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @param \_OurBrand_\Quiz\Domain\Model\StudentQuizSession $studentQuizSession
  */
 public function reviewAction($exercise, $studentQuizSession)
 {
     $randomShapes = $exercise->getRandomShapes();
     $utility = new Utility();
     // Create array with correctAnswers in same format as $answerData.
     $correctAnswers = array();
     foreach ($randomShapes as $shape) {
         $correctAnswers[$utility->getSaltedString($this->persistenceManager->getIdentifierByObject($shape))] = $this->persistenceManager->getIdentifierByObject($shape);
     }
     // get previous saved answers
     $answers = $this->answerRepository->findBySessionAndExercise($studentQuizSession, $exercise)->getFirst();
     $answerData = array();
     if (is_a($answers, '\\_OurBrand_\\Quiz\\Domain\\Model\\Answer')) {
         $answerData = unserialize($answers->getAnswerDatas()->first()->getData());
         $userAnswersStatus = array('correct' => array(), 'false' => array());
         // save the correct answer here as well
         foreach ($answerData as $saltedUuid => $uuid) {
             if (isset($correctAnswers[$saltedUuid]) && $correctAnswers[$saltedUuid] === $uuid) {
                 $userAnswersStatus['correct'][] = $uuid;
             } else {
                 $userAnswersStatus['false'][] = $uuid;
             }
         }
     }
     $this->view->assign('shapes', $randomShapes);
     $this->view->assign('userAnswers', json_encode($answerData));
     $this->view->assign('userAnswersStatus', json_encode($userAnswersStatus));
     $this->view->assign('correctAnswers', json_encode($correctAnswers));
     $this->view->assign('explanationTranslateKey', 'exerciseType.matchPictureInPicture.explanation');
     $this->view->assign('currentExercise', $exercise);
     $this->view->assign('quiz', $exercise->getQuiz());
     $this->view->assign('session', $studentQuizSession);
 }
Example #8
0
 /**
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @return void
  */
 public function addExercise($exercise)
 {
     // Ensure integrity.
     $exercise->setQuiz($this);
     $exercise->setNumber($this->getExercises()->count());
     $this->exercises->add($exercise);
 }
 /**
  * Preview the exercise as Instructor
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @return void
  */
 private function previewAssignment($exercise)
 {
     $mode = 'withComma';
     $answerData = $exercise->getAnswers();
     $this->view->assign('explanationTranslateKey', 'exercise.SpellingAndGrammar.Comma.explanation');
     $this->view->assign('currentExercise', $exercise);
     $this->view->assign('quiz', $exercise->getQuiz());
     $this->view->assign('session', $this->studentQuizSession);
     $this->view->assign('mode', $mode);
     $this->view->assign('answers', $answerData);
 }
 /**
  * @inheritdoc
  */
 public function postClone()
 {
     parent::postClone();
     // Copy shapes
     $newShapes = new ArrayCollection();
     foreach ($this->getShapes() as $shape) {
         $newShape = clone $shape;
         $newShape->setExercise($this);
         $newShapes->add($newShape);
     }
     $this->shapes = $newShapes;
     // copy the mainImage
     $tempMainImageCollection = new ArrayCollection();
     foreach ($this->getMainImageCollection() as $mainImageCollection) {
         $newMainImageCollection = clone $mainImageCollection;
         $newMainImageCollection->setExercise($this);
         $tempMainImageCollection->add($newMainImageCollection);
     }
     $this->mainImageCollection = $tempMainImageCollection;
 }
 /**
  * @inheritdoc
  */
 public function postClone()
 {
     parent::postClone();
     $phrases = new \Doctrine\Common\Collections\ArrayCollection();
     foreach ($this->phrases as $phrase) {
         $newPhrase = clone $phrase;
         $newPhrase->setExercise($this);
         $phrases->add($newPhrase);
     }
     $this->phrases = $phrases;
 }
Example #12
0
 /**
  * @test
  */
 public function testGetters()
 {
     $exerciseCategory = new ExerciseCategory('TestCategory', 1);
     $exerciseType = new ExerciseType($exerciseCategory, 'TestExerciseTypeKey', 'TestExerciseTypeDesc', 'TestExerciseTypeObject');
     $quiz = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\Quiz');
     $image = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\ImageResource');
     $pdfFile = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\FileResource');
     $soundFile = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\FileResource');
     $textContent = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\TextContent');
     $mediaContents = array('picture' => false, 'pdf' => false, 'audio' => false, 'text' => false);
     $answer = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\Answer');
     $skill = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\ExerciseSkill');
     $hint = 'This is a hint test';
     $explanation = 'This is an explanation hint';
     $minutes = 15;
     $seconds = 30;
     $difficulty = $this->getMock('\\_OurBrand_\\Quiz\\Domain\\Model\\Difficulty');
     $exercise = new Exercise();
     $exercise->setQuiz($quiz);
     $exercise->setTitle('Title');
     $exercise->setDescription('Description');
     $exercise->setType($exerciseType);
     $exercise->setDuration(300);
     $exercise->setMaxScore(5);
     $exercise->setImage($image);
     $exercise->setPdfFile($pdfFile);
     $exercise->setSoundFile($soundFile);
     $exercise->setTextContent($textContent);
     foreach ($mediaContents as $key => $value) {
         $exercise->setMediaContent($key, $value);
     }
     $exercise->setAnswer($answer);
     $exercise->setExerciseSkill($skill);
     $exercise->setIsDraft(true);
     $exercise->setHint($hint);
     $exercise->setExplanation($explanation);
     $exercise->setMinutes($minutes);
     $exercise->setSeconds($seconds);
     $exercise->setDifficulty($difficulty);
     $this->assertEquals($quiz, $exercise->getQuiz());
     $this->assertEquals('Title', $exercise->getTitle());
     $this->assertEquals('Description', $exercise->getDescription());
     $this->assertEquals($exerciseType, $exercise->getType());
     $this->assertEquals(300, $exercise->getDuration());
     $this->assertEquals(5, $exercise->getMaxScore());
     $this->assertEquals($image, $exercise->getImage());
     $this->assertEquals($pdfFile, $exercise->getPdfFile());
     $this->assertEquals($soundFile, $exercise->getSoundFile());
     $this->assertEquals($textContent, $exercise->getTextContent());
     $this->assertEquals($mediaContents, $exercise->getMediaContents());
     $this->assertEquals($answer, $exercise->getAnswer());
     $this->assertEquals($skill, $exercise->getExerciseSkill());
     $this->assertEquals(true, $exercise->getIsDraft());
     $this->assertEquals($hint, $exercise->getHint());
     $this->assertEquals($explanation, $exercise->getExplanation());
     $this->assertEquals($minutes, $exercise->getMinutes());
     $this->assertEquals($seconds, $exercise->getSeconds());
     $this->assertEquals($difficulty, $exercise->getDifficulty());
 }
 /**
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @param \_OurBrand_\Quiz\Domain\Model\StudentQuizSession $studentQuizSession
  * @throws ForwardException
  * @throws AccessDeniedException
  */
 public function reviewAction($exercise, $studentQuizSession)
 {
     if ($studentQuizSession->getQuizSession()->getQuiz() != $exercise->getQuiz()) {
         $this->throwStatus(403);
     }
     // TODO: Access. Can only be viewed by student or responsible instructor.
     $useController = $this->getControllerNameForExercise($exercise);
     if ($useController !== false) {
         $this->forward('review', $useController, null, array('exercise' => $exercise, 'studentQuizSession' => $studentQuizSession));
     } else {
         throw new ForwardException('Can not forward to correct controller for object of type ' . get_class($exercise));
     }
 }