MDL-19163 restore - enable course selection for teachers having perms in more than 1 course ; merged from 19_STABLE

This commit is contained in:
stronk7 2009-05-12 14:57:40 +00:00
parent d4e15ca389
commit 94ba4c9eb8

View file

@ -1,4 +1,5 @@
<?php //$Id$
//This page receive all the restore_form data. Then, if existing course
//has been selected, shows a list of courses to select one.
//It cheks that the parammeter from restore_form are coherent.
@ -208,23 +209,48 @@
print_error("siteisnotdefined", 'debug');
}
// Non-cached - get accessinfo
if (isset($USER->access)) {
$accessinfo = $USER->access;
} else {
$accessinfo = get_user_access_sitewide($USER->id);
}
// Get all the courses the user is able to restore to
$mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true, 'c.sortorder ASC', array('id', 'fullname', 'shortname', 'visible'));
// Calculate if the user can create courses
$cancreatecourses = user_can_create_courses();
//Depending the selected restoreto:
// If user is a teacher (and not creator) or we are restoring from within SITEID:
// A) If user has 'moodle/site:restore' in more than one course and cannot create courses and he isn't restoring from SITEID:
// 0-Existing course, deleting: Select the destination course and launch the check again, then
// put $restore->course_id and $restore->deleting (true), create the restore object.
// 1-Existing course, adding: Select the destination course and launch the check again, then
// put $restore->course_id and $restore->deleting (false), create the restore object.
// B) Else, if user cannot create courses or he is restoring from within SITEID:
// 0-Current course, deleting: Put $restore->course_id and $restore->deleting (true), create the restore object
// 1-Current course, adding: Put $restore->course_id and $restore->deleting (false), create the restore object
// If the uses is a creator:
// C) If the user is a creator:
// 0-Existing course, deleting: Select the destination course and launch the check again, then
// put $restore->course_id and $restore->deleting (true), create the restore object.
// 1-Existing course, adding: Select the destination course and launch the check again, then
// put $restore->course_id and $restore->deleting (false), create the restore object.
// 2-New course: Create the restore object and launch the execute.
// NOTE: SITEID is prevented as a source for restoring because it's public area and we must encourage admins
// to avoid using it as a "repository" for courses storage.
//If the user is a teacher and not a creator or we are restoring from within SITEID
$cancreatecourses = user_can_create_courses();
if (!$cancreatecourses || $id == SITEID) {
$restore->course_id = $id;
// A) If user has 'moodle/site:restore' in more than one course, cannot create courses and he isn't restoring from SITEID
if (count($mycourses) > 1 && !$cancreatecourses && $id != SITEID) {
/// Nothing to do, process continues and C) will show the list of courses
// B) Else, if the user is a teacher and not a creator or we are restoring from within SITEID
} else if (!$cancreatecourses || $id == SITEID) {
$restore->course_id = $id; /// Force restore to current course, disabling pick course from list
}
// C) Arrived here, we have preprocessed all the changes needed by A) and B). Continue with the process
//Set restore->deleting as needed
if ($restore->restoreto == 0) {
$restore->deleting = true;
@ -232,16 +258,7 @@
$restore->deleting = false;
}
// Non-cached - get accessinfo
if (isset($USER->access)) {
$accessinfo = $USER->access;
} else {
$accessinfo = get_user_access_sitewide($USER->id);
}
$mycourses = get_user_courses_bycap($USER->id, 'moodle/site:restore', $accessinfo, true, 'c.sortorder ASC', array('id', 'fullname', 'shortname', 'visible'));
//Now, select the course if needed
//if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) and get_capability_courses('moodle/site:restore')) {
if (($restore->restoreto == 0 or $restore->restoreto == 1) and ($restore->course_id == 0) && count($mycourses) > 1) {
if ($courses = $mycourses) {