/** * Get statistic information about tests * * This returns statistic info for a test * <br/>Example: * <code> * $tests = array(2, 4); * $info = EfrontStats :: getTestInfo($tests); //Get information for tests 2,4 * </code> * @param mixed $tests Either an array of tests id or false (request information for all existing tests) * @param mixed $categories denotes in how many categories will the scores from 0-100% be divided (if not false) * @param mixed $show_all: denotes whether the function should return the stats for all the times a user took a test (default=no: just return for the active test) * @return array the tests' statistinc info * @since 3.5.0 * @access public * @static */ public static function getTestInfo($tests = false, $categories = false, $show_all = false, $lesson = false, $users = false) { if ($tests == false) { $tests = eF_getTableDataFlat("tests, content", "tests.id", "tests.content_ID=content.id and content.ctg_type = 'tests' and tests.lessons_ID != 0"); //This way we get tests that have a corresponding unit $tests = $tests['id']; } elseif (!is_array($tests)) { $tests = array($tests); } $lessonNames = eF_getTableDataFlat("lessons", "id,name"); sizeof($lessonNames) > 0 ? $lessonNames = array_combine($lessonNames['id'], $lessonNames['name']) : ($lessonNames = array()); if (!$users) { if ($lesson) { $lessonUsers = eF_getTableDataFlat("users_to_lessons ul, users u", "ul.users_LOGIN", "u.login=ul.users_LOGIN and u.archive=0 and ul.lessons_ID={$lesson} and ul.archive=0"); $users = array_combine($lessonUsers['users_LOGIN'], $lessonUsers['users_LOGIN']); } else { $result = eF_getTableData("users", "name, surname, login"); $users = array(); foreach ($result as $user) { $users[$user['login']] = $user; } } } if ($users) { if (sizeof($tests) == 1) { $doneTests = EfrontStats::getDoneTestsPerTest(array_keys($users), current($tests), false, false, $lesson); } else { $doneTests = EfrontStats::getDoneTestsPerTest(array_keys($users), false, false, false, $lesson); } } foreach ($tests as $id) { $testInfo = array(); $test = new EfrontTest($id); //$unit = $test -> getUnit(); $testInfo['general']['id'] = $id; //$testInfo['general']['name'] = $unit -> offsetGet('name'); //$testInfo['general']['content_ID'] = $unit -> offsetGet('id'); $testInfo['general']['name'] = $test->test['name']; $testInfo['general']['content_ID'] = $test->test['content_ID']; $testInfo['general']['lesson_name'] = $lessonNames[$test->test['lessons_ID']]; $testInfo['general']['duration'] = $test->options['duration']; $testInfo['general']['duration_str'] = eF_convertIntervalToTime($test->options['duration']); $testInfo['general']['redoable'] = $test->options['redoable']; $testInfo['general']['redoable_str'] = $test->options['redoable'] >= 1 ? _YES : _NO; $testInfo['general']['onebyone'] = $test->options['onebyone']; $testInfo['general']['onebyone_str'] = $test->options['onebyone'] == 1 ? _YES : _NO; $testInfo['general']['answers'] = $test->options['answers']; $testInfo['general']['answers_str'] = $test->options['answers'] == 1 ? _YES : _NO; $testInfo['general']['description'] = $test->test['description']; //$testInfo['general']['timestamp'] = $unit -> offsetGet('timestamp'); //$testInfo['general']['timestamp_str'] = strftime('%d-%m-%Y, %H:%M:%S', $testInfo['general']['timestamp']); $testInfo['general']['scorm'] = 0; $testInfo['questions']['total'] = 0; $testInfo['questions']['raw_text'] = 0; $testInfo['questions']['multiple_one'] = 0; $testInfo['questions']['multiple_many'] = 0; $testInfo['questions']['true_false'] = 0; $testInfo['questions']['match'] = 0; $testInfo['questions']['empty_spaces'] = 0; $testInfo['questions']['drag_drop'] = 0; $testInfo['questions']['low'] = 0; $testInfo['questions']['medium'] = 0; $testInfo['questions']['high'] = 0; if (!empty($test->options['random_test'])) { $questions = $test->getQuestionsForRandomSolvedTests(true); } else { $questions = $test->getQuestions(true); } foreach ($questions as $question) { $testInfo['questions']['total']++; $testInfo['questions'][$question->question['type']]++; $testInfo['questions'][$question->question['difficulty']]++; } //@todo: Compatibility status with old versions, need to change $testInfo['done'] = array(); // Create results score categories if ($categories) { $testInfo['score_categories'] = array(); $step = 100 / $categories; for ($i = 0; $i < $categories; $i++) { $testInfo['score_categories'][$i] = array("from" => $i * $step, "to" => ($i + 1) * $step, "count" => 0); if ($i == $categories - 1) { $testInfo['score_categories'][$i]["to"] = 100; } } } foreach ($doneTests[$id] as $user => $done) { foreach ($done as $key => $dt) { // Check that this $dt refers to a test occurence - and not average scores etc if (eF_checkParameter($key, "id") && ($show_all || $dt['archive'] == 0) && $dt['status'] != 'incomplete' && $dt['status'] != '') { $done_test = array('id' => $done['active_score'], 'users_LOGIN' => $dt['users_LOGIN'], 'name' => $users[$dt['users_LOGIN']]['name'], 'surname' => $users[$dt['users_LOGIN']]['surname'], 'score' => $dt['score'], 'active_score' => $done['active_score'], 'active_test_id' => $done['active_test_id'], 'timestamp' => $dt['time_end'], 'mastery_score' => $dt['mastery_score'], 'status' => $dt['status']); $testInfo['done'][] = $done_test; // Get the user's score in the correct stats category if ($categories) { $stat_cat = $dt['score'] / $step; $testInfo['score_categories'][$stat_cat >= $categories ? $categories - 1 : $stat_cat]["count"]++; } } } } // Create results score categories if ($categories) { $doneTestsCount = sizeof($testInfo['done']); $sum_count = $doneTestsCount; // counts how many users have score equal or above each score_category if ($sum_count > 0) { foreach ($testInfo['score_categories'] as $key => $score) { $testInfo['score_categories'][$key]['percent'] = round(100 * ($testInfo['score_categories'][$key]['count'] / $doneTestsCount), 2); $testInfo['score_categories'][$key]['sum_count'] = $sum_count; $testInfo['score_categories'][$key]['sum_count_percent'] = round(100 * ($sum_count / $doneTestsCount), 2); $sum_count -= $testInfo['score_categories'][$key]['count']; } } } $testsInfo[$id] = $testInfo; } return $testsInfo; }
if ($question['lessons_ID'] == 0) { $questions[$qid]['name'] = _SKILLGAPTESTS; } else { $questions[$qid]['name'] = _LESSON . ': "' . $question['name'] . '"'; } } // The test name requirement is to help avoid problems with databases where tests wiht lessons_ID=0 somehow exist. // Skillgap tests have mandatory name so the condition is correct $tests = eF_getTableData("tests LEFT OUTER JOIN tests_to_questions ON tests.id = tests_to_questions.tests_ID", "tests.*, count(questions_ID) as questions_num", "lessons_ID=0 AND tests.name <> '' GROUP BY tests.id"); //$smarty -> assign("T_RECENTLY_SKILLGAP_OPTIONS", array(array('text' => _SHOWALLSOLVEDSKILLGAPTESTS, 'image' => "16x16/search.png", 'href' => basename($_SERVER['PHP_SELF'])."?ctg=tests&solved_tests=1"))); } $testIds = array(); foreach ($tests as $key => $test) { $testIds[] = $test['id']; //@todo: change this call $doneTests = EfrontStats::getDoneTestsPerTest(false, $test['id']); $tests[$key]['average_score'] = $doneTests[$test['id']]['average_score']; $tests[$key]['options'] = unserialize($test['options']); if ($tests[$key]['options']['random_pool'] > 0) { if ($tests[$key]['questions_num'] > $tests[$key]['options']['random_pool']) { $tests[$key]['questions_num'] = $tests[$key]['options']['random_pool']; } } // If somehow the general threshold value is not set if (!isset($tests[$key]['options']['general_threshold'])) { $tests[$key]['options']['general_threshold'] = 50; $newOptions = serialize($tests[$key]['options']); eF_updateTableData("tests", array("options" => $newOptions), "id = '" . $test['id'] . "'"); } } $smarty->assign("T_QUESTIONTYPESTRANSLATIONS", Question::$questionTypes);