diff --git a/TandemPlugin.class.php b/TandemPlugin.class.php index e5cc1a467916722cf1617227b2f50cdf4307cd5d..bfac88e043de94530f4d5ee7e275fc33f862b639 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 4e386799fe38e55fb479b3b3ef844a75611ff7a0..63c5e015a6897ff8e04550d5505e2e377f9a6937 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 9b5cc82a8287b0c964c27077bf0d02c691fefa55..71cffc5ea7e60a977ff6cb3e5f5ecd788ff75f78 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 0000000000000000000000000000000000000000..221c8e080a37966b48c12a6ff800e8375334924f --- /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 7747d47605028b12ce179ddfa0ed966859d00824..f49b16ac34431bd05d20672c522fa0f61a3dcdd2 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>