public function isLockQuiz()
 {
     $quizId = (int) $this->_post['quizId'];
     $userId = get_current_user_id();
     $data = array();
     $lockMapper = new WpProQuiz_Model_LockMapper();
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $prerequisiteMapper = new WpProQuiz_Model_PrerequisiteMapper();
     $quiz = $quizMapper->fetch($this->_post['quizId']);
     if ($quiz === null || $quiz->getId() <= 0) {
         return null;
     }
     if ($this->isPreLockQuiz($quiz)) {
         $lockIp = $lockMapper->isLock($this->_post['quizId'], $this->getIp(), $userId, WpProQuiz_Model_Lock::TYPE_QUIZ);
         $lockCookie = false;
         $cookieTime = $quiz->getQuizRunOnceTime();
         if (isset($this->_cookie['wpProQuiz_lock']) && $userId == 0 && $quiz->isQuizRunOnceCookie()) {
             $cookieJson = json_decode($this->_cookie['wpProQuiz_lock'], true);
             if ($cookieJson !== false) {
                 if (isset($cookieJson[$this->_post['quizId']]) && $cookieJson[$this->_post['quizId']] == $cookieTime) {
                     $lockCookie = true;
                 }
             }
         }
         $data['lock'] = array('is' => $lockIp || $lockCookie, 'pre' => true);
     }
     if ($quiz->isPrerequisite()) {
         $quizIds = array();
         if ($userId > 0) {
             $quizIds = $prerequisiteMapper->getNoPrerequisite($quizId, $userId);
         } else {
             $checkIds = $prerequisiteMapper->fetchQuizIds($quizId);
             if (isset($this->_cookie['wpProQuiz_result'])) {
                 $r = json_decode($this->_cookie['wpProQuiz_result'], true);
                 if ($r !== null && is_array($r)) {
                     foreach ($checkIds as $id) {
                         if (!isset($r[$id]) || !$r[$id]) {
                             $quizIds[] = $id;
                         }
                     }
                 }
             } else {
                 $quizIds = $checkIds;
             }
         }
         if (!empty($quizIds)) {
             $names = $quizMapper->fetchCol($quizIds, 'name');
             if (!empty($names)) {
                 $data['prerequisite'] = implode(', ', $names);
             }
         }
     }
     if ($quiz->isStartOnlyRegisteredUser()) {
         $data['startUserLock'] = (int) (!is_user_logged_in());
     }
     return $data;
 }
 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();
 }