diff --git a/admin/tool/uploadcourse/classes/course.php b/admin/tool/uploadcourse/classes/course.php index 6600bf0b1be9a..d6887015f9b28 100644 --- a/admin/tool/uploadcourse/classes/course.php +++ b/admin/tool/uploadcourse/classes/course.php @@ -101,9 +101,9 @@ class tool_uploadcourse_course { protected $updatemode; /** @var array fields allowed as course data. */ - static protected $validfields = array('fullname', 'shortname', 'idnumber', 'category', 'visible', 'startdate', 'enddate', + static protected $validfields = ['fullname', 'shortname', 'idnumber', 'category', 'visible', 'startdate', 'enddate', 'summary', 'format', 'theme', 'lang', 'newsitems', 'showgrades', 'showreports', 'legacyfiles', 'maxbytes', - 'groupmode', 'groupmodeforce', 'enablecompletion', 'downloadcontent', 'showactivitydates'); + 'groupmode', 'groupmodeforce', 'enablecompletion', 'downloadcontent', 'showactivitydates', 'relativedatesmode']; /** @var array fields required on course creation. */ static protected $mandatoryfields = array('fullname', 'category'); diff --git a/admin/tool/uploadcourse/classes/tracker.php b/admin/tool/uploadcourse/classes/tracker.php index 860c84cc5d87d..f81a788d43138 100644 --- a/admin/tool/uploadcourse/classes/tracker.php +++ b/admin/tool/uploadcourse/classes/tracker.php @@ -52,7 +52,7 @@ class tool_uploadcourse_tracker { /** * @var array columns to display. */ - protected $columns = array('line', 'result', 'id', 'shortname', 'fullname', 'idnumber', 'status'); + protected $columns = ['line', 'result', 'id', 'shortname', 'fullname', 'idnumber', 'relativedatesmode', 'status']; /** * @var int row number. @@ -154,7 +154,8 @@ public function output($line, $outcome, $status, $data) { isset($data['id']) ? $data['id'] : '', isset($data['shortname']) ? $data['shortname'] : '', isset($data['fullname']) ? $data['fullname'] : '', - isset($data['idnumber']) ? $data['idnumber'] : '' + isset($data['idnumber']) ? $data['idnumber'] : '', + isset($data['relativedatesmode']) ? $data['relativedatesmode'] : '', ); $this->buffer->output(implode("\t", $message)); if (!empty($status)) { @@ -183,6 +184,10 @@ public function output($line, $outcome, $status, $data) { echo html_writer::tag('td', isset($data['shortname']) ? s($data['shortname']) : '', array('class' => 'c' . $ci++)); echo html_writer::tag('td', isset($data['fullname']) ? s($data['fullname']) : '', array('class' => 'c' . $ci++)); echo html_writer::tag('td', isset($data['idnumber']) ? s($data['idnumber']) : '', array('class' => 'c' . $ci++)); + echo html_writer::tag('td', + isset($data['relativedatesmode']) ? s($data['relativedatesmode']) : '', + ['class' => 'c' . $ci++] + ); echo html_writer::tag('td', $status, array('class' => 'c' . $ci++)); echo html_writer::end_tag('tr'); } @@ -215,6 +220,7 @@ public function start() { echo html_writer::tag('th', get_string('shortname'), array('class' => 'c' . $ci++, 'scope' => 'col')); echo html_writer::tag('th', get_string('fullname'), array('class' => 'c' . $ci++, 'scope' => 'col')); echo html_writer::tag('th', get_string('idnumber'), array('class' => 'c' . $ci++, 'scope' => 'col')); + echo html_writer::tag('th', get_string('relativedatesmode'), array('class' => 'c' . $ci++, 'scope' => 'col')); echo html_writer::tag('th', get_string('status'), array('class' => 'c' . $ci++, 'scope' => 'col')); echo html_writer::end_tag('tr'); } diff --git a/admin/tool/uploadcourse/tests/course_test.php b/admin/tool/uploadcourse/tests/course_test.php index e5fc520504ed4..678f3447303b8 100644 --- a/admin/tool/uploadcourse/tests/course_test.php +++ b/admin/tool/uploadcourse/tests/course_test.php @@ -352,6 +352,30 @@ public function test_create_with_sections(): void { $DB->count_records('course_sections', ['course' => $courseid])); } + /** + * Test that the course is created with the correct relativedatesmode. + * + * @return void + * @covers \tool_uploadcourse_course::prepare + */ + public function test_create_with_relativedatesmode(): void { + global $DB; + $this->initialise_test(); + set_config('enablecourserelativedates', 1); + $updatemode = tool_uploadcourse_processor::UPDATE_NOTHING; + + // Add new course, make sure default number of sections is created. + $mode = tool_uploadcourse_processor::MODE_CREATE_NEW; + $data = ['shortname' => 'newcourse1', 'fullname' => 'New course1', 'format' => 'topics', 'category' => 1, + 'relativedatesmode' => 1]; + $co = new tool_uploadcourse_course($mode, $updatemode, $data); + $this->assertTrue($co->prepare()); + $co->proceed(); + $course = $DB->get_record('course', ['shortname' => 'newcourse1']); + $this->assertNotEmpty($course); + $this->assertEquals('1', $course->relativedatesmode); + } + public function test_delete(): void { global $DB; $this->initialise_test();