From b46ece81acf8d7e265ee4ce7937840fce14fd454 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Noack?= <noack@data-quest.de> Date: Fri, 10 Dec 2021 13:59:14 +0000 Subject: [PATCH] Resolve "Sichtbarkeit von Werkzeugen wirkt sich nur auf den Reiter aus" --- app/controllers/public_courses.php | 110 ++++++++++++++++++----------- app/views/public_courses/index.php | 4 +- lib/classes/MyRealmModel.php | 18 +++-- lib/models/ToolActivation.php | 2 +- 4 files changed, 83 insertions(+), 51 deletions(-) diff --git a/app/controllers/public_courses.php b/app/controllers/public_courses.php index 726b303ed7c..e32a8539206 100644 --- a/app/controllers/public_courses.php +++ b/app/controllers/public_courses.php @@ -59,28 +59,9 @@ class PublicCoursesController extends AuthenticatedController $seminars = $statement->fetchGrouped(PDO::FETCH_ASSOC); $seminars = $this->get_seminar_navigations($seminars); - $seminars = $this->get_plugin_navigations($seminars); - $this->seminars = $seminars; } - /** - * Loads all possible standard plugins for the given seminars and adds - * a navigation entry for each one. - * - * @param array $seminars List of seminars - * @return array Extended list of seminars - */ - protected function get_plugin_navigations($seminars) - { - foreach ($seminars as $id => $seminar) { - foreach (PluginEngine::getPlugins('StandardPlugin', $id) as $plugin) { - $seminars[$id]['navigations'][] = $plugin->getIconNavigation($id, time(), $GLOBALS['user']->id); - } - } - return $seminars; - } - /** * Adds all navigation entries for each passed seminar. * @@ -95,11 +76,29 @@ class PublicCoursesController extends AuthenticatedController foreach ($seminars as $id => $seminar) { $seminar['navigations'] = []; - - foreach (words('forum files news scm schedule wiki vote') as $key) { - $seminar['navigations'][$key] = false; + $seminar['tools'] = new SimpleCollection(ToolActivation::findByrange_id($id)); + foreach (MyRealmModel::getDefaultModules() as $plugin_id => $plugin) { + + // Go to next module if current module is not available and not voting-module + if ($plugin !== 'vote' && !$seminar['tools']->findOneBy('plugin_id', $plugin_id)) { + $seminar['navigations'][get_class($plugin)] = null; + continue; + } + + if (!Config::get()->VOTE_ENABLE && $plugin_id === 'vote') { + continue; + } + + if ($plugin === 'vote') { + $seminar['navigations'][$plugin] = false; + } else if ($tool = $seminar['tools']->findOneBy('plugin_id', $plugin_id)) { + if ($tool->getVisibilityPermission() === 'nobody') { + $seminar['navigations'][get_class($plugin)] = false; + } else { + $seminar['navigations'][get_class($plugin)] = null; + } + } } - $seminars[$id] = $seminar; } @@ -115,9 +114,11 @@ class PublicCoursesController extends AuthenticatedController $statement = DBManager::get()->prepare($query); $statement->execute([$seminar_ids]); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { - $nav = new Navigation('files', 'dispatch.php/course/files/index'); - $nav->setImage(Icon::create('files', 'inactive', ["title" => sprintf(_('%s Dokumente'),$row['count'])])); - $seminars[$row['range_id']]['navigations']['files'] = $nav; + if (isset($seminars[$row['range_id']]['navigations']['CoreDocuments'])) { + $nav = new Navigation('files', 'dispatch.php/course/files/index'); + $nav->setImage(Icon::create('files', Icon::ROLE_CLICKABLE, ["title" => sprintf(_('%s Dokumente'), $row['count'])])); + $seminars[$row['range_id']]['navigations']['CoreDocuments'] = $nav; + } } // News @@ -130,9 +131,11 @@ class PublicCoursesController extends AuthenticatedController $statement = DBManager::get()->prepare($query); $statement->execute([$seminar_ids]); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { - $nav = new Navigation('news', ''); - $nav->setImage(Icon::create('news', 'inactive', ["title" => sprintf(_('%s Ankündigungen'),$row['count'])])); - $seminars[$row['range_id']]['navigations']['news'] = $nav; + if (isset($seminars[$row['range_id']]['navigations']['CoreOverview'])) { + $nav = new Navigation('news', ''); + $nav->setImage(Icon::create('news', Icon::ROLE_CLICKABLE, ["title" => sprintf(_('%s Ankündigungen'),$row['count'])])); + $seminars[$row['range_id']]['navigations']['CoreOverview'] = $nav; + } } // Information @@ -143,9 +146,11 @@ class PublicCoursesController extends AuthenticatedController $statement = DBManager::get()->prepare($query); $statement->execute([$seminar_ids]); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { - $nav = new Navigation('scm', 'dispatch.php/course/scm'); - $nav->setImage(Icon::create('infopage', 'inactive', ["title" => sprintf(_('%s Einträge'),$row['count'])])); - $seminars[$row['range_id']]['navigations']['scm'] = $nav; + if (isset($seminars[$row['range_id']]['navigations']['CoreScm'])) { + $nav = new Navigation('scm', 'dispatch.php/course/scm'); + $nav->setImage(Icon::create('infopage', Icon::ROLE_CLICKABLE, ["title" => sprintf(_('%s Einträge'), $row['count'])])); + $seminars[$row['range_id']]['navigations']['CoreScm'] = $nav; + } } // Appointments @@ -156,9 +161,11 @@ class PublicCoursesController extends AuthenticatedController $statement = DBManager::get()->prepare($query); $statement->execute([$seminar_ids]); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { - $nav = new Navigation('schedule', 'dispatch.php/course/dates'); - $nav->setImage(Icon::create('schedule', 'inactive', ["title" => sprintf(_('%s Termine'),$row['count'])])); - $seminars[$row['range_id']]['navigations']['schedule'] = $nav; + if (isset($seminars[$row['range_id']]['navigations']['CoreSchedule'])) { + $nav = new Navigation('schedule', 'dispatch.php/course/dates'); + $nav->setImage(Icon::create('schedule', Icon::ROLE_CLICKABLE, ["title" => sprintf(_('%s Termine'), $row['count'])])); + $seminars[$row['range_id']]['navigations']['CoreSchedule'] = $nav; + } } // Wiki @@ -170,9 +177,11 @@ class PublicCoursesController extends AuthenticatedController $statement = DBManager::get()->prepare($query); $statement->execute([$seminar_ids]); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { - $nav = new Navigation('wiki', 'wiki.php'); - $nav->setImage(Icon::create('wiki', 'inactive', ["title" => sprintf(_('%s WikiSeiten'),$row['count'])])); - $seminars[$row['range_id']]['navigations']['wiki'] = $nav; + if (isset($seminars[$row['range_id']]['navigations']['CoreWiki'])) { + $nav = new Navigation('wiki', 'wiki.php'); + $nav->setImage(Icon::create('wiki', Icon::ROLE_CLICKABLE, ["title" => sprintf(_('%s WikiSeiten'), $row['count'])])); + $seminars[$row['range_id']]['navigations']['CoreWiki'] = $nav; + } } } @@ -187,12 +196,31 @@ class PublicCoursesController extends AuthenticatedController $statement = DBManager::get()->prepare($query); $statement->execute([$seminar_ids]); while ($row = $statement->fetch(PDO::FETCH_ASSOC)) { - $nav = new Navigation('vote', '#vote'); - $nav->setImage(Icon::create('vote', 'inactive', ["title" => sprintf(_('%s Umfrage(n)'),$row['count'])])); - $seminars[$row['range_id']]['navigations']['vote'] = $nav; + if (isset($seminars[$row['range_id']]['navigations']['vote'])) { + $nav = new Navigation('vote', '#vote'); + $nav->setImage(Icon::create('vote', Icon::ROLE_CLICKABLE, ["title" => sprintf(_('%s Umfrage(n)'), $row['count'])])); + $seminars[$row['range_id']]['navigations']['vote'] = $nav; + } } } + foreach ($seminars as $id => $seminar) { + foreach ($seminar['tools'] as $tool) { + $module = $tool->getStudipModule(); + if (!$module || get_class($module) === 'CoreAdmin' || get_class($module) === 'CoreStudygroupAdmin') { + continue; + } + if (array_key_exists(get_class($module), $seminar['navigations'])) { + continue; + } + if ($tool->getVisibilityPermission() === 'nobody') { + $seminar['navigations'][get_class($module)] = $module->getIconNavigation($id, time(), 'nobody'); + } else { + $seminar['navigations'][get_class($module)] = null; + } + } + $seminars[$id] = $seminar; + } return $seminars; } } diff --git a/app/views/public_courses/index.php b/app/views/public_courses/index.php index 50543837179..7f74ea76c19 100644 --- a/app/views/public_courses/index.php +++ b/app/views/public_courses/index.php @@ -64,10 +64,10 @@ } ?> <a href="<?= URLHelper::getLink('seminar_main.php?auswahl='. $id . '&redirect_to=' . str_replace('?', '&', $navigation->getURL())) ?>"<?= $badge ?>> - <?= $navigation->getImageTag() ?> + <?= $navigation->getImage()->asImg(20, $navigation->getLinkAttributes()) ?> </a> <? else: ?> - <?= Assets::img('blank.gif', ['width' => 16, 'height' => 16]) ?> + <?= Assets::img('blank.gif', ['width' => 20, 'height' => 20]) ?> <? endif; ?> <? endforeach; ?> </td> diff --git a/lib/classes/MyRealmModel.php b/lib/classes/MyRealmModel.php index c832aecaca6..2dd81a42943 100644 --- a/lib/classes/MyRealmModel.php +++ b/lib/classes/MyRealmModel.php @@ -463,14 +463,14 @@ class MyRealmModel } if ($plugin === 'vote') { - $nav = self::checkVote($my_obj_values, $user_id, $object_id); + $navigation[$plugin_id] = self::checkVote($my_obj_values, $user_id, $object_id); } else if ($tool = $my_obj_values['tools']->findOneBy('plugin_id', $plugin_id)) { - $nav = $plugin->getIconNavigation($object_id, $visit_data[$plugin_id]['visitdate'], $user_id) ?: false; + if (Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $object_id, $user_id)) { + $navigation[$plugin_id] = $plugin->getIconNavigation($object_id, $visit_data[$plugin_id]['visitdate'], $user_id); + } else { + $navigation[$plugin_id] = null; + } } - - // add the main navigation item to resultset - $navigation[$plugin_id] = $nav ?: null; - unset($nav); } foreach ($my_obj_values['tools'] as $tool) { if (array_key_exists($tool->plugin_id, $navigation)) { @@ -480,7 +480,11 @@ class MyRealmModel if (!$module || get_class($module) === 'CoreAdmin' || get_class($module) === 'CoreStudygroupAdmin') { continue; } - $navigation[$tool->plugin_id] = $module->getIconNavigation($object_id, $visit_data[$tool->plugin_id]['visitdate'], $user_id); + if (Seminar_Perm::get()->have_studip_perm($tool->getVisibilityPermission(), $object_id, $user_id)) { + $navigation[$tool->plugin_id] = $module->getIconNavigation($object_id, $visit_data[$tool->plugin_id]['visitdate'], $user_id); + } else { + $navigation[$tool->plugin_id] = null; + } } return $navigation; } diff --git a/lib/models/ToolActivation.php b/lib/models/ToolActivation.php index 3da9b8dd51d..bcf40ecab4b 100644 --- a/lib/models/ToolActivation.php +++ b/lib/models/ToolActivation.php @@ -90,7 +90,7 @@ class ToolActivation extends SimpleORMap if ($this->metadata['visibility'] === 'tutor') { return 'tutor'; } else { - return 'user'; + return 'nobody'; } } -- GitLab