Commit 74e28344 authored by Gregor Anzelj's avatar Gregor Anzelj Committed by Robert Lyon

Bug 1658395: Show institution in group settings

behatnotneeded

Change-Id: I2e4e1da62f182484b20ebb044eee4dddc6efad95
parent 36f929a9
......@@ -69,6 +69,39 @@ function groupquotasform_submit(Pieform $form, $values) {
}
$institutionform = pieform(array(
'name' => 'institutionform',
'renderer' => 'div',
'elements' => array(
'groupid' => array(
'type' => 'hidden',
'value' => $group->id,
),
'institution' => array(
'type' => 'select',
'title' => get_string('institution'),
'defaultvalue' => $group->institution,
'collapseifoneoption' => true,
'options' => get_institutions_to_associate(),
),
'submit' => array(
'type' => 'submit',
'class' => 'btn-primary',
'value' => get_string('save'),
)
),
));
function institutionform_submit(Pieform $form, $values) {
global $SESSION;
update_record('group', array('institution' => $values['institution']), array('id' => $values['groupid']));
$SESSION->add_ok_msg(get_string('groupassigned', 'group'));
redirect(get_config('wwwroot').'admin/groups/groups.php');
}
$admins = get_column_sql(
"SELECT gm.member FROM {group_member} gm WHERE gm.role = 'admin' AND gm.group = ?", array($group->id)
);
......@@ -131,6 +164,7 @@ $smarty = smarty();
setpageicon($smarty, 'icon-users');
$smarty->assign('quotasform', $quotasform);
$smarty->assign('institutionform', $institutionform);
$smarty->assign('groupname', $group->name);
$smarty->assign('managegroupform', $groupadminsform);
$smarty->display('admin/groups/manage.tpl');
......@@ -49,6 +49,7 @@ else {
'id' => null,
'name' => null,
'description' => null,
'institution' => 'mahara',
'grouptype' => 'standard',
'open' => 1,
'controlled' => 0,
......@@ -85,6 +86,13 @@ $form = array(
'defaultvalue' => $group_data->name,
),
'shortname' => group_get_shortname_element($group_data),
'institution' => array(
'type' => 'select',
'title' => get_string('assigntoinstitution', 'group'),
'defaultvalue' => $group_data->institution,
'collapseifoneoption' => true,
'options' => get_institutions_to_associate(),
),
'description' => array(
'type' => 'wysiwyg',
'title' => get_string('groupdescription', 'group'),
......@@ -487,9 +495,12 @@ function editgroup_submit(Pieform $form, $values) {
$values['public'] = (isset($values['public'])) ? $values['public'] : 0;
$values['usersautoadded'] = (isset($values['usersautoadded'])) ? $values['usersautoadded'] : 0;
$allowedinstitutions = get_institutions_to_associate();
$institution = isset($allowedinstitutions[$values['institution']]) ? $values['institution'] : 'mahara';
$newvalues = array(
'name' => $group_data->name == $values['name'] ? $values['name'] : trim($values['name']),
'institution' => $institution,
'description' => $values['description'],
'grouptype' => $values['grouptype'],
'category' => empty($values['category']) ? null : intval($values['category']),
......
......@@ -14,6 +14,9 @@ defined('INTERNAL') || die();
// my groups
$string['groupname'] = 'Group name';
$string['groupshortname'] = 'Short name';
$string['assigntoinstitution'] = 'Assign to institution';
$string['assigntoaninstitution'] = 'Assign group \'%s\' to an institution';
$string['groupassigned'] = 'Group assigned to institution successfully';
$string['creategroup'] = 'Create group';
$string['copygroup'] = 'Copy group "%s"';
$string['groupmemberrequests'] = 'Pending membership requests';
......
......@@ -599,9 +599,6 @@ function group_update($new, $create=false) {
$new->allowarchives = 0;
}
// Institution cannot be updated (yet)
unset($new->institution);
$update_blog_access = ($new->editroles != $old->editroles);
foreach (array('id', 'grouptype', 'public', 'request', 'submittableto', 'allowarchives', 'editroles',
......@@ -1780,7 +1777,7 @@ function build_grouplist_html($query, $limit, $offset, &$count=null, $institutio
$group->displayname = $group->name;
$group->submitpages = $group->submittableto;
$group->roles = $group->grouptype;
$group->institutionname = get_field('institution', 'displayname', 'name', $group->institution);
switch ($group->jointype) {
case 'open':
$group->open = 1;
......
......@@ -5244,3 +5244,41 @@ function create_elasticsearch_triggers() {
}
}
}
/**
* Return a list of available institution(s) to associate to a group.
*
* This list is based on user's institution memberships.
* If the user is admin then all institutions are returned.
*
*/
function get_institutions_to_associate() {
global $USER;
$institutions = array();
if (is_array($USER->institutions) && count($USER->institutions) > 0) {
// Get all institutions where user is member
foreach ($USER->institutions as $inst) {
if (empty($inst->suspended)) {
$institutions = array_merge($institutions, array($inst->institution => $inst->displayname));
}
}
}
else if ($USER->get('admin')) {
// Get all institutions since user is admin
$records = get_records_array('institution');
foreach ($records as $inst) {
if (empty($inst->suspended)) {
$institutions = array_merge($institutions, array($inst->name => $inst->displayname));
}
}
}
else {
$institutions = array(
'mahara' => get_field('institution', 'displayname', 'name', 'mahara')
);
}
return $institutions;
}
......@@ -263,8 +263,9 @@ table.table tr {
// Specific width for group table.
.table>thead>tr>th.groupname,
.table>thead>tr>th.groupshortname {
width: 20%;
.table>thead>tr>th.groupshortname,
.table>thead>tr>th.groupmanagebuttons {
width: 15%;
}
.table.profile-info {
......
......@@ -14,7 +14,8 @@
<th>{str tag="groupcategory" section="group"}</th>
{/if}
<th>{str tag="groupvisible" section="admin"}</th>
<th><span class="accessible-hidden sr-only">{str tag=edit}</span></th>
<th>{str tag="institution"}</th>
<th class="groupmanagebuttons"><span class="accessible-hidden sr-only">{str tag=edit}</span></th>
</tr>
</thead>
<tbody>
......
......@@ -13,6 +13,7 @@
<td>{$group->categorytitle}</td>
{/if}
<td>{$group->visibility}</td>
<td>{$group->institutionname}</td>
<td class="right">
<div class="btn-group">
<a class="btn btn-default btn-sm" title="{str tag="groupmanage" section="admin"}" href="{$WWWROOT}admin/groups/manage.php?id={$group->id}">
......
{include file="header.tpl"}
<div class="panel panel-default">
<h2 class="panel-heading">{str tag=assigntoaninstitution section=group args=$groupname}</h2>
<div class="panel-body">
{$institutionform|safe}
</div>
</div>
<div class="panel panel-default">
<h2 class="panel-heading">{str tag=groupquotas section=admin args=$groupname}</h2>
<div class="panel-body">
......
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