From 6e617efef05719e38a82969a8b8f52208198f77a Mon Sep 17 00:00:00 2001 From: Stefan Meyer Date: Thu, 17 Oct 2024 13:29:51 +0200 Subject: [PATCH] Precondition: test result percentage evaluation --- .../Test/classes/class.ilObjTestAccess.php | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/components/ILIAS/Test/classes/class.ilObjTestAccess.php b/components/ILIAS/Test/classes/class.ilObjTestAccess.php index 4c9a579e49c9..ddfc27efd30f 100755 --- a/components/ILIAS/Test/classes/class.ilObjTestAccess.php +++ b/components/ILIAS/Test/classes/class.ilObjTestAccess.php @@ -209,6 +209,42 @@ public static function _isPassed($user_id, $a_obj_id): bool } } + protected static function isRangeAchieved(int $user_id, int $a_obj_id, string $value): bool + { + global $DIC; + + $value_arr = unserialize($value); + if ($value_arr === false) { + return false; + } + $min_percentage = $value_arr['min_percentage'] ?? 0; + $max_percentage = $value_arr['max_percentage'] ?? 0; + ilLoggerFactory::getLogger('root')->info("Requirements: " . $min_percentage . ' ' . $max_percentage . '%'); + + $db = $DIC->database(); + + $query = '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 = ' . $db->quote($user_id, ilDBConstants::T_INTEGER) . ' ' . + 'AND tst_tests.obj_fi = ' . $db->quote($a_obj_id, ilDBConstants::T_INTEGER) . ' ' . + 'AND tst_result_cache.active_fi = tst_active.active_id'; + $res = $db->query($query); + while ($row = $res->fetchRow(ilDBConstants::FETCHMODE_OBJECT)) { + $max = $row->max_points; + $reached = $row->reached_points; + $reached_percentage = (!$max) ? 0 : ($reached / $max) * 100.0; + ilLoggerFactory::getLogger('root')->info('Reached: ' . $reached_percentage . '%'); + + if ( + $reached_percentage >= $min_percentage && + $reached_percentage <= $max_percentage + ) { + return true; + } + return false; + } + } + /** * Returns TRUE if the user with the user id $user_id failed the test with the object id $a_obj_id * @@ -352,6 +388,9 @@ public static function checkCondition(int $a_trigger_obj_id, string $a_operator, case ilConditionHandler::OPERATOR_NOT_FINISHED: return !ilObjTestAccess::hasFinished($a_usr_id, $a_trigger_obj_id); + case ilConditionHandler::OPERATOR_RESULT_RANGE_PERCENTAGE: + return ilObjTestAccess::isRangeAchieved($a_usr_id, $a_trigger_obj_id, $a_value); + default: return true; }