Пример #1
0
 /**
  * @param \_OurBrand_\Quiz\Domain\Model\Quiz $quiz
  */
 public function duplicateAction($quiz)
 {
     $newQuiz = $this->quizService->makeCopy($quiz);
     if ($newQuiz == null) {
         // TODO: User error handling.
     }
     $newQuiz->setCreator($this->currentUser->getIdentifier());
     $newQuiz->setIsDraft(true);
     $this->quizRepository->add($newQuiz);
     $this->persistenceManager->persistAll();
     $this->redirect('edit', null, null, array('quiz' => $newQuiz));
 }
Пример #2
0
 /**
  * @param string $authentication
  * @param string $quizIdentifier
  */
 public function quizDeleteAction($authentication, $quizIdentifier)
 {
     if (!$this->verifyAuthentication($authentication, (string) $quizIdentifier)) {
         throw new AccessDeniedException('Access denied');
     }
     $quiz = $this->quizRepository->findByIdentifier($quizIdentifier);
     if ($quiz) {
         $this->quizRepository->remove($quiz);
         $this->persistenceManager->persistAll();
     }
     $this->view->assign('value', array('ok'));
 }
 /**
  * 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);
 }
Пример #4
0
 /**
  * @param \_OurBrand_\Quiz\Domain\Model\Exercise $exercise
  * @return void
  */
 public function deleteAction($exercise)
 {
     if (!$this->accessHelper->canUserEditQuiz($this->currentUser, $exercise->getQuiz())) {
         $this->throwStatus(403);
     }
     $number = $exercise->getNumber();
     $quiz = $exercise->getQuiz();
     $prevExercise = null;
     $quiz->removeExercise($exercise);
     $quiz->touch();
     if ($quiz->getExercises()->count() > 0) {
         $prevExercise = $quiz->getExerciseByNumber($number > 0 ? $number - 1 : 0);
     }
     $this->quizRepository->update($quiz);
     $this->persistenceManager->persistAll();
     if ($prevExercise) {
         $this->redirect('edit', 'exercise', null, array('exercise' => $prevExercise));
     } else {
         $this->redirect('edit', 'quiz', null, array('quiz' => $quiz));
     }
 }
Пример #5
0
 public function setUpQuiz()
 {
     $quiz = new \_OurBrand_\Quiz\Domain\Model\Quiz();
     $quiz->setAuthor('Tester');
     $quiz->setIsDraft(false);
     $quiz->setIsDeleted(false);
     $quiz->setCreator('tester');
     $quiz->setType(0);
     $quiz->setTitle('Test Quiz');
     $subject = $this->filterOptions['subjects']['Math'];
     $quiz->addSubject($subject);
     $level1 = $this->filterOptions['teamLevels']['4'];
     $quiz->addLevel($level1);
     $level2 = $this->filterOptions['teamLevels']['5'];
     $quiz->addLevel($level2);
     $category = $this->filterOptions['categories']['Geometry'];
     $quiz->setCategory($category);
     $quiz->addExercise($this->exercises['1']);
     $this->quizRepository->add($quiz);
     $quiz = new \_OurBrand_\Quiz\Domain\Model\Quiz();
     $quiz->setAuthor('Tester');
     $quiz->setIsDraft(false);
     $quiz->setIsDeleted(false);
     $quiz->setCreator('tester');
     $quiz->setType(0);
     $quiz->setTitle('Test Quiz2');
     $subject = $this->filterOptions['subjects']['Math'];
     $quiz->addSubject($subject);
     $level1 = $this->filterOptions['teamLevels']['4'];
     $quiz->addLevel($level1);
     $level2 = $this->filterOptions['teamLevels']['5'];
     $quiz->addLevel($level2);
     $category = $this->filterOptions['categories']['Geometry'];
     $quiz->setCategory($category);
     $this->quizRepository->add($quiz);
     $this->persistenceManager->persistAll();
 }
Пример #6
0
 /**
  * Updates Quiz before updating Exercise. This function is needed when user saves Exercise for Portal
  * @param \_OurBrand_\Quiz\Domain\Model\Quiz $quiz
  * @param array $quizArguments
  */
 public function updateQuizBeforeUpdatingExercise($quiz, $quizArguments)
 {
     $quizArguments['subject'] = $this->subjectRepository->findByIdentifier($quizArguments['subject']);
     $quiz->setPropertiesForPortalQuizWhenEditsTheExercise($quizArguments);
     $this->quizRepository->update($quiz);
 }
 /**
  * @return void
  */
 public function indexAction()
 {
     $quizzes = $this->quizRepository->findAllNotSnapshot();
     $this->view->assign('quizzes', $quizzes);
 }
Пример #8
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;
 }