From db64b80b53f160cbf6410aaff5b2fdbe2bcff39f Mon Sep 17 00:00:00 2001 From: Christoph Ludolf Date: Wed, 20 Nov 2024 11:17:20 +0100 Subject: [PATCH] Tracking: Adds LP percentage support for LP MODE COLLECTION --- .../classes/class.ilLPTableBaseGUI.php | 28 ++++++++++--------- .../status/class.ilLPStatusCollection.php | 17 +++++++++++ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/components/ILIAS/Tracking/classes/class.ilLPTableBaseGUI.php b/components/ILIAS/Tracking/classes/class.ilLPTableBaseGUI.php index 9b512555277f..4bccab7826a0 100755 --- a/components/ILIAS/Tracking/classes/class.ilLPTableBaseGUI.php +++ b/components/ILIAS/Tracking/classes/class.ilLPTableBaseGUI.php @@ -758,19 +758,21 @@ protected function isPercentageAvailable(int $a_obj_id): bool $mode = $olp->getCurrentMode(); if (in_array( $mode, - array(ilLPObjSettings::LP_MODE_TLT, - ilLPObjSettings::LP_MODE_VISITS, - ilLPObjSettings::LP_MODE_SCORM, - ilLPObjSettings::LP_MODE_LTI_OUTCOME, - ilLPObjSettings::LP_MODE_CMIX_COMPLETED, - ilLPObjSettings::LP_MODE_CMIX_COMPL_WITH_FAILED, - ilLPObjSettings::LP_MODE_CMIX_PASSED, - ilLPObjSettings::LP_MODE_CMIX_PASSED_WITH_FAILED, - ilLPObjSettings::LP_MODE_CMIX_COMPLETED_OR_PASSED, - ilLPObjSettings::LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED, - ilLPObjSettings::LP_MODE_VISITED_PAGES, - ilLPObjSettings::LP_MODE_TEST_PASSED - ) + [ + ilLPObjSettings::LP_MODE_TLT, + ilLPObjSettings::LP_MODE_VISITS, + ilLPObjSettings::LP_MODE_SCORM, + ilLPObjSettings::LP_MODE_LTI_OUTCOME, + ilLPObjSettings::LP_MODE_CMIX_COMPLETED, + ilLPObjSettings::LP_MODE_CMIX_COMPL_WITH_FAILED, + ilLPObjSettings::LP_MODE_CMIX_PASSED, + ilLPObjSettings::LP_MODE_CMIX_PASSED_WITH_FAILED, + ilLPObjSettings::LP_MODE_CMIX_COMPLETED_OR_PASSED, + ilLPObjSettings::LP_MODE_CMIX_COMPL_OR_PASSED_WITH_FAILED, + ilLPObjSettings::LP_MODE_VISITED_PAGES, + ilLPObjSettings::LP_MODE_TEST_PASSED, + ilLPObjSettings::LP_MODE_COLLECTION + ] )) { return true; } diff --git a/components/ILIAS/Tracking/classes/status/class.ilLPStatusCollection.php b/components/ILIAS/Tracking/classes/status/class.ilLPStatusCollection.php index 38a3c35d1440..e7b52d238de9 100755 --- a/components/ILIAS/Tracking/classes/status/class.ilLPStatusCollection.php +++ b/components/ILIAS/Tracking/classes/status/class.ilLPStatusCollection.php @@ -527,4 +527,21 @@ public static function _lookupInProgressForObject( $a_user_ids ); } + + public function determinePercentage(int $a_obj_id, int $a_usr_id, ?object $a_obj = null): int + { + $status_info = self::_getStatusInfo($a_obj_id); + if (empty($status_info)) { + return 0; + } + $passed = 0; + foreach ($status_info['collections'] as $item_ref_id) { + $obj_id = ilObject::_lookupObjId($item_ref_id); + if (ilLPStatusWrapper::_determineStatus($obj_id, $a_usr_id) === self::LP_STATUS_COMPLETED_NUM) { + $passed++; + } + } + $percentage = (int) ((100.0 / $status_info["num_collections"]) * $passed); + return $percentage; + } }