Added a progress bar for the role assignments

This commit is contained in:
moodler 2006-09-29 06:19:47 +00:00
parent dcc6b7c483
commit 72da504606
2 changed files with 24 additions and 3 deletions

View File

@ -949,6 +949,18 @@ function moodle_install_roles() {
$dbtables = $db->MetaTables('TABLES');
/// Set up the progress bar
$usertables = array('user_admins', 'user_coursecreators', 'user_teachers', 'user_students');
$totalcount = $progresscount = 0;
foreach ($usertables as $usertable) {
if (in_array($CFG->prefix.$usertable, $dbtables)) {
$totalcount += count_records($usertable);
}
}
print_progress(0, $totalcount, 5, 1, 'Processing '.$totalcount.'role assignments');
/// Upgrade the admins.
/// Sort using id ASC, first one is primary admin.
@ -958,6 +970,8 @@ function moodle_install_roles() {
while (! $rs->EOF) {
$admin = $rs->FetchObj();
role_assign($adminrole, $admin->userid, 0, $systemcontext->id);
$progresscount++;
print_progress($progresscount, $totalcount, 5, 1, 'Processing '.$totalcount.'role assignments');
$rs->MoveNext();
}
}
@ -972,6 +986,8 @@ function moodle_install_roles() {
while (! $rs->EOF) {
$coursecreator = $rs->FetchObj();
role_assign($coursecreatorrole, $coursecreator->userid, 0, $systemcontext->id);
$progresscount++;
print_progress($progresscount, $totalcount, 5, 1, 'Processing '.$totalcount.'role assignments');
$rs->MoveNext();
}
}
@ -998,6 +1014,8 @@ function moodle_install_roles() {
} else {
role_assign($noneditteacherrole, $teacher->userid, 0, $coursecontext->id);
}
$progresscount++;
print_progress($progresscount, $totalcount, 5, 1, 'Processing '.$totalcount.'role assignments');
$rs->MoveNext();
}
@ -1021,6 +1039,8 @@ function moodle_install_roles() {
// assign the default student role
$coursecontext = get_context_instance(CONTEXT_COURSE, $student->course);
role_assign($studentrole, $student->userid, 0, $coursecontext->id);
$progresscount++;
print_progress($progresscount, $totalcount, 5, 1, 'Processing '.$totalcount.'role assignments');
$rs->MoveNext();
}
@ -1032,6 +1052,7 @@ function moodle_install_roles() {
if ($guestuser = get_record('user', 'username', 'guest')) {
role_assign($guestrole, $guestuser->id, 0, $systemcontext->id);
}
print_progress($totalcount, $totalcount, 5, 1, 'Processing '.$totalcount.'role assignments');
/// Insert the correct records for legacy roles

View File

@ -436,10 +436,10 @@ function print_progress($done, $total, $updatetime=5, $sleeptime=1, $donetext=''
$starttime = $lasttime = time();
$lasttime = $starttime - $updatetime;
echo '<table width="500" cellpadding="0" cellspacing="0" align="center"><tr><td width="500">';
echo '<div id="bar" style="border-style:solid;border-width:1px;width:500px;height:50px;">';
echo '<div id="slider" style="border-style:solid;border-width:1px;height:48px;width:10px;background-color:green;"></div>';
echo '<div id="bar'.$total.'" style="border-style:solid;border-width:1px;width:500px;height:50px;">';
echo '<div id="slider'.$total.'" style="border-style:solid;border-width:1px;height:48px;width:10px;background-color:green;"></div>';
echo '</div>';
echo '<div id="text" align="center" style="width:500px;"></div>';
echo '<div id="text'.$total.'" align="center" style="width:500px;"></div>';
echo '</td></tr></table>';
echo '</div>';
}