From 4b0e6c5374d5686b7ff83908fa80734805cae659 Mon Sep 17 00:00:00 2001 From: Rami Jasim Date: Wed, 11 Dec 2024 12:12:13 +0100 Subject: remaining first batch of MR comments --- lib/classes/MyRealmModel.php | 26 +++++++++++++++----------- lib/modules/Blubber.php | 4 +++- lib/modules/CoreDocuments.php | 2 +- lib/modules/IliasInterfaceModule.php | 2 +- 4 files changed, 20 insertions(+), 14 deletions(-) diff --git a/lib/classes/MyRealmModel.php b/lib/classes/MyRealmModel.php index 83c41e8..d8cd973 100644 --- a/lib/classes/MyRealmModel.php +++ b/lib/classes/MyRealmModel.php @@ -464,11 +464,13 @@ class MyRealmModel { // -- 0. Extract all courses: semester is irrelevant and flatten for children $all_courses = []; - foreach ($sem_courses as $sem => &$courses) { - foreach ($courses as $c_id => &$course) { - $all_courses[$c_id] = &$course; - foreach ($course['children'] as $child) { - $all_courses[$child['seminar_id']] = &$child; + foreach ($sem_courses as $courses) { + foreach ($courses as $c_id => $course) { + $all_courses[$c_id] = $course; + if (!empty($course['children'])) { + foreach ($course['children'] as $child_course) { + $all_courses[$child_course['seminar_id']] = $child_course; + } } } } @@ -480,7 +482,7 @@ class MyRealmModel if (!Config::get()->VOTE_ENABLE && isset($default_modules[-1])) { unset($default_modules[-1]); } - foreach ($all_courses as $course_id => &$course) { // Somehow the `&` is necessary here, otherwise some courses will be missing + foreach ($all_courses as $course_id => $course) { // add every default module with null, so there will be blank spaces in the nav $navigation[$course_id] = array_fill_keys( array_keys($default_modules), @@ -514,7 +516,7 @@ class MyRealmModel if ($c_ids) { if ($plugin_id === -1) { foreach ($c_ids as $c_id) { - // TODO test vote + // TODO testing vote need to be done $navigation[$c_id][$plugin_id] = self::checkVote($all_courses[$c_id], $user_id, $c_id); } } elseif ($plugin_data['studip_module'] instanceof StudipModuleExtended) { @@ -535,10 +537,12 @@ class MyRealmModel } // -- 3. Assign the data to the original object - foreach ($all_course_ids as $c_id) { - $all_courses[$c_id]['navigation'] = $navigation[$c_id]; - $all_courses[$c_id]['visitdate'] = $visits[$c_id][0]['visitdate']; - $all_courses[$c_id]['last_visitdate'] = $visits[$c_id][0]['last_visitdate']; + foreach ($sem_courses as &$courses) { + foreach ($courses as $c_id => &$course) { + $course['navigation'] = $navigation[$c_id] ?? null; + $course['visitdate'] = $visits[$c_id][0]['visitdate'] ?? null; + $course['last_visitdate'] = $visits[$c_id][0]['last_visitdate'] ?? null; + } } } diff --git a/lib/modules/Blubber.php b/lib/modules/Blubber.php index 3f00aa1..12f4ca0 100644 --- a/lib/modules/Blubber.php +++ b/lib/modules/Blubber.php @@ -125,7 +125,9 @@ class Blubber extends CorePlugin implements StudipModuleExtended ]; $threads = []; BlubberComment::findEachBySQL( - fn($comment) => $threads[$comment->thread_id][] = $comment, + function ($comment) use (&$threads) { + $threads[$comment->thread_id][] = $comment; + }, $condition, $params ); diff --git a/lib/modules/CoreDocuments.php b/lib/modules/CoreDocuments.php index fab81c4..b782808 100644 --- a/lib/modules/CoreDocuments.php +++ b/lib/modules/CoreDocuments.php @@ -146,7 +146,7 @@ class CoreDocuments extends CorePlugin implements StudipModuleExtended, OERModul public function getManyIconNavigation(array $course_ids, ?string $user_id = null): array { // Assume that either courses or institutes will be fetched, but not a mix of them - $range_type = get_object_type($course_ids[0], ['sem', 'inst']) === 'sem' ? 'course' : 'institute'; + $range_type = get_object_type(array_pop($course_ids), ['sem', 'inst']) === 'sem' ? 'course' : 'institute'; $condition = "SELECT folders.range_id, file_refs.id FROM file_refs JOIN folders ON (folders.id = file_refs.folder_id) diff --git a/lib/modules/IliasInterfaceModule.php b/lib/modules/IliasInterfaceModule.php index 4019af9..1e4c2ca 100644 --- a/lib/modules/IliasInterfaceModule.php +++ b/lib/modules/IliasInterfaceModule.php @@ -109,7 +109,7 @@ class IliasInterfaceModule extends CorePlugin implements StudipModuleExtended, S public function getManyIconNavigation(array $course_ids, ?string $user_id = null): array { - // TODO Test + // TODO Test this function if (!Config::get()->ILIAS_INTERFACE_ENABLE) { return []; } -- cgit v1.0