Ejemplo n.º 1
0
 /**
  * Displays the finish page.
  *
  * @param \_OurBrand_\Quiz\Domain\Model\Quiz $quiz
  */
 public function finishAction(\_OurBrand_\Quiz\Domain\Model\Quiz $quiz)
 {
     if (!$this->accessHelper->canUserEditQuiz($this->currentUser, $quiz)) {
         $this->throwStatus(403);
     }
     // Todo: Should never be necessary. Quiz that has not been finished should not have been assigned.
     $sessions = $this->studentQuizSessionRepository->findByQuiz($quiz);
     if ($sessions->count() > 0) {
         throw new \Exception('Can not edit quiz that has been assigned');
     }
     // Get data for view.
     $contentCategoryOptions = $this->contentCategoryRepository->findAll();
     $gradeOptions = $this->gradeRepository->findAll();
     $quizGrades = $this->quizGradeRepository->findByQuiz($quiz);
     $subjects = $quiz->getSubjects();
     $quizCategoryOptions = $this->getQuizCategoryOptions($subjects, $quiz->getType());
     $quizTypeOptions = $this->quizTypeRepository->findBySubjectsAndProduct($subjects, $quiz->getType());
     $tagOptions = $this->tagRepository->findAll();
     // Handle quiz grades
     if ($quiz->getMaxScore() < count($gradeOptions)) {
         foreach ($quizGrades as $quizGrade) {
             $this->quizGradeRepository->remove($quizGrade);
         }
         $this->persistenceManager->persistAll();
     } elseif (!$quizGrades->count()) {
         $this->preFillGrades($quiz, $gradeOptions);
         $quizGrades = $this->quizGradeRepository->findByQuiz($quiz);
     }
     // Are we handling a special subject
     $hasLanguageSubject = 0;
     foreach ($quiz->getSubjects() as $subject) {
         if ($subject->getIsLanguage()) {
             $hasLanguageSubject = 1;
             break;
         }
     }
     // Handle duration
     $duration = $quiz->getDuration();
     $minAndSeconds = gmdate("H:i", $duration);
     $parts = explode(':', $minAndSeconds);
     $minutes = $parts[1];
     $hours = $parts[0];
     $subjectIsEmpty = $subjects->isEmpty() ? 1 : 0;
     $this->view->assign('subjectIsEmpty', $subjectIsEmpty);
     $this->view->assign('isFinishingQuiz', 1);
     $this->view->assign('hasLanguageSubject', $hasLanguageSubject);
     $this->view->assign('minutes', $minutes);
     $this->view->assign('hours', $hours);
     $this->view->assign('defaultDuration', $this->defaultDuration / 60);
     $this->view->assign('quiz', $quiz);
     $this->view->assign('quizGrades', $quizGrades);
     $this->view->assign('quizTypeOptions', $quizTypeOptions);
     $this->view->assign('quizCategoryOptions', $quizCategoryOptions);
     $this->view->assign('contentCategoryOptions', $contentCategoryOptions);
     $this->view->assign('gradeOptions', $gradeOptions);
     $this->view->assign('tagOptions', $tagOptions);
 }
 /**
  * Generate a new ContentCategory
  *
  * This command inserts a new ContentCategory record into the database. Mostly used for development while management
  * tools for content categories are not yet available
  *
  * @param string $translationId The TranslationId of the content category to generate
  * @return void
  */
 public function contentCategoryCommand($translationId)
 {
     $contentCategory = new ContentCategory($translationId);
     $this->contentCategoryRepository->add($contentCategory);
     $this->outputLine('ContentCategory with title "%s" added to the database.', array($translationId));
 }