diff options
| author | Viktoria Wiebe <vwiebe@uni-osnabrueck.de> | 2022-11-21 15:28:19 +0000 |
|---|---|---|
| committer | Elmar Ludwig <elmar.ludwig@uni-osnabrueck.de> | 2022-11-21 15:28:19 +0000 |
| commit | c1b760e7b459dec48ff8f730c6bb89ebd05ef371 (patch) | |
| tree | 62e2f6336732bd83eaaa5666aa2a6374db83aa6a /app/controllers/my_courses.php | |
| parent | 470d57a844a9d52da3bdafe1266ae0239603458e (diff) | |
implementation of course overview portal widget, fixes #1080
Closes #1080
Merge request studip/studip!757
Diffstat (limited to 'app/controllers/my_courses.php')
| -rw-r--r-- | app/controllers/my_courses.php | 199 |
1 files changed, 114 insertions, 85 deletions
diff --git a/app/controllers/my_courses.php b/app/controllers/my_courses.php index e42b2c8..ee35616 100644 --- a/app/controllers/my_courses.php +++ b/app/controllers/my_courses.php @@ -81,8 +81,6 @@ class MyCoursesController extends AuthenticatedController PageLayout::setHelpKeyword('Basis.MeineVeranstaltungen'); PageLayout::setTitle(_('Meine Veranstaltungen')); - $this->sem_data = Semester::getAllAsArray(); - $sem_key = $this->getSemesterKey(); $group_field = $this->getGroupField(); @@ -115,89 +113,7 @@ class MyCoursesController extends AuthenticatedController } $this->setupSidebar($sem_key, $group_field, $this->check_for_new($sem_courses, $group_field)); - - $temp_courses = []; - $groups = []; - if (is_array($sem_courses)) { - foreach ($sem_courses as $_outer_index => $_outer) { - if ($group_field === 'sem_number') { - $_courses = []; - - foreach ($_outer as $course) { - $_courses[$course['seminar_id']] = $course; - if (!empty($course['children']) && is_array($course['children'])) { - foreach ($course['children'] as $child) { - $_courses[$child['seminar_id']] = $child; - } - } - } - - $groups[] = [ - 'id' => $_outer_index, - 'name' => (string)$this->sem_data[$_outer_index]['name'], - 'data' => [ - [ - 'id' => md5($_outer_index), - 'label' => false, - 'ids' => array_keys($_courses), - ], - ], - ]; - $temp_courses = array_merge($temp_courses, $_courses); - } else { - $count = 1; - $_groups = []; - foreach ($_outer as $_inner_index => $_inner) { - $_courses = []; - - foreach ($_inner as $course) { - $_courses[$course['seminar_id']] = $course; - if ($course['children']) { - foreach ($course['children'] as $child) { - $_courses[$child['seminar_id']] = $child; - } - } - } - - $label = $_inner_index; - if ($group_field === 'sem_tree_id' && !$label) { - $label = _('keine Zuordnung'); - } elseif ($group_field === 'gruppe') { - $label = _('Gruppe') . ' ' . $count++; - } - - $_groups[] = [ - 'id' => md5($_outer_index . $_inner_index), - 'label' => $label, - 'ids' => array_keys($_courses), - ]; - - $temp_courses = array_merge($temp_courses, $_courses); - } - - $groups[] = [ - 'id' => $_outer_index, - 'name' => (string)$this->sem_data[$_outer_index]['name'], - 'data' => $_groups, - ]; - } - } - } - - $data = [ - 'courses' => $this->sanitizeNavigations(array_map([$this, 'convertCourse'], $temp_courses)), - 'groups' => $groups, - 'user_id' => $GLOBALS['user']->id, - 'config' => [ - 'allow_dozent_visibility' => Config::get()->ALLOW_DOZENT_VISIBILITY, - 'open_groups' => array_values($GLOBALS['user']->cfg->MY_COURSES_OPEN_GROUPS), - 'sem_number' => Config::get()->IMPORTANT_SEMNUMBER, - 'display_type' => $GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY ? 'tiles' : 'tables', - 'responsive_type' => $GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY_RESPONSIVE ? 'tiles' : 'tables', - 'navigation_show_only_new' => $GLOBALS['user']->cfg->MY_COURSES_SHOW_NEW_ICONS_ONLY, - 'group_by' => $this->getGroupField(), - ], - ]; + $data = $this->getMyCoursesData($sem_courses, $group_field); PageLayout::addHeadElement( 'script', @@ -769,6 +685,119 @@ class MyCoursesController extends AuthenticatedController } /** + * Get the data array for presenting the course list in the portal widget. + */ + public function getPortalWidgetData() + { + $sem_key = $this->getSemesterKey(); + $group_field = $this->getGroupField(); + + $sem_courses = MyRealmModel::getPreparedCourses($sem_key, [ + 'group_field' => $group_field, + 'order_by' => null, + 'order' => 'asc', + 'studygroups_enabled' => Config::get()->MY_COURSES_ENABLE_STUDYGROUPS, + 'deputies_enabled' => Config::get()->DEPUTIES_ENABLE, + ]); + + return $this->getMyCoursesData($sem_courses, $group_field); + } + + /** + * Get the data array for presenting the course list in Vue. + * + * @param array $sem_courses + * @param string $group_field + */ + private function getMyCoursesData($sem_courses, $group_field) + { + $sem_data = Semester::getAllAsArray(); + $temp_courses = []; + $groups = []; + + if (is_array($sem_courses)) { + foreach ($sem_courses as $_outer_index => $_outer) { + if ($group_field === 'sem_number') { + $_courses = []; + + foreach ($_outer as $course) { + $_courses[$course['seminar_id']] = $course; + if (!empty($course['children']) && is_array($course['children'])) { + foreach ($course['children'] as $child) { + $_courses[$child['seminar_id']] = $child; + } + } + } + + $groups[] = [ + 'id' => $_outer_index, + 'name' => (string) $sem_data[$_outer_index]['name'], + 'data' => [ + [ + 'id' => md5($_outer_index), + 'label' => false, + 'ids' => array_keys($_courses), + ], + ], + ]; + $temp_courses = array_merge($temp_courses, $_courses); + } else { + $count = 1; + $_groups = []; + foreach ($_outer as $_inner_index => $_inner) { + $_courses = []; + + foreach ($_inner as $course) { + $_courses[$course['seminar_id']] = $course; + if ($course['children']) { + foreach ($course['children'] as $child) { + $_courses[$child['seminar_id']] = $child; + } + } + } + + $label = $_inner_index; + if ($group_field === 'sem_tree_id' && !$label) { + $label = _('keine Zuordnung'); + } elseif ($group_field === 'gruppe') { + $label = _('Gruppe') . ' ' . $count++; + } + + $_groups[] = [ + 'id' => md5($_outer_index . $_inner_index), + 'label' => $label, + 'ids' => array_keys($_courses), + ]; + + $temp_courses = array_merge($temp_courses, $_courses); + } + + $groups[] = [ + 'id' => $_outer_index, + 'name' => (string) $sem_data[$_outer_index]['name'], + 'data' => $_groups, + ]; + } + } + } + + return [ + 'courses' => $this->sanitizeNavigations(array_map([$this, 'convertCourse'], $temp_courses)), + 'groups' => $groups, + 'user_id' => $GLOBALS['user']->id, + 'config' => [ + 'allow_dozent_visibility' => Config::get()->ALLOW_DOZENT_VISIBILITY, + 'open_groups' => array_values($GLOBALS['user']->cfg->MY_COURSES_OPEN_GROUPS), + 'sem_number' => Config::get()->IMPORTANT_SEMNUMBER, + 'display_type' => $GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY ? 'tiles' : 'tables', + 'responsive_type' => $GLOBALS['user']->cfg->MY_COURSES_TILED_DISPLAY_RESPONSIVE ? 'tiles' : 'tables', + 'navigation_show_only_new' => $GLOBALS['user']->cfg->MY_COURSES_SHOW_NEW_ICONS_ONLY, + 'group_by' => $this->getGroupField(), + ], + ]; + } + + /** * Get widget for grouping selected courses (e.g. by colors, ...) * * @param string $group_field |
