public function export($ids)
 {
     $dom = new DOMDocument('1.0', 'utf-8');
     $root = $dom->createElement('wpProQuiz');
     $dom->appendChild($root);
     $header = $dom->createElement('header');
     $header->setAttribute('version', WPPROQUIZ_VERSION);
     $header->setAttribute('exportVersion', 1);
     $root->appendChild($header);
     $data = $dom->createElement('data');
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $formMapper = new WpProQuiz_Model_FormMapper();
     foreach ($ids as $id) {
         $quizModel = $quizMapper->fetch($id);
         if ($quizModel->getId() <= 0) {
             continue;
         }
         $questionModel = $questionMapper->fetchAll($quizModel->getId());
         $forms = array();
         if ($quizModel->isFormActivated()) {
             $forms = $formMapper->fetch($quizModel->getId());
         }
         $quizElement = $this->getQuizElement($dom, $quizModel, $forms);
         $quizElement->appendChild($questionsElement = $dom->createElement('questions'));
         foreach ($questionModel as $model) {
             $questionElement = $this->createQuestionElement($dom, $model);
             $questionsElement->appendChild($questionElement);
         }
         $data->appendChild($quizElement);
     }
     $root->appendChild($data);
     return $dom->saveXML();
 }
 public function showAction($id)
 {
     $view = new WpProQuiz_View_FrontQuiz();
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $categoryMapper = new WpProQuiz_Model_CategoryMapper();
     $formMapper = new WpProQuiz_Model_FormMapper();
     $quiz = $quizMapper->fetch($id);
     if ($quiz->isShowMaxQuestion() && $quiz->getShowMaxQuestionValue() > 0) {
         $value = $quiz->getShowMaxQuestionValue();
         if ($quiz->isShowMaxQuestionPercent()) {
             $count = $questionMapper->count($id);
             $value = ceil($count * $value / 100);
         }
         $question = $questionMapper->fetchAll($id, true, $value);
     } else {
         $question = $questionMapper->fetchAll($id);
     }
     $view->quiz = $quiz;
     $view->question = $question;
     $view->category = $categoryMapper->fetchByQuiz($quiz->getId());
     $view->forms = $formMapper->fetch($quiz->getId());
     $view->show(true);
 }
 /**
  * @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 static function ajaxLoadCopyQuestion($data)
 {
     if (!current_user_can('wpProQuiz_edit_quiz')) {
         echo json_encode(array());
         exit;
     }
     $quizId = $data['quizId'];
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $data = array();
     $quiz = $quizMapper->fetchAll();
     foreach ($quiz as $qz) {
         if ($qz->getId() == $quizId) {
             continue;
         }
         $question = $questionMapper->fetchAll($qz->getId());
         $questionArray = array();
         foreach ($question as $qu) {
             $questionArray[] = array('name' => $qu->getTitle(), 'id' => $qu->getId());
         }
         $data[] = array('name' => $qz->getName(), 'id' => $qz->getId(), 'question' => $questionArray);
     }
     return json_encode($data);
 }
 public static function ajaxQuizLoadData($data)
 {
     $id = $data['quizId'];
     $view = new WpProQuiz_View_FrontQuiz();
     $quizMapper = new WpProQuiz_Model_QuizMapper();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $categoryMapper = new WpProQuiz_Model_CategoryMapper();
     $formMapper = new WpProQuiz_Model_FormMapper();
     $quiz = $quizMapper->fetch($id);
     if ($quiz->isShowMaxQuestion() && $quiz->getShowMaxQuestionValue() > 0) {
         $value = $quiz->getShowMaxQuestionValue();
         if ($quiz->isShowMaxQuestionPercent()) {
             $count = $questionMapper->count($id);
             $value = ceil($count * $value / 100);
         }
         $question = $questionMapper->fetchAll($id, true, $value);
     } else {
         $question = $questionMapper->fetchAll($id);
     }
     if (empty($quiz) || empty($question)) {
         return null;
     }
     $view->quiz = $quiz;
     $view->question = $question;
     $view->category = $categoryMapper->fetchByQuiz($quiz->getId());
     $view->forms = $formMapper->fetch($quiz->getId());
     return json_encode($view->getQuizData());
 }
 public function getQuestion($quizId)
 {
     $m = new WpProQuiz_Model_QuestionMapper();
     return $m->fetchAll($quizId);
 }