/** * Call parent initialize, and abort if user is not administrator. */ protected function initializeAction() { parent::initializeAction(); if (!$this->currentUser->isAdministrator()) { $this->throwStatus(403); } }
/** * @param \_OurBrand_\My\Domain\Model\User $user * @param int $quizType * * @return bool */ public function canUserCreateQuiz(\_OurBrand_\My\Domain\Model\User $user, $quizType) { if ($user->isWorker() || $user->isAdministrator()) { return true; } return $user->isInstructor() && $this->userHasSubscriptionToQuizType($user, $quizType); }
/** * Initializes the view with common variables. * * @param \TYPO3\Flow\Mvc\View\ViewInterface $view * @return void */ protected function initializeView(\TYPO3\Flow\Mvc\View\ViewInterface $view) { // We don't need to do all this for json responses. if ($this->request->hasArgument('json')) { return; } // Are user an Editor? $isEditor = 0; if ($this->securityContext->hasRole('_OurBrand_.Business:worker')) { $isEditor = 1; } // Are user an Admin? $isAdmin = 0; if ($this->currentUser->isAdministrator()) { $isAdmin = 1; } $inDev = 0; if (strstr($_SERVER['HTTP_HOST'], '.local')) { $inDev = 1; } // Get file stamp $fileStamp = time(); if ($this->environment->getContext() == 'Production' && file_exists(FLOW_PATH_ROOT . 'Data/Temporary/Production/Configuration/ProductionConfigurations.php')) { $fileStamp = @filemtime(FLOW_PATH_ROOT . 'Data/Temporary/Production/Configuration/ProductionConfigurations.php'); } // Exercise categories $exerciseCategoryRepository = new \_OurBrand_\Quiz\Domain\Repository\ExerciseCategoryRepository(); $exerciseCategories = $exerciseCategoryRepository->findAll(); $subjectRepository = new \_OurBrand_\Quiz\Domain\Repository\SubjectRepository(); $this->view->assign('archiveUri', $this->getArchiveUri()); $this->view->assign('UIPath', $this->settings['UIPath']); $this->view->assign('isEditor', $isEditor); $this->view->assign('isAdmin', $isAdmin); $this->view->assign('inDev', $inDev); $this->view->assign('logintime', $fileStamp); // When was system updated? $this->view->assign('exerciseCategories', $exerciseCategories); $this->view->assign('user', $this->currentUser); if ($this->request->hasArgument('exercise') || $this->request->hasArgument('currentExercise')) { $exercise = $this->getExerciseFromArgument(); if (is_a($exercise, '\\_OurBrand_\\Quiz\\Domain\\Model\\Exercise')) { // Set type $objectName = explode('\\', get_class($exercise)); $exerciseType = $this->exerciseTypeRepository->findOneByObjectName(array_pop($objectName)); $exercise->setType($exerciseType); $durations = $this->getDurationsForExercise($this->settings['exercise']['durations']); $this->view->assign('editExerciseDurations', $durations); $this->view->assign('editExerciseCategories', $this->getExerciseCategories($exercise)); $this->view->assign('editExerciseDifficulties', $this->getDifficultiesForExercise()); $this->view->assign('previewExerciseDuration', $this->getExerciseDurationLabel($exercise)); $this->view->assign('previewExerciseSkill', $this->getExerciseSkillLabel($exercise)); $this->view->assign('previewExerciseDifficulty', $this->getExerciseDifficultyLabel($exercise)); $this->view->assign('previewExerciseIsHintSet', $exercise->getHint() != '' ? 1 : 0); $this->view->assign('previewExerciseIsExplanationSet', $exercise->getExplanation() != '' ? 1 : 0); $this->view->assign('subjectOptions', $subjectRepository->findAll()); $this->view->assign('subjectPlaceholder', $this->translateById('quiz.placeholder.subject')); } $quiz = $exercise->getQuiz(); } else { if ($this->request->hasArgument('quiz')) { $quiz = $this->getQuizFromArgument(); } } // Get/Set duration. $duration = 0; if (isset($quiz) && is_a($quiz, '\\_OurBrand_\\Quiz\\Domain\\Model\\Quiz')) { $duration = $quiz->getDuration(); } $this->view->assign('duration', gmdate("H:i", $duration)); }