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); }
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()); }