fixing roles support for backup/restore

This commit is contained in:
toyomoyo 2006-10-04 09:01:50 +00:00
parent e0539647aa
commit c0c98c7c78
2 changed files with 33 additions and 29 deletions

View file

@ -422,7 +422,7 @@ $xml_file = $CFG->dataroot."/temp/backup/".$backup_unique_code."/moodle.xml";
$info = restore_read_xml_info($xml_file);
$siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course_header->course_id), "shortname");
$siterolesarray = get_assignable_roles (get_context_instance(CONTEXT_COURSE, $course->id), "shortname");
echo ('<table width="100%" class="restore-form-instances">');
echo ('<tr><td align="right"><b>'.get_string('sourcerole').'</b></td><td align="left"><b>'.get_string('targetrole').'</b></td></tr>');
@ -432,19 +432,19 @@ if ($info->backup_moodle_version < 2006092801) {
/// Editting teacher
echo ('<tr><td align="right">');
print_string('teacheredit');
print_string('defaultcourseteacher');
echo ('</td><td algin="left">');
// get the first teacheredit legacy
$roles = get_roles_with_capability('moodle/legacy:editingteacher', CAP_ALLOW, get_context_instance(CONTEXT_SYSTEM, SITEID));
$editteacher = array_shift($roles);
choose_from_menu ($siterolesarray, "defaultteacheredit", $editteacher->id);
echo ('</td></tr>');
/// Non-editting teacher
echo ('<tr><td align="right">');
print_string('teacher');
print_string('noneditingteacher');
echo ('</td><td algin="left">');
// get the first teacheredit legacy
@ -457,7 +457,7 @@ if ($info->backup_moodle_version < 2006092801) {
/// Student
echo ('<tr><td align="right">');
print_string('student');
print_string('defaultcoursestudent');
echo ('</td><td algin="left">');
// get the first teacheredit legacy
@ -469,25 +469,26 @@ if ($info->backup_moodle_version < 2006092801) {
} else {
// 1.7 and above backup
$roles = restore_read_xml_roles($xml_file);
if (is_array($roles)) { // possible to have course with no roles
foreach ($roles->roles as $roleid=>$role) {
echo ('<tr><td align="right">');
echo $role->shortname;
echo ('</td><td align="left">');
foreach ($roles->roles as $roleid=>$role) {
echo ('<tr><td align="right">');
echo $role->shortname;
echo ('</td><td align="left">');
// see if any short name match
$matchrole = 0;
foreach ($siterolesarray as $siteroleid=>$siteroleshortname) {
if ($siteroleshortname == $role->shortname) {
$matchrole = $siteroleid;
break;
}
// see if any short name match
$matchrole = 0;
foreach ($siterolesarray as $siteroleid=>$siteroleshortname) {
if ($siteroleshortname == $role->shortname) {
$matchrole = $siteroleid;
break;
}
}
choose_from_menu ($siterolesarray, "roles_".$roleid, $matchrole, 'new role', '', '0');
echo ('</td></tr>');
}
choose_from_menu ($siterolesarray, "roles_".$roleid, $matchrole, 'new role', '', '0');
echo ('</td></tr>');
}
} // end else