From 19d6305c039fb906d2d8ebcdbb8e4df5604320d4 Mon Sep 17 00:00:00 2001 From: Jan-Hendrik Willms <tleilax+studip@gmail.com> Date: Mon, 18 Mar 2024 09:09:19 +0000 Subject: [PATCH] prevent warning, fixes #3822 Closes #3822 Merge request studip/studip!2689 --- lib/classes/MyRealmModel.php | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/lib/classes/MyRealmModel.php b/lib/classes/MyRealmModel.php index 6d1ef02a86f..8008580dffa 100644 --- a/lib/classes/MyRealmModel.php +++ b/lib/classes/MyRealmModel.php @@ -655,16 +655,18 @@ class MyRealmModel // Create sort order for assigned sem_tree entries. $entries = StudipStudyArea::findMany(array_keys($sem_tree_names)); - $order = []; - foreach ($entries as $entry) { - $order[$entry->getId()] = $entry->getIndex(); - } - $max = max(array_map('strlen', $order)); + if (count($entries) > 0) { + $order = []; + foreach ($entries as $entry) { + $order[$entry->getId()] = $entry->getIndex(); + } + $max = max(array_map('strlen', $order)); - // Now sort courses by sem_tree entry order. - uksort($_tmp_courses[$sem_key], function ($a, $b) use ($order, $max) { - return str_pad($order[$a] ?? '', $max, '0') - str_pad($order[$b] ?? '', $max, '0'); - }); + // Now sort courses by sem_tree entry order. + uksort($_tmp_courses[$sem_key], function ($a, $b) use ($order, $max) { + return str_pad($order[$a] ?? '', $max, '0') - str_pad($order[$b] ?? '', $max, '0'); + }); + } //At this point the $_tmp_courses array is sorted by the ordering //of the sem_tree. -- GitLab