Skip to content
Snippets Groups Projects
Commit bd60f4a8 authored by Jan-Hendrik Willms's avatar Jan-Hendrik Willms Committed by David Siegfried
Browse files

fix php8 errors and warnings on my courses page, fixes #2232

Closes #2232

Merge request studip/studip!1462
parent b7ce03e2
No related branches found
No related tags found
No related merge requests found
...@@ -603,7 +603,7 @@ class MyCoursesController extends AuthenticatedController ...@@ -603,7 +603,7 @@ class MyCoursesController extends AuthenticatedController
if (is_array($courses)) { if (is_array($courses)) {
if ($group_field !== 'sem_number') { if ($group_field !== 'sem_number') {
// tlx: If array is 2-dimensional, merge it into a 1-dimensional // tlx: If array is 2-dimensional, merge it into a 1-dimensional
$courses = call_user_func_array('array_merge', $courses); $courses = array_merge(...array_values($courses));
} }
foreach ($courses as $course) { foreach ($courses as $course) {
...@@ -753,7 +753,7 @@ class MyCoursesController extends AuthenticatedController ...@@ -753,7 +753,7 @@ class MyCoursesController extends AuthenticatedController
foreach ($_inner as $course) { foreach ($_inner as $course) {
$_courses[$course['seminar_id']] = $course; $_courses[$course['seminar_id']] = $course;
if ($course['children']) { if (isset($course['children']) && is_array($couse['children'])) {
foreach ($course['children'] as $child) { foreach ($course['children'] as $child) {
$_courses[$child['seminar_id']] = $child; $_courses[$child['seminar_id']] = $child;
} }
......
...@@ -634,7 +634,12 @@ class MyRealmModel ...@@ -634,7 +634,12 @@ class MyRealmModel
*/ */
public static function groupBySemTree(&$sem_courses) public static function groupBySemTree(&$sem_courses)
{ {
$_tmp_courses = [];
foreach ($sem_courses as $sem_key => $collection) { foreach ($sem_courses as $sem_key => $collection) {
if (!isset($_tmp_courses[$sem_key])) {
$_tmp_courses[$sem_key] = [];
}
//We have to store the sem_tree names separately //We have to store the sem_tree names separately
//since we first need the sem_tree IDs as array keys. //since we first need the sem_tree IDs as array keys.
//This makes it more easy to get the ordering //This makes it more easy to get the ordering
...@@ -644,10 +649,18 @@ class MyRealmModel ...@@ -644,10 +649,18 @@ class MyRealmModel
if (!empty($course['sem_tree'])) { if (!empty($course['sem_tree'])) {
foreach ($course['sem_tree'] as $tree) { foreach ($course['sem_tree'] as $tree) {
$sem_tree_names[$tree['sem_tree_id']] = $tree['name']; $sem_tree_names[$tree['sem_tree_id']] = $tree['name'];
if (!isset($_tmp_courses[$sem_key][(string)$tree['sem_tree_id']])) {
$_tmp_courses[$sem_key][(string)$tree['sem_tree_id']] = [];
}
$_tmp_courses[$sem_key][(string)$tree['sem_tree_id']][$course['seminar_id']] = $course; $_tmp_courses[$sem_key][(string)$tree['sem_tree_id']][$course['seminar_id']] = $course;
} }
} else { } else {
$_tmp_courses[$sem_key][""][$course['seminar_id']] = $course; if (!isset($_tmp_courses[$sem_key][''])) {
$_tmp_courses[$sem_key][''] = [];
}
$_tmp_courses[$sem_key][''][$course['seminar_id']] = $course;
} }
} }
uksort($_tmp_courses[$sem_key], function ($a, $b) use ($sem_tree_names) { uksort($_tmp_courses[$sem_key], function ($a, $b) use ($sem_tree_names) {
...@@ -655,8 +668,7 @@ class MyRealmModel ...@@ -655,8 +668,7 @@ class MyRealmModel
'StudipSemTree', 'StudipSemTree',
['build_index' => true] ['build_index' => true]
); );
return (int)($the_tree->tree_data[$a]['index'] return (int)($the_tree->tree_data[$a]['index'] ?? 0 - $the_tree->tree_data[$b]['index'] ?? 0);
- $the_tree->tree_data[$b]['index']);
}); });
//At this point the $_tmp_courses array is sorted by the ordering //At this point the $_tmp_courses array is sorted by the ordering
//of the sem_tree. //of the sem_tree.
...@@ -664,9 +676,13 @@ class MyRealmModel ...@@ -664,9 +676,13 @@ class MyRealmModel
//of the $_tmp_courses array with the sem_tree names: //of the $_tmp_courses array with the sem_tree names:
foreach ($_tmp_courses[$sem_key] as $sem_tree_id => $courses) { foreach ($_tmp_courses[$sem_key] as $sem_tree_id => $courses) {
foreach ($courses as $course) { foreach ($courses as $course) {
$_tmp_courses[$sem_key][(string)$sem_tree_names[$sem_tree_id]][$course['seminar_id']] = $course; $index = (string)($sem_tree_names[$sem_tree_id] ?? '');
if (!isset($_tmp_courses[$sem_key][$index])) {
$_tmp_courses[$sem_key][$index] = [];
}
$_tmp_courses[$sem_key][$index][$course['seminar_id']] = $course;
} }
if ($sem_tree_names[$sem_tree_id]) { if (isset($sem_tree_names[$sem_tree_id])) {
unset($_tmp_courses[$sem_key][$sem_tree_id]); unset($_tmp_courses[$sem_key][$sem_tree_id]);
} }
} }
......
...@@ -127,7 +127,7 @@ class StudipStudyArea extends SimpleORMap ...@@ -127,7 +127,7 @@ class StudipStudyArea extends SimpleORMap
public function getName() public function getName()
{ {
if ($this->studip_object_id) { if ($this->studip_object_id) {
return $this->institute->name; return $this->institute ? $this->institute->name : _('Unbekannte Einrichtung');
} }
return $this->content['name']; return $this->content['name'];
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment