aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJan-Hendrik Willms <tleilax+studip@gmail.com>2024-04-29 18:04:09 +0000
committerJan-Hendrik Willms <tleilax+studip@gmail.com>2024-04-29 18:04:09 +0000
commit01bf94bcc6369b7e7812f6727a52b189728dbe77 (patch)
treed278512d7936071f2958b160edc30a1553c1b487 /lib
parent6d93659a93446ed620d5c620a6e0dee2c51781b3 (diff)
fixes #4076
Closes #4076 Merge request studip/studip!2919
Diffstat (limited to 'lib')
-rw-r--r--lib/classes/ResponsiveHelper.php117
-rw-r--r--lib/navigation/CourseNavigation.php68
-rw-r--r--lib/navigation/StudipNavigation.php2
3 files changed, 101 insertions, 86 deletions
diff --git a/lib/classes/ResponsiveHelper.php b/lib/classes/ResponsiveHelper.php
index 3e29db3..f02ee80 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 6e37cf5..a22b89e 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 4a61153..bc3fae9 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 {