Commit d31efef9 authored by Robert Lyon's avatar Robert Lyon Committed by Gerrit Code Review
Browse files

Merge "User in multi institutions can lose progress bar (Bug #1347362)" into 1.9_STABLE

parents ebbdd966 87e031aa
......@@ -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,8 +2942,10 @@ function progressbar_sideblock($preview=false) {
// Get all institutions where user is member
$institutions = array();
foreach ($USER->institutions as $inst) {
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.
if (!$institution || !array_key_exists($institution, $institutions)) {
......@@ -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