/**
  * Generate testData
  *
  * This command inserts all the required data to start testing the student view of the Dictation exercise
  *
  * @return void
  */
 public function generateInsertCommand()
 {
     $quiz = new Quiz();
     $quiz->setTitle('Dictation Insert');
     $quiz->setAuthor('Test Instructor');
     $quiz->setCreator('instructor');
     $quiz->setIsDraft(false);
     $quiz->setType(0);
     $exercise = new InsertDictationExercise();
     $exercise->setTitle('Spelling and Grammer: Insert Dictation');
     $exercise->setDescription('Description');
     $snippet = new DictationSnippet();
     $snippet->setText('<span class="textShow">This is a very</span> <span class="textmark">marvellous</span> horse');
     $markedText = new MarkedText();
     $markedText->setText('marvellous');
     $snippet->addMarkedText($markedText);
     $exercise->addSnippet($snippet);
     $snippet = new DictationSnippet();
     $snippet->setText('<span class="textShow">This is another</span> <span class="textmark">sentence</span> horse');
     $markedText = new MarkedText();
     $markedText->setText('sentence');
     $snippet->addMarkedText($markedText);
     $exercise->addSnippet($snippet);
     $snippet = new DictationSnippet();
     $snippet->setText('<span class="textmark">Newest</span> <span class="textShow">more</span><span class="textmark">text</span>');
     $markedText = new MarkedText();
     $markedText->setText('Newest');
     $snippet->addMarkedText($markedText);
     $markedText = new MarkedText();
     $markedText->setText('text');
     $snippet->addMarkedText($markedText);
     $exercise->addSnippet($snippet);
     $quiz->addExercise($exercise);
     $this->quizRepository->add($quiz);
     //Create QuizSession
     $quizSession = new QuizSession();
     $quizSession->setQuiz($quiz);
     $quizSession->setInstructor('instructor');
     $quizSession->setStudentCanSeeSummaryAndReviewExercises(1);
     $quizSession->setShowGradeOnSummary(1);
     $this->quizSessionRepository->add($quizSession);
     //Create studentQuizSession
     $studentQuizSession = new StudentQuizSession();
     $studentQuizSession->setQuizSession($quizSession);
     $studentQuizSession->setStudent('student');
     $this->studentQuizSessionRepository->add($studentQuizSession);
 }
Пример #2
0
 /**
  * Creates a quiz session and student quiz session objects for each
  * student.
  *
  * @param \_OurBrand_\Quiz\Domain\Model\QuizAssignment $quizAssignment
  * @param $quizSession
  *
  * @return \_OurBrand_\Quiz\Domain\Model\QuizSession $quizSession
  *
  * @throws \InvalidArgumentException
  * @throws \RuntimeException
  *
  * @api
  */
 public function assignQuizToStudents($quizAssignment, $quizSession = "")
 {
     $newQuizSessionFlag = empty($quizSession) ? true : false;
     // Step 1: Validate parameters.
     if ($quizAssignment->getQuiz() == null || $quizAssignment->getStudentAssignments()->count() < 1 || $quizAssignment->getInstructorIdentifier() == '') {
         throw new \InvalidArgumentException('Error in QuizAssignment properties.', 1384944001);
     }
     // If quiz is a snapshot, find the original and use that instead. Will make the next operations more consistent
     if ($quizAssignment->getQuiz()->getSnapshotOf() instanceof \_OurBrand_\Quiz\Domain\Model\Quiz) {
         $quizAssignment->setQuiz($quizAssignment->getQuiz()->getSnapshotOf());
     }
     // Step 2: Find out which snapshot of quiz we can use.
     $snapshot = $this->quizRepository->findLatestValidSnapshot($quizAssignment->getQuiz());
     if (!$snapshot instanceof \_OurBrand_\Quiz\Domain\Model\Quiz) {
         $snapshot = $this->makeSnapshotAndPersist($quizAssignment->getQuiz());
     }
     if (!$snapshot instanceof \_OurBrand_\Quiz\Domain\Model\Quiz) {
         throw new \RuntimeException('Snapshot not found and could not be made for Quiz!', 1396342271);
     }
     if ($newQuizSessionFlag) {
         // insert new record into QuizSession model
         $quiz = is_null($quizSession) ? $quizAssignment->getQuiz() : $snapshot;
         $quizSession = new \_OurBrand_\Quiz\Domain\Model\QuizSession();
         $quizSession->setQuiz($quiz);
         $quizSession->setInstructor($quizAssignment->getInstructorIdentifier());
         $quizSession->setContext($quizAssignment->getContext());
         $quizSession->setTeamIdentifier($quizAssignment->getTeamIdentifier());
         $quizSession->setShowGradeOnSummary($quizAssignment->getShowGradeOnSummary());
         $quizSession->setShowTimer($quizAssignment->getShowTimer());
         $quizSession->setIsDemo($quizAssignment->getIsDemo());
         if ($quizAssignment->getIsDemo()) {
             // Set the start time at once, so we know when it is removed by garbage collector
             $quizSession->setStartTime(new \TYPO3\Flow\Utility\Now());
         }
     } else {
         // iupdate existent record in QuizSession model
         if (!is_a($quizSession, '\\_OurBrand_\\Quiz\\Domain\\Model\\QuizSession')) {
             $quizSession = $this->persistenceManager->getIdentifierByObject($quizSession);
         }
         $quizSession->setContext($quizAssignment->getContext());
         $quizSession->setShowGradeOnSummary($quizAssignment->getShowGradeOnSummary());
         $quizSession->setShowTimer($quizAssignment->getShowTimer());
         // remove all studentAssignments (StundetQuizSessions) to insert updated ones
         $quizSessionId = $this->persistenceManager->getIdentifierByObject($quizSession);
         $this->studentQuizSessionRepository->removeAllByQuizSession($quizSessionId);
     }
     if ($quizAssignment->getAssignmentType() == \_OurBrand_\Quiz\Domain\Model\QuizAssignment::ASSIGNMENT_AT_HOME) {
         $this->startQuizSession($quizSession);
     }
     foreach ($quizAssignment->getStudentAssignments() as $studentAssignment) {
         // insert new records about assignments for each student
         $studentQuizSession = new \_OurBrand_\Quiz\Domain\Model\StudentQuizSession();
         $studentQuizSession->setQuizSession($quizSession);
         $studentQuizSession->setStudent($studentAssignment->getStudentIdentifier());
         $studentQuizSession->setExtratime($studentAssignment->getExtraTime());
         $quizSession->addStudentQuizSession($studentQuizSession);
     }
     if ($newQuizSessionFlag) {
         $this->quizSessionRepository->add($quizSession);
     } else {
         $this->quizSessionRepository->update($quizSession);
     }
     $this->persistenceManager->persistAll();
     return $quizSession;
 }