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( ...@@ -199,6 +199,7 @@ $string['progressbargenerictask'] = array(
1 => 'Add %d: %s' 1 => 'Add %d: %s'
); );
$string['profilecompletionforwhichinstitution'] = 'for'; $string['profilecompletionforwhichinstitution'] = 'for';
$string['noprogressitems'] = 'No profile completion items for this institution.';
// Online users sideblock strings // Online users sideblock strings
$string['onlineusers'] = 'Online users'; $string['onlineusers'] = 'Online users';
......
...@@ -2942,7 +2942,9 @@ function progressbar_sideblock($preview=false) { ...@@ -2942,7 +2942,9 @@ function progressbar_sideblock($preview=false) {
// Get all institutions where user is member // Get all institutions where user is member
$institutions = array(); $institutions = array();
foreach ($USER->institutions as $inst) { 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 user's first institution in case that institution isn't
// set yet or user is not member of currently set institution. // set yet or user is not member of currently set institution.
...@@ -2964,9 +2966,27 @@ function progressbar_sideblock($preview=false) { ...@@ -2964,9 +2966,27 @@ function progressbar_sideblock($preview=false) {
// by function param instead // by function param instead
$institution = param_alphanum('institution', $default[0]); $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 // 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) // Without locked ones (site locked and institution locked)
$sitelocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', 'mahara'); $sitelocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', 'mahara');
$instlocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution); $instlocked = (array) get_column('institution_locked_profile_field', 'profilefield', 'name', $institution);
...@@ -3106,7 +3126,20 @@ function progressbar_sideblock($preview=false) { ...@@ -3106,7 +3126,20 @@ function progressbar_sideblock($preview=false) {
'totalcounting' => $totalcounting, '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( return array(
'data' => null, 'data' => null,
'percent' => 0, 'percent' => 0,
......
...@@ -1560,7 +1560,7 @@ function load_user_institutions($userid) { ...@@ -1560,7 +1560,7 @@ function load_user_institutions($userid) {
throw new InvalidArgumentException("couldn't load institutions, no user id specified"); throw new InvalidArgumentException("couldn't load institutions, no user id specified");
} }
if ($institutions = get_records_sql_assoc(' 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 FROM {usr_institution} u INNER JOIN {institution} i ON u.institution = i.name
WHERE u.usr = ? ORDER BY i.priority DESC', array($userid))) { WHERE u.usr = ? ORDER BY i.priority DESC', array($userid))) {
return $institutions; return $institutions;
......
{if $sbdata.data || $sbdata.preview} {if $sbdata.data || $sbdata.preview || $sbdata.count > 1}
<div class="sidebar-header"> <div class="sidebar-header">
<h3>{if $sbdata.preview}{str tag="profilecompletenesspreview"}{else}{str tag="profilecompleteness"}{/if}</h3> <h3>{if $sbdata.preview}{str tag="profilecompletenesspreview"}{else}{str tag="profilecompleteness"}{/if}</h3>
{if $sbdata.count > 1} {if $sbdata.count > 1}
...@@ -22,9 +22,10 @@ ...@@ -22,9 +22,10 @@
</tr> </tr>
</tbody></table> </tbody></table>
</form> </form>
<!--<label for="123">{str tag=forinstitution}&nbsp;</label>-->
{/if} {/if}
</div> </div>
{/if}
{if $sbdata.data || $sbdata.preview}
<div class="sidebar-content"> <div class="sidebar-content">
<div id="progressbarwrap"> <div id="progressbarwrap">
{if $sbdata.percent < 100} {if $sbdata.percent < 100}
...@@ -54,4 +55,8 @@ ...@@ -54,4 +55,8 @@
{/if} {/if}
</div> </div>
</div> </div>
{else}
{if $sbdata.totalcounting == 0 && $sbdata.count > 1}
<div class="sidebar-content">{str tag="noprogressitems"}</div>
{/if}
{/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