mirror of
https://github.com/moodle/moodle.git
synced 2025-03-14 20:50:21 +01:00
Merge branch 'wip-MDL-59262-master-2' of git://github.com/marinaglancy/moodle
This commit is contained in:
commit
25a425d709
@ -95,7 +95,7 @@ class tool_uploadcourse_course {
|
||||
/** @var array fields allowed as course data. */
|
||||
static protected $validfields = array('fullname', 'shortname', 'idnumber', 'category', 'visible', 'startdate', 'enddate',
|
||||
'summary', 'format', 'theme', 'lang', 'newsitems', 'showgrades', 'showreports', 'legacyfiles', 'maxbytes',
|
||||
'groupmode', 'groupmodeforce', 'groupmodeforce', 'enablecompletion');
|
||||
'groupmode', 'groupmodeforce', 'enablecompletion');
|
||||
|
||||
/** @var array fields required on course creation. */
|
||||
static protected $mandatoryfields = array('fullname', 'category');
|
||||
@ -676,6 +676,17 @@ class tool_uploadcourse_course {
|
||||
return false;
|
||||
}
|
||||
|
||||
// TODO MDL-59259 allow to set course format options for the current course format.
|
||||
|
||||
// Special case, 'numsections' is not a course format option any more but still should apply 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 {
|
||||
$coursedata['numsections'] = get_config('moodlecourse', 'numsections');
|
||||
}
|
||||
}
|
||||
|
||||
// Saving data.
|
||||
$this->data = $coursedata;
|
||||
$this->enrolmentdata = tool_uploadcourse_helper::get_enrolment_data($this->rawdata);
|
||||
|
@ -120,6 +120,36 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
|
||||
$this->assertTrue($DB->record_exists('course', array('shortname' => 'c2')));
|
||||
}
|
||||
|
||||
public function test_create_with_sections() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
$updatemode = tool_uploadcourse_processor::UPDATE_NOTHING;
|
||||
$defaultnumsections = get_config('moodlecourse', 'numsections');
|
||||
|
||||
// Add new course, make sure default number of sections is created.
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
||||
$data = array('shortname' => 'newcourse1', 'fullname' => 'New course1', 'format' => 'topics', 'category' => 1);
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->assertTrue($co->prepare());
|
||||
$co->proceed();
|
||||
$courseid = $DB->get_field('course', 'id', array('shortname' => 'newcourse1'));
|
||||
$this->assertNotEmpty($courseid);
|
||||
$this->assertEquals($defaultnumsections + 1,
|
||||
$DB->count_records('course_sections', ['course' => $courseid]));
|
||||
|
||||
// Add new course specifying number of sections.
|
||||
$mode = tool_uploadcourse_processor::MODE_CREATE_NEW;
|
||||
$data = array('shortname' => 'newcourse2', 'fullname' => 'New course2', 'format' => 'topics', 'category' => 1,
|
||||
'numsections' => 15);
|
||||
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
|
||||
$this->assertTrue($co->prepare());
|
||||
$co->proceed();
|
||||
$courseid = $DB->get_field('course', 'id', array('shortname' => 'newcourse2'));
|
||||
$this->assertNotEmpty($courseid);
|
||||
$this->assertEquals(15 + 1,
|
||||
$DB->count_records('course_sections', ['course' => $courseid]));
|
||||
}
|
||||
|
||||
public function test_delete() {
|
||||
global $DB;
|
||||
$this->resetAfterTest(true);
|
||||
|
@ -2942,6 +2942,7 @@ class course_request {
|
||||
$data->visibleold = $data->visible;
|
||||
$data->lang = $courseconfig->lang;
|
||||
$data->enablecompletion = $courseconfig->enablecompletion;
|
||||
$data->numsections = $courseconfig->numsections;
|
||||
|
||||
$course = create_course($data);
|
||||
$context = context_course::instance($course->id, MUST_EXIST);
|
||||
|
Loading…
x
Reference in New Issue
Block a user