From 3b662756549d66e549571ccbedbd997a1e73a884 Mon Sep 17 00:00:00 2001
From: Moritz Strohm <strohm@data-quest.de>
Date: Wed, 2 May 2018 16:26:06 +0200
Subject: [PATCH] made plugin navigation path configurable, fixes #6
---
TandemPlugin.class.php | 27 ++++++++---
controllers/admin.php | 48 +++++++++++++------
migrations/03_add_role.php | 27 ++++-------
...nfig_tandemplugin_use_tools_navigation.php | 37 ++++++++++++++
views/admin/config.php | 22 ++++++++-
5 files changed, 120 insertions(+), 41 deletions(-)
create mode 100644 migrations/06_add_config_tandemplugin_use_tools_navigation.php
diff --git a/TandemPlugin.class.php b/TandemPlugin.class.php
index e5cc1a4..bfac88e 100644
--- a/TandemPlugin.class.php
+++ b/TandemPlugin.class.php
@@ -95,12 +95,20 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin
PluginEngine::getURL('tandemplugin/admin/pairs')
);
- $top_navigation = clone $navigation;
- $top_navigation->setImage(
- Icon::create("roles", "navigation")
- );
- Navigation::addItem("/tandemplugin", $top_navigation);
-
+ $top_navigation = null;
+ $navigation_name = 'admin';
+ if (Config::get()->TANDEMPLUGIN_USE_TOOLS_NAVIGATION) {
+ if (Navigation::hasItem('/tools')) {
+ $top_navigation = Navigation::getItem('/tools');
+ $navigation_name = 'tandemplugin';
+ }
+ } else {
+ $top_navigation = clone $navigation;
+ $top_navigation->setImage(
+ Icon::create("roles", "navigation")
+ );
+ Navigation::addItem("/tandemplugin", $top_navigation);
+ }
$sub_navigation = new Navigation(
dgettext('TandemPlugin', 'Etablierte Tandems'),
@@ -138,7 +146,12 @@ class TandemPlugin extends StudIPPlugin implements SystemPlugin, PortalPlugin
);
$navigation->addSubNavigation('config', $sub_navigation);
- $top_navigation->addSubNavigation('admin', $navigation);
+ if ($top_navigation) {
+ $top_navigation->addSubNavigation(
+ $navigation_name,
+ $navigation
+ );
+ }
}
}
diff --git a/controllers/admin.php b/controllers/admin.php
index 4e38679..63c5e01 100644
--- a/controllers/admin.php
+++ b/controllers/admin.php
@@ -30,6 +30,11 @@ class AdminController extends PluginController
if(!RolePersistence::isAssignedRole(User::findCurrent()->id, 'TandemAdmin') and !$perm->have_perm('root')) {
throw new AccessDeniedException();
}
+
+ $this->admin_nav_path = '/tandemplugin/admin';
+ if (Config::get()->TANDEMPLUGIN_USE_TOOLS_NAVIGATION) {
+ $this->admin_nav_path = '/tools/tandemplugin';
+ }
}
@@ -61,18 +66,16 @@ class AdminController extends PluginController
}
if($this->status == -1) {
- if(Navigation::hasItem('/tandemplugin/admin/rejected')) {
- Navigation::activateItem('/tandemplugin/admin/rejected');
+ if(Navigation::hasItem($this->admin_nav_path . '/rejected')) {
+ Navigation::activateItem($this->admin_nav_path . '/rejected');
}
-
} elseif($this->status == 0) {
- if(Navigation::hasItem('/tandemplugin/admin/requested')) {
- Navigation::activateItem('/tandemplugin/admin/requested');
+ if(Navigation::hasItem($this->admin_nav_path . '/requested')) {
+ Navigation::activateItem($this->admin_nav_path . '/requested');
}
-
} elseif($this->status == 1) {
- if(Navigation::hasItem('/tandemplugin/admin/established')) {
- Navigation::activateItem('/tandemplugin/admin/established');
+ if(Navigation::hasItem($this->admin_nav_path . '/established')) {
+ Navigation::activateItem($this->admin_nav_path . '/established');
}
}
@@ -236,8 +239,8 @@ class AdminController extends PluginController
$sidebar->addWidget($actions);
- if(Navigation::hasItem('/tandemplugin/admin/terminated')) {
- Navigation::activateItem('/tandemplugin/admin/terminated');
+ if(Navigation::hasItem($this->admin_nav_path . '/terminated')) {
+ Navigation::activateItem($this->admin_nav_path . '/terminated');
}
$this->terminated_pairs = [];
@@ -324,8 +327,8 @@ class AdminController extends PluginController
public function search_action()
{
- if(Navigation::hasItem('/tandemplugin/admin/search')) {
- Navigation::activateItem('/tandemplugin/admin/search');
+ if(Navigation::hasItem($this->admin_nav_path . '/search')) {
+ Navigation::activateItem($this->admin_nav_path . '/search');
}
$this->age_of_request = 0;
@@ -487,8 +490,8 @@ class AdminController extends PluginController
public function config_action()
{
- if(Navigation::hasItem('/tandemplugin/admin/config')) {
- Navigation::activateItem('/tandemplugin/admin/config');
+ if(Navigation::hasItem($this->admin_nav_path . '/config')) {
+ Navigation::activateItem($this->admin_nav_path . '/config');
}
if(Navigation::hasItem('/profile/tandem_administration/config')) {
@@ -502,6 +505,7 @@ class AdminController extends PluginController
$this->gender_search_enabled = (bool)Request::get('gender_search_enabled', false);
$this->delete_old_period = (int)Request::int('delete_old_period', 6);
$this->proof_fields_enabled = (bool)Request::get('proof_fields_enabled', false);
+ $this->use_tools_navigation = Request::int('use_tools_navigation', 0);
if(($this->delete_old_period < 1) or ($this->delete_old_period > 24)) {
PageLayout::postError(
@@ -530,10 +534,20 @@ class AdminController extends PluginController
$delete_old_period->store();
}
+ $config->store(
+ 'TANDEMPLUGIN_USE_TOOLS_NAVIGATION',
+ (int)$this->use_tools_navigation
+ );
+
PageLayout::postSuccess(
dgettext('TandemPlugin', 'Die Konfiguration wurde gespeichert!')
);
+ //Reload page to avoid POST requests in browser history
+ //and to avoid the obsolet navigation path to be shown,
+ //if the navigation path for the tandem administration
+ //has been changed.
+ $this->redirect('admin/config');
} else {
$this->proof_fields_enabled = (bool)
($config->TANDEMPLUGIN_PROOF_FIELDS_ENABLED ?
@@ -546,6 +560,12 @@ class AdminController extends PluginController
$this->delete_old_period = (int)
($config->TANDEMPLUGIN_DELETE_OLD_PERIOD ?
$config->TANDEMPLUGIN_DELETE_OLD_PERIOD : 6);
+
+ $this->use_tools_navigation = (int) (
+ $config->TANDEMPLUGIN_USE_TOOLS_NAVIGATION
+ ? $config->TANDEMPLUGIN_USE_TOOLS_NAVIGATION
+ : 0
+ );
}
}
}
diff --git a/migrations/03_add_role.php b/migrations/03_add_role.php
index 9b5cc82..71cffc5 100644
--- a/migrations/03_add_role.php
+++ b/migrations/03_add_role.php
@@ -11,35 +11,24 @@
* @author Moritz Strohm <strohm@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Plugin
-**/
+ **/
class AddRole extends Migration
{
-
-
-
public function up()
{
- $db = DBManager::get();
-
//Create TandemAdmin role:
-
- $db->exec(
- "INSERT INTO roles (rolename, system)
- VALUES ('TandemAdmin', 'n');"
- );
-
- //close DB connection:
- $db = null;
-
+ $role = new Role();
+ $role->rolename = 'TandemAdmin';
+ RolePersistence::saveRole($role);
}
-
-
+
+
public function down()
{
//Get and delete TandemAdmin role:
-
+
$roles = RolePersistence::getAllRoles();
foreach($roles as $role) {
@@ -49,6 +38,6 @@ class AddRole extends Migration
break;
}
}
-
+
}
}
diff --git a/migrations/06_add_config_tandemplugin_use_tools_navigation.php b/migrations/06_add_config_tandemplugin_use_tools_navigation.php
new file mode 100644
index 0000000..221c8e0
--- /dev/null
+++ b/migrations/06_add_config_tandemplugin_use_tools_navigation.php
@@ -0,0 +1,37 @@
+<?php
+
+/**
+ * This file is part of the TandemPlugin for Stud.IP
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * @author Elmar Ludwig <elmar.ludwig@uos.de>
+ * @author Moritz Strohm <strohm@data-quest.de>
+ * @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
+ * @category Plugin
+ */
+
+
+class AddConfigTandempluginUseToolsNavigation extends Migration
+{
+ public function up()
+ {
+ Config::get()->create(
+ 'TANDEMPLUGIN_USE_TOOLS_NAVIGATION',
+ [
+ 'type' => 'boolean',
+ 'value' => 0,
+ 'section' => 'tandemplugin',
+ 'description' => 'Soll die Tandem-Verwaltung unter dem Navigationpunkt "Tools" angezeigt werden (true) oder nicht (false)?'
+ ]
+ );
+ }
+
+ public function down()
+ {
+ Config::get()->delete('TANDEMPLUGIN_USE_TOOLS_NAVIGATION');
+ }
+}
diff --git a/views/admin/config.php b/views/admin/config.php
index 7747d47..f49b16a 100644
--- a/views/admin/config.php
+++ b/views/admin/config.php
@@ -65,10 +65,30 @@
value="1">
</label>
</fieldset>
+ <fieldset>
+ <legend>
+ <?= dgettext('TandemPlugin', 'Anzeige der Tandem-Verwaltung') ?>
+ </legend>
+ <p>
+ <?= dgettext(
+ 'TandemPlugin',
+ 'Die Verwaltung der Tandem-Funktionen kann entweder als eigener Punkt in der Hauptnavigation angezeigt werden (Voreinstellung) oder als Reiter im Bereich "Tools".'
+ ) ?>
+ </p>
+ <label>
+ <?= dgettext(
+ 'TandemPlugin',
+ 'Tandem-Verwaltung im Bereich "Tools" anzeigen'
+ ) ?>
+ <input type="checkbox" name="use_tools_navigation"
+ <?= $use_tools_navigation ? 'checked="checked"' : '' ?>
+ value="1">
+ </label>
+ </fieldset>
<div>
<?= \Studip\Button::create(
dgettext('TandemPlugin', 'Speichern'),
'save'
- ) ?>
+ ) ?>
</div>
</form>
--
GitLab