Commit fd5dc8fa authored by Maria Sorica's avatar Maria Sorica Committed by Robert Lyon
Browse files

Bug 1722861: Add the institution tags page

1. If a visible institution enables the
institution tags, a "Tags" link will appear
under the Institutions menu.

2. The link will take the user to the
institution tags page.

Change-Id: I29b2777c34253ebf57d0a3bd294081b7727cdc9b
parent 8858f497
......@@ -836,8 +836,6 @@ function institution_submit(Pieform $form, $values) {
$newinstitution = new Institution($institution);
$newinstitution->displayname = $values['displayname'];
$oldinstitution = get_record('institution', 'name', $institution);
// Clear out any cached menus for this institution
clear_menu_cache($institution);
}
$newinstitution->showonlineusers = !isset($values['showonlineusers']) ? 2 : $values['showonlineusers'];
......@@ -1173,7 +1171,8 @@ function institution_submit(Pieform $form, $values) {
$SESSION->add_ok_msg($message);
$nexturl = '/admin/users/institutions.php';
}
// Clear out any cached menus for this institution
clear_menu_cache();
redirect($nexturl);
}
......
<?php
/**
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
define('INTERNAL', 1);
define('INSTITUTIONALADMIN', 1);
define('SECTION_PLUGINTYPE', 'core');
define('SECTION_PLUGINNAME', 'admin');
define('MENUITEM', 'manageinstitutions/institutiontags');
require(dirname(dirname(dirname(__FILE__))) . '/init.php');
require_once(get_config('libroot') . 'institution.php');
$institution = param_alphanum('institution', false);
// Get all the institutions that the current user has access to.
$institutionelement = get_institution_selector(true, false, false, false, false, true);
if (!$institutionelement || empty($institutionelement['options'])) {
throw new AccessDeniedException(get_string('cantlistinstitutioncollections', 'collection'));
}
if (!$institution || !$USER->can_edit_institution($institution, true)) {
$institution = empty($institutionelement['value']) ? $institutionelement['defaultvalue'] : $institutionelement['value'];
}
else if (!empty($institution)) {
$institutionelement['defaultvalue'] = $institution;
}
define('TITLE', get_string('institutiontags'));
$institutionselector = pieform(array(
'name' => 'usertypeselect',
'class' => 'form-inline',
'elements' => array(
'institution' => $institutionelement,
)
));
// The institution drop-down selector if applicable.
$wwwroot = get_config('wwwroot');
$js = <<< EOF
function reloadTags() {
window.location.href = '{$wwwroot}admin/users/institutiontags.php?institution='+$('#usertypeselect_institution').val();
}
$(document).ready(function() {
$('#usertypeselect_institution').on('change', reloadTags);
});
EOF;
$smarty = smarty(array('paginator'));
setpageicon($smarty, 'icon-university');
$smarty->assign('institutionselector', $institutionselector);
$smarty->assign('INLINEJAVASCRIPT', $js);
$smarty->display('admin/users/institutiontags.tpl');
......@@ -217,6 +217,8 @@ $string['resultsperpage'] = 'Results per page';
// Institution tags
$string['allowinstitutiontags'] = 'Allow institution tags';
$string['allowinstitutiontagsdescription'] = 'Administrators can define a set of tags that institution members can use.';
$string['institutiontags'] = 'Institution tags';
$string['institutiontagsdescription'] = 'The institution tags are predefined by the institution and available for use by all institution members. You can create as many tags as you like.';
// License metadata
$string['license'] = 'License';
......
......@@ -911,10 +911,12 @@ class Institution {
* @param bool $includesitestaff To allow site staff to see dropdown like the site admin would
* @param bool $includeinstitutionstaff To allow institution staff to see dropdown like institution admin would
* @param bool $allselector To add an 'all' option to the dropdown where it makes sense, eg in institution statistics page
* @param bool $withactiveinstitutiontags To only fetch institutions which are configured to define their own tags
*
* @return null or array suitable for pieform element
*/
function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false, $allselector=false) {
function get_institution_selector($includedefault = true, $assumesiteadmin=false, $includesitestaff=false, $includeinstitutionstaff=false,
$allselector=false, $withactiveinstitutiontags=false) {
global $USER;
if (($assumesiteadmin || $USER->get('admin')) || ($includesitestaff && $USER->get('staff'))) {
......@@ -960,8 +962,17 @@ function get_institution_selector($includedefault = true, $assumesiteadmin=false
if ($allselector) {
$options['all'] = get_string('Allinstitutions', 'mahara');
}
foreach ($institutions as $i) {
$options[$i->name] = $i->displayname;
if ($withactiveinstitutiontags) {
foreach ($institutions as $i) {
if ($i->tags) {
$options[$i->name] = $i->displayname;
}
}
}
else {
foreach ($institutions as $i) {
$options[$i->name] = $i->displayname;
}
}
$institution = key($options);
$institutionelement = array(
......
......@@ -2564,6 +2564,16 @@ function admin_nav() {
);
}
// Add the menu items for tags, if that feature is enabled in a visible institution.
if (($selector = get_institution_selector(false, false, false, false, false, true)) && !empty($selector['options'])) {
$menu['manageinstitutions/institutiontags'] = array(
'path' => 'manageinstitutions/tags',
'url' => 'admin/users/institutiontags.php',
'title' => get_string('tags'),
'weight' => 95
);
}
// enable plugins to augment the admin menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
......@@ -2741,6 +2751,16 @@ function institutional_admin_nav() {
),
);
// Add the menu items for tags, if that feature is enabled in a visible institution.
if (($selector = get_institution_selector(false, false, false, false, false, true)) && !empty($selector['options'])) {
$ret['manageinstitutions/institutiontags'] = array(
'path' => 'manageinstitutions/tags',
'url' => 'admin/users/institutiontags.php',
'title' => get_string('tags'),
'weight' => 95
);
}
// enable plugins to augment the institution admin menu structure
foreach (array('artefact', 'interaction', 'module', 'auth') as $plugintype) {
if ($plugins = plugins_installed($plugintype)) {
......
{include file="header.tpl"}
<p class="lead view-description">{str tag=institutiontagsdescription}</p>
{include file="footer.tpl"}
\ No newline at end of file
......@@ -36,7 +36,13 @@ Scenario: Creating an institution (selenium test)
And I attach the file "Image2.png" to "Logo"
And I press "Submit"
# Checking that institution tags is available
And I choose "Tags" in "Institutions" from administration menu
And I should see "Institution tags"
# Delete the institution
And I choose "Settings" in "Institutions" from administration menu
And I click on "Delete" in "Institution One" row
And I press "Yes"
Then I should see "Institution deleted successfully"
And I should not see "Tags" in the "Institutions sub-menu" property
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment