private function addEditQuiz() { $quizId = isset($_GET['quizId']) ? (int) $_GET['quizId'] : 0; if ($quizId) { if (!current_user_can('wpProQuiz_edit_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } } else { if (!current_user_can('wpProQuiz_add_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } } $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $cateoryMapper = new WpProQuiz_Model_CategoryMapper(); $quiz = new WpProQuiz_Model_Quiz(); $forms = null; $prerequisiteQuizList = array(); if ($quizId && $quizMapper->exists($quizId) == 0) { WpProQuiz_View_View::admin_notices(__('Quiz not found', 'wp-pro-quiz'), 'error'); return; } if (isset($this->_post['template']) || isset($this->_post['templateLoad']) && isset($this->_post['templateLoadId'])) { if (isset($this->_post['template'])) { $template = $this->saveTemplate(); } else { $template = $templateMapper->fetchById($this->_post['templateLoadId']); } $data = $template->getData(); if ($data !== null) { /** @var WpProQuiz_Model_Quiz $quiz */ $quiz = $data['quiz']; $quiz->setId($quizId); $forms = $data['forms']; $prerequisiteQuizList = $data['prerequisiteQuizList']; } } else { if (isset($this->_post['submit'])) { if (isset($this->_post['resultGradeEnabled'])) { $this->_post['result_text'] = $this->filterResultTextGrade($this->_post); } $this->_post['categoryId'] = $this->_post['category'] > 0 ? $this->_post['category'] : 0; $this->_post['adminEmail'] = new WpProQuiz_Model_Email($this->_post['adminEmail']); $this->_post['userEmail'] = new WpProQuiz_Model_Email($this->_post['userEmail']); $quiz = new WpProQuiz_Model_Quiz($this->_post); $quiz->setId($quizId); if (isset($this->_post['plugin'])) { $quiz->getPluginContainer()->set($this->_post['plugin']); } if ($this->checkValidit($this->_post)) { if ($quizId) { WpProQuiz_View_View::admin_notices(__('Quiz edited', 'wp-pro-quiz'), 'info'); } else { WpProQuiz_View_View::admin_notices(__('quiz created', 'wp-pro-quiz'), 'info'); } $quizMapper->save($quiz); $quizId = $quiz->getId(); $prerequisiteMapper->delete($quizId); if ($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList'])) { $prerequisiteMapper->save($quizId, $this->_post['prerequisiteList']); $quizMapper->activateStatitic($this->_post['prerequisiteList'], 1440); } if (!$this->formHandler($quiz->getId(), $this->_post)) { $quiz->setFormActivated(false); $quizMapper->save($quiz); } $forms = $formMapper->fetch($quizId); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($quizId); } else { WpProQuiz_View_View::admin_notices(__('Quiz title or quiz description are not filled', 'wp-pro-quiz')); } } else { if ($quizId) { $quiz = $quizMapper->fetch($quizId); $forms = $formMapper->fetch($quizId); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($quizId); } } } $view = new WpProQuiz_View_QuizEdit(); $view->quiz = $quiz; $view->forms = $forms; $view->prerequisiteQuizList = $prerequisiteQuizList; $view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $view->quizList = $quizMapper->fetchAllAsArray(array('id', 'name'), $quizId ? array($quizId) : array()); $view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); $view->categories = $cateoryMapper->fetchAll(WpProQuiz_Model_Category::CATEGORY_TYPE_QUIZ); $view->header = $quizId ? __('Edit quiz', 'wp-pro-quiz') : __('Create quiz', 'wp-pro-quiz'); $view->show(); }
private function editAction($id) { if (!current_user_can('wpProQuiz_edit_quiz')) { wp_die(__('You do not have sufficient permissions to access this page.')); } $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $templateMapper = new WpProQuiz_Model_TemplateMapper(); $m = new WpProQuiz_Model_QuizMapper(); $this->view = new WpProQuiz_View_QuizEdit(); $this->view->header = __('Edit quiz', 'wp-pro-quiz'); $forms = $formMapper->fetch($id); $prerequisiteQuizList = $prerequisiteMapper->fetchQuizIds($id); if ($m->exists($id) == 0) { WpProQuiz_View_View::admin_notices(__('Quiz not found', 'wp-pro-quiz'), 'error'); return; } if (isset($this->_post['submit'])) { if (isset($this->_post['resultGradeEnabled'])) { $this->_post['result_text'] = $this->filterResultTextGrade($this->_post); } $quiz = new WpProQuiz_Model_Quiz($this->_post); $quiz->setId($id); if ($this->checkValidit($this->_post)) { WpProQuiz_View_View::admin_notices(__('Quiz edited', 'wp-pro-quiz'), 'info'); $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper(); $prerequisiteMapper->delete($id); if ($quiz->isPrerequisite() && !empty($this->_post['prerequisiteList'])) { $prerequisiteMapper->save($id, $this->_post['prerequisiteList']); $quizMapper->activateStatitic($this->_post['prerequisiteList'], 1440); } if (!$this->formHandler($quiz->getId(), $this->_post)) { $quiz->setFormActivated(false); } $quizMapper->save($quiz); $this->showAction(); return; } else { WpProQuiz_View_View::admin_notices(__('Quiz title or quiz description are not filled', 'wp-pro-quiz')); } } else { if (isset($this->_post['template']) || isset($this->_post['templateLoad'])) { if (isset($this->_post['template'])) { $template = $this->saveTemplate(); } else { $template = $templateMapper->fetchById($this->_post['templateLoadId']); } $data = $template->getData(); if ($data !== null) { $quiz = $data['quiz']; $forms = $data['forms']; $prerequisiteQuizList = $data['prerequisiteQuizList']; } } else { $quiz = $m->fetch($id); } } $this->view->quiz = $quiz; $this->view->prerequisiteQuizList = $prerequisiteQuizList; $this->view->quizList = $m->fetchAllAsArray(array('id', 'name'), array($id)); $this->view->captchaIsInstalled = class_exists('ReallySimpleCaptcha'); $this->view->forms = $forms; $this->view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false); $this->view->show(); }