private function makeDataList($quizId, $array, $modus)
 {
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $question = $questionMapper->fetchAllList($quizId, array('id', 'points'));
     $ids = array();
     foreach ($question as $q) {
         if (!isset($array[$q['id']])) {
             continue;
         }
         $ids[] = $q['id'];
         $v = $array[$q['id']];
         if (!isset($v) || $v['points'] > $q['points'] || $v['points'] < 0) {
             return false;
         }
     }
     $avgTime = null;
     if ($modus == WpProQuiz_Model_Quiz::QUIZ_MODUS_SINGLE) {
         $avgTime = ceil($array['comp']['quizTime'] / count($question));
     }
     unset($array['comp']);
     $ak = array_keys($array);
     if (array_diff($ids, $ak) !== array_diff($ak, $ids)) {
         return false;
     }
     $values = array();
     foreach ($array as $k => $v) {
         $s = new WpProQuiz_Model_Statistic();
         $s->setQuestionId($k);
         $s->setHintCount(isset($v['tip']) ? 1 : 0);
         $s->setSolvedCount(isset($v['solved']) && $v['solved'] ? 1 : 0);
         $s->setCorrectCount($v['correct'] ? 1 : 0);
         $s->setIncorrectCount($v['correct'] ? 0 : 1);
         $s->setPoints($v['points']);
         $s->setQuestionTime($avgTime === null ? $v['time'] : $avgTime);
         $s->setAnswerData(isset($v['data']) ? $v['data'] : null);
         $values[] = $s;
     }
     return $values;
 }
 public static function ajaxLoadQuestionsSort($data)
 {
     if (!current_user_can('wpProQuiz_edit_quiz')) {
         return json_encode(array());
     }
     $quizMapper = new WpProQuiz_Model_QuestionMapper();
     $questions = $quizMapper->fetchAllList($data['quizId'], array('id', 'title'), true);
     return json_encode($questions);
 }
 /**
  * @deprecated
  */
 public static function ajaxLoadStatistic($data, $func)
 {
     if (!current_user_can('wpProQuiz_show_statistics')) {
         return json_encode(array());
     }
     $userId = $data['userId'];
     $quizId = $data['quizId'];
     $testId = $data['testId'];
     $maxPoints = 0;
     $sumQuestion = 0;
     $inTest = false;
     $category = array();
     $categoryList = array();
     $testJson = array();
     $formData = null;
     $statisticMapper = new WpProQuiz_Model_StatisticMapper();
     $questionMapper = new WpProQuiz_Model_QuestionMapper();
     $statisticRefMapper = new WpProQuiz_Model_StatisticRefMapper();
     $tests = $statisticRefMapper->fetchAll($quizId, $userId, $testId);
     $i = 1;
     foreach ($tests as $test) {
         if ($testId == $test->getStatisticRefId()) {
             $inTest = true;
         }
         $testJson[] = array('id' => $test->getStatisticRefId(), 'date' => '#' . $i++ . ' ' . WpProQuiz_Helper_Until::convertTime($test->getCreateTime(), get_option('wpProQuiz_statisticTimeFormat', 'Y/m/d g:i A')));
     }
     if (!$inTest) {
         $data['testId'] = $testId = 0;
     }
     if (!$testId) {
         $statistics = $statisticRefMapper->fetchAvg($quizId, $userId);
     } else {
         $statistics = $statisticMapper->fetchAllByRef($testId);
         $refModel = $statisticRefMapper->fetchByRefId($testId);
         $formData = $refModel->getFormData();
     }
     $questionData = $questionMapper->fetchAllList($quizId, array('id', 'category_id', 'points'));
     $empty = array('questionId' => 0, 'correct' => 0, 'incorrect' => 0, 'hint' => 0, 'points' => 0, 'result' => 0, 'questionTime' => 0);
     $ca = $sa = array();
     $ga = $empty;
     foreach ($questionData as $cc) {
         $categoryList[$cc['id']] = $cc['category_id'];
         $c =& $category[$cc['category_id']];
         if (empty($c)) {
             $c = $cc;
             $c['sum'] = 1;
         } else {
             $c['points'] += $cc['points'];
             $c['sum']++;
         }
         $maxPoints += $cc['points'];
         $sumQuestion++;
         $sa[$cc['id']] = self::calcTotal($empty);
         $sa[$cc['id']]['questionId'] = $cc['id'];
         $ca[$cc['category_id']] = self::calcTotal($empty);
     }
     foreach ($statistics as $statistic) {
         $s = $statistic->getCorrectCount() + $statistic->getIncorrectCount();
         if ($s > 0) {
             $correct = $statistic->getCorrectCount() . ' (' . round(100 * $statistic->getCorrectCount() / $s, 2) . '%)';
             $incorrect = $statistic->getIncorrectCount() . ' (' . round(100 * $statistic->getIncorrectCount() / $s, 2) . '%)';
         } else {
             $incorrect = $correct = '0 (0%)';
         }
         $ga['correct'] += $statistic->getCorrectCount();
         $ga['incorrect'] += $statistic->getIncorrectCount();
         $ga['hint'] += $statistic->getHintCount();
         $ga['points'] += $statistic->getPoints();
         $ga['questionTime'] += $statistic->getQuestionTime();
         $cats =& $ca[$categoryList[$statistic->getQuestionId()]];
         if (!is_array($cats)) {
             $cats = $empty;
         }
         $cats['correct'] += $statistic->getCorrectCount();
         $cats['incorrect'] += $statistic->getIncorrectCount();
         $cats['hint'] += $statistic->getHintCount();
         $cats['points'] += $statistic->getPoints();
         $cats['questionTime'] += $statistic->getQuestionTime();
         $sa[$statistic->getQuestionId()] = array('questionId' => $statistic->getQuestionId(), 'correct' => $correct, 'incorrect' => $incorrect, 'hint' => $statistic->getHintCount(), 'points' => $statistic->getPoints(), 'questionTime' => self::convertToTimeString($statistic->getQuestionTime()));
     }
     foreach ($ca as $catIndex => $cat) {
         $ca[$catIndex] = self::calcTotal($cat, $category[$catIndex]['points'], $category[$catIndex]['sum']);
     }
     $sa[0] = self::calcTotal($ga, $maxPoints, $sumQuestion);
     return json_encode(array('question' => $sa, 'category' => $ca, 'tests' => $testJson, 'testId' => $data['testId'], 'formData' => $formData));
 }