aboutsummaryrefslogtreecommitdiff
path: root/lib/classes/ResponsiveHelper.php
diff options
context:
space:
mode:
authorThomas Hackl <hackl@data-quest.de>2022-12-12 15:20:27 +0000
committerDavid Siegfried <david.siegfried@uni-vechta.de>2022-12-12 15:20:27 +0000
commit936d1c00ea05bb0a5c56f441ff2eece6ccefada6 (patch)
tree10c4b9a4a1d02780112f7ddc99f9a88b37a1ad20 /lib/classes/ResponsiveHelper.php
parent54dbf11a35cac0de6fed1c50114c9583d210a40e (diff)
Resolve "StEP00348: Responsive Navigation Stud.IP 5.x"
Closes #32 Merge request studip/studip!65
Diffstat (limited to 'lib/classes/ResponsiveHelper.php')
-rw-r--r--lib/classes/ResponsiveHelper.php173
1 files changed, 155 insertions, 18 deletions
diff --git a/lib/classes/ResponsiveHelper.php b/lib/classes/ResponsiveHelper.php
index eb7f41c..c2b201e 100644
--- a/lib/classes/ResponsiveHelper.php
+++ b/lib/classes/ResponsiveHelper.php
@@ -24,27 +24,54 @@ class ResponsiveHelper
$link_params = array_fill_keys(array_keys(URLHelper::getLinkParams()), null);
foreach (Navigation::getItem('/')->getSubNavigation() as $path => $nav) {
- if (!$nav->isVisible(true)) {
- continue;
+ $image = $nav->getImage();
+
+ $forceVisibility = false;
+ /*
+ * Special treatment for "browse" navigation which is normally hidden
+ * when we are inside a course.
+ */
+ if ($path === 'browse' && !$image) {
+ $image = Icon::create('seminar');
+ $forceVisibility = true;
+ }
+ /*
+ * Special treatment for "footer" navigation because
+ * the real footer is hidden in responsive view.
+ */
+ if ($path === 'footer' && !$image) {
+ $image = Icon::create('info');
+ $nav->setTitle(_('Impressum & Information'));
+ $forceVisibility = true;
}
- $image = $nav->getImage();
$image_src = $image ? $image->copyWithRole('info_alt')->asImagePath() : false;
$item = [
- 'icon' => $image_src ? self::getAssetsURL($image_src) : false,
- 'title' => (string) $nav->getTitle(),
- 'url' => self::getURL($nav->getURL(), $link_params),
+ 'icon' => $image_src ? self::getAssetsURL($image_src) : false,
+ 'title' => (string) $nav->getTitle(),
+ 'url' => URLHelper::getURL($nav->getURL(), $link_params, true),
+ 'parent' => '/',
+ 'path' => $path,
+ 'visible' => $forceVisibility ? true : $nav->isVisible(true),
+ 'active' => $nav->isActive()
];
if ($nav->isActive()) {
- $activated[] = $path;
+ // course navigation is integrated in course sub-navigation items
+ if ($path === 'course') {
+ $activated[] = 'browse/my_courses/' . (Context::get()->getId());
+ } else {
+ $activated[] = $path;
+ }
}
- if ($nav->getSubnavigation() && $path != 'start') {
+ if ($nav->getSubnavigation() && $path != 'start') {
$item['children'] = self::getChildren($nav, $path, $activated);
}
- $navigation[$path] = $item;
+ if ($path !== 'course') {
+ $navigation[$path] = $item;
+ }
}
return [$navigation, $activated];
@@ -54,35 +81,50 @@ class ResponsiveHelper
* Recursively build a navigation array from the subnavigation/children
* of a navigation object.
*
- * @param Navigation $navigation The navigation object
- * @param String $path Current path segment
- * @param array $activated Activated items
+ * @param Navigation $navigation The navigation object
+ * @param String $path Current path segment
+ * @param array $activated Activated items
+ * @param String|null $cid Optional context ID
* @return Array containing the children (+ grandchildren...)
*/
- protected static function getChildren(Navigation $navigation, $path, &$activated = [])
+ protected static function getChildren(Navigation $navigation, $path, &$activated = [], string $cid = null)
{
$children = [];
foreach ($navigation->getSubNavigation() as $subpath => $subnav) {
- if (!$subnav->isVisible()) {
+ /*if (!$subnav->isVisible()) {
continue;
- }
+ }*/
+ $originalSubpath = $subpath;
$subpath = "{$path}/{$subpath}";
$item = [
- 'title' => (string) $subnav->getTitle(),
- 'url' => self::getURL($subnav->getURL()),
+ 'title' => (string) $subnav->getTitle(),
+ 'url' => URLHelper::getURL($subnav->getURL(), $cid ? ['cid' => $cid] : []),
+ 'parent' => $path,
+ 'path' => $subpath,
+ 'visible' => $subnav->isVisible(),
+ 'active' => $subnav->isActive()
];
if ($subnav->isActive()) {
- $activated[] = $subpath;
+ // course navigation is integrated in course sub-navigation items
+ if ($path === 'course') {
+ $activated[] = 'browse/my_courses/' . Context::get()->getId() . '/' . $originalSubpath;
+ } else {
+ $activated[] = $subpath;
+ }
}
if ($subnav->getSubNavigation()) {
$item['children'] = self::getChildren($subnav, $subpath);
}
+ if ($subpath === 'browse/my_courses') {
+ $item['children'] = array_merge($item['children'] ?? [], static::getMyCoursesNavigation($activated));
+ }
+
$children[$subpath] = $item;
}
@@ -113,4 +155,99 @@ class ResponsiveHelper
{
return str_replace($GLOBALS['ASSETS_URL'], '', $url);
}
+
+ /**
+ * Specialty for responsive navigation: build navigation items
+ * for my courses in current semester.
+ *
+ * @return array
+ */
+ protected static function getMyCoursesNavigation($activated): array
+ {
+ if (!$GLOBALS['perm']->have_perm('admin')) {
+ $sem_data = Semester::getAllAsArray();
+
+ $currentIndex = -1;
+
+ foreach ($sem_data as $index => $semester) {
+ if ($semester['current']) {
+ $currentIndex = $index;
+ break;
+ }
+ }
+
+ $params = [
+ 'deputies_enabled' => Config::get()->DEPUTIES_ENABLE
+ ];
+
+ $courses = MyRealmModel::getCourses($currentIndex, $currentIndex, $params);
+ } else {
+ $courses = [];
+ }
+
+ $items = [];
+
+ $standardIcon = Icon::create('seminar', Icon::ROLE_INFO_ALT)->asImagePath();
+
+ // Add current course to list.
+ if (Context::get() && Context::isCourse()) {
+ $courses[] = Context::get();
+ }
+
+ foreach ($courses as $course) {
+ $avatar = CourseAvatar::getAvatar($course->id);
+ if ($avatar->is_customized()) {
+ $icon = $avatar->getURL(Avatar::SMALL);
+ } else {
+ $icon = $standardIcon;
+ }
+
+ $cnav = [
+ 'icon' => $icon,
+ 'title' => $course->getFullname(),
+ 'url' => URLHelper::getURL('dispatch.php/course/details', ['cid' => $course->id]),
+ 'parent' => 'browse/my_courses',
+ 'path' => 'browse/my_courses/' . $course->id,
+ 'visible' => true,
+ 'active' => Course::findCurrent() ? Course::findCurrent()->id === $course->id : false,
+ 'children' => []
+ ];
+
+ foreach ($course->tools as $tool) {
+ if (Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $course->id)) {
+
+ $path = 'browse/my_courses/' . $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')) {
+ $cnav['children'][$path . '/' . $nav_name] = [
+ 'icon' => $navigation->getImage() ? $navigation->getImage()->asImagePath() : '',
+ 'title' => $tool->getDisplayname(),
+ '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
+ ),
+ ];
+ }
+ }
+ }
+ }
+ }
+
+ $items['browse/my_courses/' . $course->id] = $cnav;
+
+ }
+
+ return $items;
+ }
}