Skip to content

Commit

Permalink
MDL-83572 tool_uploadcourse: Add relativedatemode to upload
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentdavid committed Dec 9, 2024
1 parent 0888a6d commit 909d250
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
4 changes: 2 additions & 2 deletions admin/tool/uploadcourse/classes/course.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
10 changes: 8 additions & 2 deletions admin/tool/uploadcourse/classes/tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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');
}
Expand Down Expand Up @@ -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');
}
Expand Down
24 changes: 24 additions & 0 deletions admin/tool/uploadcourse/tests/course_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 909d250

Please sign in to comment.