private function addEditQuestion($quizId)
 {
     $questionId = isset($_GET['questionId']) ? (int) $_GET['questionId'] : 0;
     if ($questionId) {
         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.'));
         }
     }
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $cateoryMapper = new WpProQuiz_Model_CategoryMapper();
     $templateMapper = new WpProQuiz_Model_TemplateMapper();
     if ($questionId && $questionMapper->existsAndWritable($questionId) == 0) {
         WpProQuiz_View_View::admin_notices(__('Question not found', 'wp-pro-quiz'), 'error');
         return;
     }
     $question = new WpProQuiz_Model_Question();
     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_Question $question */
             $question = $data['question'];
             $question->setId($questionId);
             $question->setQuizId($quizId);
         }
     } else {
         if (isset($this->_post['submit'])) {
             if ($questionId) {
                 WpProQuiz_View_View::admin_notices(__('Question edited', 'wp-pro-quiz'), 'info');
             } else {
                 WpProQuiz_View_View::admin_notices(__('Question added', 'wp-pro-quiz'), 'info');
             }
             $question = $questionMapper->save($this->getPostQuestionModel($quizId, $questionId), true);
             $questionId = $question->getId();
         } else {
             if ($questionId) {
                 $question = $questionMapper->fetch($questionId);
             }
         }
     }
     $view = new WpProQuiz_View_QuestionEdit();
     $view->categories = $cateoryMapper->fetchAll();
     $view->quiz = $quizMapper->fetch($quizId);
     $view->templates = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUESTION, false);
     $view->question = $question;
     $view->answerData = $this->setAnswerObject($question);
     $view->header = $questionId ? __('Edit question', 'wp-pro-quiz') : __('New question', 'wp-pro-quiz');
     if ($view->question->isAnswerPointsActivated()) {
         $view->question->setPoints(1);
     }
     $view->show();
 }
 /**
  * @deprecated
  */
 public function editPostAction($id)
 {
     $mapper = new WpProQuiz_Model_QuestionMapper();
     if (isset($this->_post['submit']) && $mapper->existsAndWritable($id)) {
         $post = $this->_post;
         $post['id'] = $id;
         $post['title'] = isset($post['title']) ? trim($post['title']) : '';
         $clearPost = $this->clearPost($post);
         $post['answerData'] = $clearPost['answerData'];
         if (empty($post['title'])) {
             $question = $mapper->fetch($id);
             $post['title'] = sprintf(__('Question: %d', 'wp-pro-quiz'), $question->getSort() + 1);
         }
         if ($post['answerType'] === 'assessment_answer') {
             $post['answerPointsActivated'] = 1;
         }
         if (isset($post['answerPointsActivated'])) {
             if (isset($post['answerPointsDiffModusActivated'])) {
                 $post['points'] = $clearPost['maxPoints'];
             } else {
                 $post['points'] = $clearPost['points'];
             }
         }
         $post['categoryId'] = $post['category'] > 0 ? $post['category'] : 0;
         $mapper->save(new WpProQuiz_Model_Question($post), true);
         WpProQuiz_View_View::admin_notices(__('Question edited', 'wp-pro-quiz'), 'info');
     }
 }