public static function ajaxShowFrontToplist($data) { // workaround ... $_POST = $_POST['data']; $quizIds = empty($data['quizIds']) ? array() : array_unique((array) $data['quizIds']); $toplistMapper = new WpProQuiz_Model_ToplistMapper(); $quizMapper = new WpProQuiz_Model_QuizMapper(); $j = array(); foreach ($quizIds as $quizId) { $quiz = $quizMapper->fetch($quizId); if ($quiz == null || $quiz->getId() == 0) { continue; } $toplist = $toplistMapper->fetch($quizId, $quiz->getToplistDataShowLimit(), $quiz->getToplistDataSort()); foreach ($toplist as $tp) { $j[$quizId][] = array('name' => $tp->getName(), 'date' => WpProQuiz_Helper_Until::convertTime($tp->getDate(), get_option('wpProQuiz_toplistDataFormat', 'Y/m/d g:i A')), 'points' => $tp->getPoints(), 'result' => $tp->getResult()); } } return json_encode($j); }
public static function ajaxLoadHistory($data) { if (!current_user_can('wpProQuiz_show_statistics')) { return json_encode(array()); } $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper(); $formMapper = new WpProQuiz_Model_FormMapper(); $quizId = $data['quizId']; $forms = $formMapper->fetch($quizId); $page = isset($data['page']) && $data['page'] > 0 ? $data['page'] : 1; $limit = $data['pageLimit']; $start = $limit * ($page - 1); $startTime = (int) $data['dateFrom']; $endTime = (int) $data['dateTo'] ? $data['dateTo'] + 86400 : 0; $statisticModel = $statisticRefMapper->fetchHistory($quizId, $start, $limit, $data['users'], $startTime, $endTime); foreach ($statisticModel as $model) { /* @var $model WpProQuiz_Model_StatisticHistory */ if (!$model->getUserId()) { $model->setUserName(__('Anonymous', 'wp-pro-quiz')); } else { if ($model->getUserName() == '') { $model->setUserName(__('Deleted user', 'wp-pro-quiz')); } } $sum = $model->getCorrectCount() + $model->getIncorrectCount(); $result = round(100 * $model->getPoints() / $model->getGPoints(), 2) . '%'; $model->setResult($result); $model->setFormatTime(WpProQuiz_Helper_Until::convertTime($model->getCreateTime(), get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A'))); $model->setFormatCorrect($model->getCorrectCount() . ' (' . round(100 * $model->getCorrectCount() / $sum, 2) . '%)'); $model->setFormatIncorrect($model->getIncorrectCount() . ' (' . round(100 * $model->getIncorrectCount() / $sum, 2) . '%)'); $formData = $model->getFormData(); $formOverview = array(); foreach ($forms as $form) { /* @var $form WpProQuiz_Model_Form */ if ($form->isShowInStatistic()) { $formOverview[] = $formData != null && isset($formData[$form->getFormId()]) ? WpProQuiz_Helper_Form::formToString($form, $formData[$form->getFormId()]) : '----'; } } $model->setFormOverview($formOverview); } $view = new WpProQuiz_View_StatisticsAjax(); $view->historyModel = $statisticModel; $view->forms = $forms; $html = $view->getHistoryTable(); $navi = null; if (isset($data['generateNav']) && $data['generateNav']) { $count = $statisticRefMapper->countHistory($quizId, $data['users'], $startTime, $endTime); $navi = ceil(($count > 0 ? $count : 1) / $limit); } return json_encode(array('html' => $html, 'navi' => $navi)); }