diff --git a/lib/classes/ResponsiveHelper.php b/lib/classes/ResponsiveHelper.php index 3e29db394905337f43b8ffb15c2397ebd0d140cd..f02ee8063086c6c60ffda6f6a82ba2307dd57ad7 100644 --- a/lib/classes/ResponsiveHelper.php +++ b/lib/classes/ResponsiveHelper.php @@ -210,30 +210,29 @@ class ResponsiveHelper $courses = []; } - $items = []; - - $standardIcon = Icon::create('seminar', Icon::ROLE_INFO_ALT)->asImagePath(); - // Add current course to list. if (Context::get()) { $courses[] = Context::get(); } - foreach ($courses as $course) { + if (Context::isInstitute()) { + $avatarClass = InstituteAvatar::class; + $url = 'dispatch.php/institute/overview'; + $standardIcon = Icon::create('institute', Icon::ROLE_INFO_ALT)->asImagePath(); + } else { $avatarClass = CourseAvatar::class; $url = 'dispatch.php/course/details'; - if (Context::isInstitute()) { - $avatarClass = InstituteAvatar::class; - $url = 'dispatch.php/institute/overview'; - $standardIcon = Icon::create('institute', Icon::ROLE_INFO_ALT)->asImagePath(); - } + $standardIcon = Icon::create('seminar', Icon::ROLE_INFO_ALT)->asImagePath(); + } + $items = []; + foreach ($courses as $course) { $avatar = $avatarClass::getAvatar($course->id); $hasAvatar = $avatar->is_customized(); $icon = $hasAvatar ? $avatar->getURL(Avatar::SMALL) : $standardIcon; - $cnav = [ + $items['browse/my_courses/' . $course->id] = [ 'icon' => $icon, 'avatar' => $hasAvatar, 'title' => $course->getFullName(), @@ -242,60 +241,60 @@ class ResponsiveHelper 'path' => 'browse/my_courses/' . $course->id, 'visible' => true, 'active' => Context::getId() === $course->id, - 'children' => [] + 'children' => self::getRangeNavigation( + $course, + 'browse/my_courses/' . $course->id, + $activated + ), ]; - $path = 'browse/my_courses/' . $course->id; - - foreach ($course->tools as $tool) { - if (Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $course->id)) { - - $studip_module = $tool->getStudipModule(); - if ($studip_module instanceof StudipModule) { - $tool_nav = $studip_module->getTabNavigation($course->id) ?: []; - foreach ($tool_nav as $nav_name => $navigation) { - if ($nav_name && is_a($navigation, 'Navigation')) { - if (!empty($tool->metadata['displayname'])) { - $navigation->setTitle($tool->getDisplayname()); - } - $cnav['children'][$path . '/' . $nav_name] = [ - 'icon' => $navigation->getImage() ? $navigation->getImage()->asImagePath() : '', - 'title' => $navigation->getTitle(), - 'url' => URLHelper::getURL($navigation->getURL(), ['cid' => $course->id]), - 'parent' => 'browse/my_courses/' . $course->id, - 'path' => 'browse/my_courses/' . $course->id . '/' . $nav_name, - 'visible' => true, - 'active' => $navigation->isActive(), - 'children' => static::getChildren( - $navigation, - 'browse/my_courses/' . $course->id . '/' . $nav_name, - $activated, - $course->id - ), - ]; - } - } - } - } - } + } - if ($GLOBALS['perm']->have_studip_perm('tutor', $course->id)) { - $cnav['children'][$path . '/plus'] = [ - 'icon' => Icon::create('add', Icon::ROLE_INFO_ALT)->asImagePath(), - 'title' => _('Mehr...'), - 'url' => URLHelper::getURL('dispatch.php/course/plus/index', ['cid' => $course->id]), - 'parent' => 'browse/my_courses/' . $course->id, - 'path' => 'browse/my_courses/' . $course->id . '/plus/index', - 'visible' => true, - 'active' => false, - 'children' => [], - ]; - } + return $items; + } + + private static function getRangeNavigation(Range $range, string $path_prefix, array &$activated): array + { + if ($range->id === Context::getId()) { + $navigation = Navigation::getItem('/course'); + } else { + $navigation = new CourseNavigation($range); + } - $items['browse/my_courses/' . $course->id] = $cnav; + $result = []; + foreach ($navigation as $nav_name => $nav) { + $result[$path_prefix . '/' . $nav_name] = [ + 'icon' => $nav->getImage() ? $nav->getImage()->asImagePath() : '', + 'title' => $nav->getTitle(), + 'url' => URLHelper::getURL($nav->getURL(), ['cid' => $range->id]), + 'parent' => 'browse/my_courses/' . $range->id, + 'path' => 'browse/my_courses/' . $range->id . '/' . $nav_name, + 'visible' => true, + 'active' => $nav->isActive(), + 'children' => static::getChildren( + $nav, + 'browse/my_courses/' . $range->id . '/' . $nav_name, + $activated, + $range->id + ), + ]; } - return $items; + // Move admin page to the end + if (count($result) > 0) { + $first_path = array_keys($result)[0]; + if (str_ends_with($first_path, '/admin')) { + $admin_navigation = array_slice(array_values($result), 0, 1)[0]; + $admin_navigation['title'] = _('Verwaltung'); + $admin_navigation['icon'] = Icon::create('add', Icon::ROLE_INFO_ALT)->asImagePath(); + $result = array_merge( + array_slice($result, 1), + [$path_prefix . '/admin' => $admin_navigation] + ); + } + } + + return $result; } } diff --git a/lib/navigation/CourseNavigation.php b/lib/navigation/CourseNavigation.php index 6e37cf589327b7922d155c04083c762efbb00a6d..a22b89edf4e9f543a8338c78d04274ed4c0fbd93 100644 --- a/lib/navigation/CourseNavigation.php +++ b/lib/navigation/CourseNavigation.php @@ -15,15 +15,23 @@ class CourseNavigation extends Navigation { + private $range; + /** * Initialize a new Navigation instance. */ - public function __construct() + public function __construct(Range $range) { - global $user, $perm; + if (!($range instanceof Course) && !($range instanceof Institute)) { + throw new InvalidArgumentException('Invalid range type "' . get_class($range) . '" for course navigation'); + } + + $this->range = $range; + + global $user; // check if logged in - if (is_object($user) && $user->id != 'nobody') { + if (User::findCurrent()) { $coursetext = _('Veranstaltungen'); $courseinfo = _('Meine Veranstaltungen & Einrichtungen'); $courselink = 'dispatch.php/my_courses'; @@ -35,8 +43,8 @@ class CourseNavigation extends Navigation parent::__construct($coursetext, $courselink); - if (is_object($user)) { - $this->setImage(Icon::create('seminar', 'navigation', ["title" => $courseinfo])); + if (User::findCurrent()) { + $this->setImage(Icon::create('seminar', Icon::ROLE_NAVIGATION, ['title' => $courseinfo])); } } @@ -48,21 +56,19 @@ class CourseNavigation extends Navigation { parent::initSubNavigation(); - $context = Context::get(); - if (!$context) { - return; - } - $admin_plugin_ids = []; - $core_admin = PluginManager::getInstance()->getPlugin('CoreAdmin'); + + $core_admin = PluginManager::getInstance()->getPlugin(CoreAdmin::class); if ($core_admin) { $admin_plugin_ids[] = $core_admin->getPluginId(); } - $core_studygroup_admin = PluginManager::getInstance()->getPlugin('CoreStudygroupAdmin'); + + $core_studygroup_admin = PluginManager::getInstance()->getPlugin(CoreStudygroupAdmin::class); if ($core_studygroup_admin) { $admin_plugin_ids[] = $core_studygroup_admin->getPluginId(); } - $tools = $context->tools->getArrayCopy(); + + $tools = $this->range->tools->getArrayCopy(); usort($tools, function ($a, $b) use ($admin_plugin_ids) { if (in_array($a['plugin_id'], $admin_plugin_ids)) { return -1; @@ -72,22 +78,32 @@ class CourseNavigation extends Navigation } return $a['position'] - $b['position']; }); + foreach ($tools as $tool) { - if (Context::isInstitute() || Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $context->id)) { - $studip_module = $tool->getStudipModule(); - if ($studip_module instanceof StudipModule) { - $tool_nav = $studip_module->getTabNavigation($context->id) ?: []; - foreach ($tool_nav as $nav_name => $navigation) { - if ($nav_name && is_a($navigation, "Navigation")) { - if ($tool->metadata['displayname']) { - $navigation->setTitle($tool->getDisplayname()); - } - $this->addSubNavigation($nav_name, $navigation); - } - } + if ( + !($this->range instanceof Institute) + && !Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $this->range->id) + ) { + continue; + } + + $studip_module = $tool->getStudipModule(); + if (!($studip_module instanceof StudipModule)) { + continue; + } + + $tool_nav = $studip_module->getTabNavigation($this->range->id) ?: []; + + foreach ($tool_nav as $nav_name => $navigation) { + if (!$nav_name || !$navigation instanceof Navigation) { + continue; + } + + if ($tool->metadata['displayname']) { + $navigation->setTitle($tool->getDisplayname()); } + $this->addSubNavigation($nav_name, $navigation); } } } - } diff --git a/lib/navigation/StudipNavigation.php b/lib/navigation/StudipNavigation.php index 4a611537377924f1a75b6a4c4c660ee56cda689b..bc3fae9d9be8a907fadabd91b976a9ca4aba3e13 100644 --- a/lib/navigation/StudipNavigation.php +++ b/lib/navigation/StudipNavigation.php @@ -40,7 +40,7 @@ class StudipNavigation extends Navigation // if a course is selected, the navigation for it will be loaded if (Context::getId()) { - $this->addSubNavigation('course', new CourseNavigation()); + $this->addSubNavigation('course', new CourseNavigation(Context::get())); } try {