/** * returns all test results for all participants * * @param array $partipants array of user ids * @param boolean if true, the result will be prepared for csv output (see processCSVRow) * * @return array of fields, see code for column titles */ function getAllTestResults($participants, $prepareForCSV = true) { $results = array(); $row = array("user_id" => $this->lng->txt("user_id"), "matriculation" => $this->lng->txt("matriculation"), "lastname" => $this->lng->txt("lastname"), "firstname" => $this->lng->txt("firstname"), "login" => $this->lng->txt("login"), "reached_points" => $this->lng->txt("tst_reached_points"), "max_points" => $this->lng->txt("tst_maximum_points"), "percent_value" => $this->lng->txt("tst_percent_solved"), "mark" => $this->lng->txt("tst_mark"), "ects" => $this->lng->txt("ects_grade")); $results[] = $row; if (count($participants)) { if ($this->ects_output) { $passed_array =& $this->getTotalPointsPassedArray(); } foreach ($participants as $active_id => $user_rec) { $row = array(); $reached_points = 0; $max_points = 0; foreach ($this->questions as $value) { $question =& ilObjTest::_instanciateQuestion($value); if (is_object($question)) { $max_points += $question->getMaximumPoints(); $reached_points += $question->getReachedPoints($active_id); } } if ($max_points > 0) { $percentvalue = $reached_points / $max_points; if ($percentvalue < 0) { $percentvalue = 0.0; } } else { $percentvalue = 0; } $mark_obj = $this->mark_schema->getMatchingMark($percentvalue * 100); $passed = ""; if ($mark_obj) { $mark = $mark_obj->getOfficialName(); $ects_mark = $this->getECTSGrade($passed_array, $reached_points, $max_points); } if ($this->getAnonymity()) { $user_rec['firstname'] = ""; $user_rec['lastname'] = $this->lng->txt("unknown"); } $row = array("user_id" => $user_rec['usr_id'], "matriculation" => $user_rec['matriculation'], "lastname" => $user_rec['lastname'], "firstname" => $user_rec['firstname'], "login" => $user_rec['login'], "reached_points" => $reached_points, "max_points" => $max_points, "percent_value" => $percentvalue, "mark" => $mark, "ects" => $ects_mark); $results[] = $prepareForCSV ? $this->processCSVRow($row, true) : $row; } } return $results; }
/** @TODO Move this to a proper place. */ function _updateTestResultCache($active_id, ilAssQuestionProcessLocker $processLocker = null) { global $ilDB; include_once "./Modules/Test/classes/class.ilObjTest.php"; include_once "./Modules/Test/classes/class.assMarkSchema.php"; $pass = ilObjTest::_getResultPass($active_id); $query = "\n\t\t\tSELECT\t\ttst_pass_result.*\n\t\t\tFROM\t\ttst_pass_result\n\t\t\tWHERE\t\tactive_fi = %s\n\t\t\tAND\t\t\tpass = %s\n\t\t"; $result = $ilDB->queryF($query, array('integer', 'integer'), array($active_id, $pass)); $row = $ilDB->fetchAssoc($result); $max = $row['maxpoints']; $reached = $row['points']; $obligationsAnswered = (int) $row['obligations_answered']; include_once "./Modules/Test/classes/class.assMarkSchema.php"; $percentage = !$max ? 0 : $reached / $max * 100.0; $mark = ASS_MarkSchema::_getMatchingMarkFromActiveId($active_id, $percentage); $isPassed = $mark["passed"] ? 1 : 0; $isFailed = !$mark["passed"] ? 1 : 0; if (is_object($processLocker)) { $processLocker->requestUserTestResultUpdateLock(); } $query = "\n\t\t\tDELETE FROM\t\ttst_result_cache\n\t\t\tWHERE\t\t\tactive_fi = %s\n\t\t"; $affectedRows = $ilDB->manipulateF($query, array('integer'), array($active_id)); $ilDB->insert('tst_result_cache', array('active_fi' => array('integer', $active_id), 'pass' => array('integer', strlen($pass) ? $pass : 0), 'max_points' => array('float', strlen($max) ? $max : 0), 'reached_points' => array('float', strlen($reached) ? $reached : 0), 'mark_short' => array('text', strlen($mark["short_name"]) ? $mark["short_name"] : " "), 'mark_official' => array('text', strlen($mark["official_name"]) ? $mark["official_name"] : " "), 'passed' => array('integer', $isPassed), 'failed' => array('integer', $isFailed), 'tstamp' => array('integer', time()), 'hint_count' => array('integer', $row['hint_count']), 'hint_points' => array('float', $row['hint_points']), 'obligations_answered' => array('integer', $obligationsAnswered))); if (is_object($processLocker)) { $processLocker->releaseUserTestResultUpdateLock(); } }
/** * Returns TRUE if the user with the user id $user_id passed the test with the object id $a_obj_id * * @param int $user_id The user id * @param int $a_obj_id The object id * @return boolean TRUE if the user passed the test, FALSE otherwise */ public static function _isPassed($user_id, $a_obj_id) { global $ilDB; $result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id", array('integer', 'integer'), array($user_id, $a_obj_id)); if (!$result->numRows()) { $result = $ilDB->queryF("SELECT tst_active.active_id FROM tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s", array('integer', 'integer'), array($user_id, $a_obj_id)); $row = $ilDB->fetchAssoc($result); if ($row['active_id'] > 0) { include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; assQuestion::_updateTestResultCache($row['active_id']); } else { return false; } } $result = $ilDB->queryF("SELECT tst_result_cache.* FROM tst_result_cache, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_result_cache.active_fi = tst_active.active_id", array('integer', 'integer'), array($user_id, $a_obj_id)); if (!$result->numRows()) { $result = $ilDB->queryF("SELECT tst_pass_result.*, tst_tests.pass_scoring, tst_tests.random_test, tst_tests.test_id FROM tst_pass_result, tst_active, tst_tests WHERE tst_active.test_fi = tst_tests.test_id AND tst_active.user_fi = %s AND tst_tests.obj_fi = %s AND tst_pass_result.active_fi = tst_active.active_id ORDER BY tst_pass_result.pass", array('integer', 'integer'), array($user_id, $a_obj_id)); $points = array(); while ($row = $ilDB->fetchAssoc($result)) { array_push($points, $row); } $reached = 0; $max = 0; if ($points[0]["pass_scoring"] == 0) { $reached = $points[count($points) - 1]["points"]; $max = $points[count($points) - 1]["maxpoints"]; if (!$max) { $active_id = $points[count($points) - 1]["active_fi"]; $pass = $points[count($points) - 1]["pass"]; if (strlen($active_id) && strlen($pass)) { include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; $res = assQuestion::_updateTestPassResults($active_id, $pass); $max = $res['maxpoints']; $reached = $res['points']; } } } else { foreach ($points as $row) { if ($row["points"] > $reached) { $reached = $row["points"]; $max = $row["maxpoints"]; if (!$max) { $active_id = $row["active_fi"]; $pass = $row["pass"]; if (strlen($active_id) && strlen($pass)) { include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php"; assQuestion::_updateTestPassResults($active_id, $pass); $max = $res['maxpoints']; $reached = $res['points']; } } } } } include_once "./Modules/Test/classes/class.assMarkSchema.php"; $percentage = !$max ? 0 : $reached / $max * 100.0; $mark = ASS_MarkSchema::_getMatchingMarkFromObjId($a_obj_id, $percentage); return $mark["passed"] ? TRUE : FALSE; } else { $row = $ilDB->fetchAssoc($result); return $row['passed'] ? true : false; } }