private function edit()
 {
     if (!current_user_can('wpProQuiz_change_settings')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $mapper = new WpProQuiz_Model_GlobalSettingsMapper();
     $categoryMapper = new WpProQuiz_Model_CategoryMapper();
     $templateMapper = new WpProQuiz_Model_TemplateMapper();
     $view = new WpProQuiz_View_GobalSettings();
     if (isset($this->_post['submit'])) {
         $mapper->save(new WpProQuiz_Model_GlobalSettings($this->_post));
         WpProQuiz_View_View::admin_notices(__('Settings saved', 'wp-pro-quiz'), 'info');
         $toplistDateFormat = $this->_post['toplist_date_format'];
         if ($toplistDateFormat == 'custom') {
             $toplistDateFormat = trim($this->_post['toplist_date_format_custom']);
         }
         $statisticTimeFormat = $this->_post['statisticTimeFormat'];
         if (add_option('wpProQuiz_toplistDataFormat', $toplistDateFormat) === false) {
             update_option('wpProQuiz_toplistDataFormat', $toplistDateFormat);
         }
         if (add_option('wpProQuiz_statisticTimeFormat', $statisticTimeFormat, '', 'no') === false) {
             update_option('wpProQuiz_statisticTimeFormat', $statisticTimeFormat);
         }
         //Email
         //$mapper->saveEmailSettiongs($this->_post['email']);
         //$mapper->saveUserEmailSettiongs($this->_post['userEmail']);
     } else {
         if (isset($this->_post['databaseFix'])) {
             WpProQuiz_View_View::admin_notices(__('Database repaired', 'wp-pro-quiz'), 'info');
             $DbUpgradeHelper = new WpProQuiz_Helper_DbUpgrade();
             $DbUpgradeHelper->databaseDelta();
         }
     }
     $view->settings = $mapper->fetchAll();
     $view->isRaw = !preg_match('[raw]', apply_filters('the_content', '[raw]a[/raw]'));
     $view->category = $categoryMapper->fetchAll();
     $view->categoryQuiz = $categoryMapper->fetchAll(WpProQuiz_Model_Category::CATEGORY_TYPE_QUIZ);
     $view->email = $mapper->getEmailSettings();
     $view->userEmail = $mapper->getUserEmailSettings();
     $view->templateQuiz = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUIZ, false);
     $view->templateQuestion = $templateMapper->fetchAll(WpProQuiz_Model_Template::TEMPLATE_TYPE_QUESTION, false);
     $view->toplistDataFormat = get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A');
     $view->statisticTimeFormat = get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A');
     $view->show();
 }
 /**
  * @deprecated
  */
 private function show($quizId)
 {
     if (!current_user_can('wpProQuiz_show_statistics')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $this->showNew($quizId);
     return;
     $view = new WpProQuiz_View_Statistics();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $categoryMapper = new WpProQuiz_Model_CategoryMapper();
     $formMapper = new WpProQuiz_Model_FormMapper();
     $questions = $questionMapper->fetchAll($quizId);
     $category = $categoryMapper->fetchAll();
     $categoryEmpty = new WpProQuiz_Model_Category();
     $categoryEmpty->setCategoryName(__('No category', 'wp-pro-quiz'));
     $list = array();
     $cats = array();
     foreach ($category as $c) {
         $cats[$c->getCategoryId()] = $c;
     }
     $cats[0] = $categoryEmpty;
     foreach ($questions as $q) {
         $list[$q->getCategoryId()][] = $q;
     }
     $view->quiz = $quizMapper->fetch($quizId);
     $view->questionList = $list;
     $view->categoryList = $cats;
     $view->forms = $formMapper->fetch($quizId);
     if (has_action('pre_user_query', 'ure_exclude_administrators')) {
         remove_action('pre_user_query', 'ure_exclude_administrators');
         $users = get_users(array('fields' => array('ID', 'user_login', 'display_name')));
         add_action('pre_user_query', 'ure_exclude_administrators');
     } else {
         $users = get_users(array('fields' => array('ID', 'user_login', 'display_name')));
     }
     array_unshift($users, (object) array('ID' => 0));
     $view->users = $users;
     $view->show();
 }
 public function showAction()
 {
     if (!current_user_can('wpProQuiz_show')) {
         wp_die(__('You do not have sufficient permissions to access this page.'));
     }
     $m = new WpProQuiz_Model_QuizMapper();
     $mm = new WpProQuiz_Model_QuestionMapper();
     $categoryMapper = new WpProQuiz_Model_CategoryMapper();
     $view = new WpProQuiz_View_QuestionOverall();
     $view->quiz = $m->fetch($this->_quizId);
     $per_page = (int) get_user_option('wp_pro_quiz_question_overview_per_page');
     if (empty($per_page) || $per_page < 1) {
         $per_page = 20;
     }
     $current_page = $this->getCurrentPage();
     $search = isset($_GET['s']) ? trim($_GET['s']) : '';
     $orderBy = isset($_GET['orderby']) ? trim($_GET['orderby']) : '';
     $order = isset($_GET['order']) ? trim($_GET['order']) : '';
     $offset = ($current_page - 1) * $per_page;
     $limit = $per_page;
     $filter = array();
     if (isset($_GET['cat'])) {
         $filter['cat'] = $_GET['cat'];
     }
     $result = $mm->fetchTable($this->_quizId, $orderBy, $order, $search, $limit, $offset, $filter);
     $view->questionItems = $result['questions'];
     $view->questionCount = $result['count'];
     $view->categoryItems = $categoryMapper->fetchAll(WpProQuiz_Model_Category::CATEGORY_TYPE_QUESTION);
     $view->perPage = $per_page;
     $view->show();
 }