Commit 87e031aa authored by Robert Lyon's avatar Robert Lyon
Browse files

User in multi institutions can lose progress bar (Bug #1347362)



If a user is in two (or more) institutions and the first institution has
profile progess set up for it and the other doesn't, the switching of
the select box makes the progress sideblock disappear.

This patch checks that if any institution the user belongs to has
profile progress then display the select box if they belong to two or
more institutions and show either the bar or a message mentioning this
intitution doesn't have progress.

To test:
- user with 1 institution that has progress
- user with 1 institution that has no progress
- user with 2 institution that both have progress
- user with 2 institution where one has progress
- user with 2 institution where none have progress

Change-Id: I4daca26b4b9cfef9faa73be34c34ad931d89465e
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
parent 67efc2dd
......@@ -199,6 +199,7 @@ $string['progressbargenerictask'] = array(
1 => 'Add %d: %s'
);
$string['profilecompletionforwhichinstitution'] = 'for';
$string['noprogressitems'] = 'No profile completion items for this institution.';
// Online users sideblock strings
$string['onlineusers'] = 'Online users';
......
......@@ -2942,7 +2942,9 @@ function progressbar_sideblock($preview=false) {
// Get all institutions where user is member
$institutions = array();
foreach ($USER->institutions as $inst) {
$institutions = array_merge($institutions, array($inst->institution => $inst->displayname));
if (empty($inst->suspended)) {
$institutions = array_merge($institutions, array($inst->institution => $inst->displayname));
}
}
// Set user's first institution in case that institution isn't
// set yet or user is not member of currently set institution.
......@@ -2964,9 +2966,27 @@ function progressbar_sideblock($preview=false) {
// by function param instead
$institution = param_alphanum('institution', $default[0]);
}
// We need to check to see if any of the institutions have profile completeness to allow
// the select box to work correctly for users with more than one institution
$multiinstitutionprogress = false;
$counting = null;
if (!empty($institutions)) {
foreach ($institutions as $key => $value) {
if ($result = get_records_select_assoc('institution_config', 'institution=? and field like \'progressbaritem_%\'', array($key), 'field', 'field, value')) {
$multiinstitutionprogress = true;
if ($key == $institution) {
$counting = $result;
break;
}
}
}
}
else {
$counting = get_records_select_assoc('institution_config', 'institution=? and field like \'progressbaritem_%\'', array($institution), 'field', 'field, value');
}
// Get artefacts that count towards profile completeness
if ($counting = get_records_select_assoc('institution_config', 'institution=? and field like \'progressbaritem_%\'', array($institution), 'field', 'field, value')) {
if ($counting) {
// Without locked ones (site locked and institution locked)
$sitelocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', 'mahara');
$instlocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
......@@ -3106,7 +3126,20 @@ function progressbar_sideblock($preview=false) {
'totalcounting' => $totalcounting,
);
}
else if ($multiinstitutionprogress) {
return array(
'data' => null,
'percent' => 0,
'preview' => $preview,
'count' => ($preview ? 1 : count($institutions)),
// This is important if user is member
// of more than one institution ...
'institutions' => $institutions,
'institution' => $institution,
'totalcompleted' => 0,
'totalcounting' => 0,
);
}
return array(
'data' => null,
'percent' => 0,
......
......@@ -1560,7 +1560,7 @@ function load_user_institutions($userid) {
throw new InvalidArgumentException("couldn't load institutions, no user id specified");
}
if ($institutions = get_records_sql_assoc('
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.displayname,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews, i.logo, i.style, i.licensemandatory, i.licensedefault, i.dropdownmenu, i.skins
SELECT u.institution,'.db_format_tsfield('ctime').','.db_format_tsfield('u.expiry', 'membership_expiry').',u.studentid,u.staff,u.admin,i.displayname,i.theme,i.registerallowed, i.showonlineusers,i.allowinstitutionpublicviews, i.logo, i.style, i.licensemandatory, i.licensedefault, i.dropdownmenu, i.skins, i.suspended
FROM {usr_institution} u INNER JOIN {institution} i ON u.institution = i.name
WHERE u.usr = ? ORDER BY i.priority DESC', array($userid))) {
return $institutions;
......
{if $sbdata.data || $sbdata.preview}
{if $sbdata.data || $sbdata.preview || $sbdata.count > 1}
<div class="sidebar-header">
<h3>{if $sbdata.preview}{str tag="profilecompletenesspreview"}{else}{str tag="profilecompleteness"}{/if}</h3>
{if $sbdata.count > 1}
......@@ -22,9 +22,10 @@
</tr>
</tbody></table>
</form>
<!--<label for="123">{str tag=forinstitution}&nbsp;</label>-->
{/if}
</div>
{/if}
{if $sbdata.data || $sbdata.preview}
<div class="sidebar-content">
<div id="progressbarwrap">
{if $sbdata.percent < 100}
......@@ -54,4 +55,8 @@
{/if}
</div>
</div>
{else}
{if $sbdata.totalcounting == 0 && $sbdata.count > 1}
<div class="sidebar-content">{str tag="noprogressitems"}</div>
{/if}
{/if}
Supports Markdown
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