mirror of
https://github.com/moodle/moodle.git
synced 2025-04-13 04:22:07 +02:00
Merge branch 'MDL-63268-master' of https://github.com/lucaboesch/moodle
This commit is contained in:
commit
45a8249431
@ -703,10 +703,18 @@ class tool_uploadcourse_course {
|
||||
$coursedata += $courseformat->validate_course_format_options($this->rawdata);
|
||||
}
|
||||
|
||||
// Special case, 'numsections' is not a course format option any more but still should apply from defaults.
|
||||
// Special case, 'numsections' is not a course format option any more but still should apply from the template course,
|
||||
// if any, and otherwise from defaults.
|
||||
if (!$exists || !array_key_exists('numsections', $coursedata)) {
|
||||
if (isset($this->rawdata['numsections']) && is_numeric($this->rawdata['numsections'])) {
|
||||
$coursedata['numsections'] = (int)$this->rawdata['numsections'];
|
||||
} else if (isset($this->options['templatecourse'])) {
|
||||
$numsections = tool_uploadcourse_helper::get_coursesection_count($this->options['templatecourse']);
|
||||
if ($numsections != 0) {
|
||||
$coursedata['numsections'] = $numsections;
|
||||
} else {
|
||||
$coursedata['numsections'] = get_config('moodlecourse', 'numsections');
|
||||
}
|
||||
} else {
|
||||
$coursedata['numsections'] = get_config('moodlecourse', 'numsections');
|
||||
}
|
||||
|
@ -286,6 +286,25 @@ class tool_uploadcourse_helper {
|
||||
return $roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper to detect how many sections a course with a given shortname has.
|
||||
*
|
||||
* @param string $shortname shortname of a course to count sections from.
|
||||
* @return integer count of sections.
|
||||
*/
|
||||
public static function get_coursesection_count($shortname) {
|
||||
global $DB;
|
||||
if (!empty($shortname) || is_numeric($shortname)) {
|
||||
// Creating restore from an existing course.
|
||||
$course = $DB->get_record('course', array('shortname' => $shortname));
|
||||
}
|
||||
if (!empty($course)) {
|
||||
$courseformat = course_get_format($course);
|
||||
return $courseformat->get_last_section_number();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the role renaming data from the passed data.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user