Merge branch 'MDL-56251_master-fix' of https://github.com/markn86/moodle
This commit is contained in:
+13
-11
@@ -516,18 +516,20 @@ class format_weeks extends format_base {
|
||||
|
||||
// Use one DB query to retrieve necessary fields in course, value for automaticenddate and number of the last
|
||||
// section. This query will also validate that the course is indeed in 'weeks' format.
|
||||
$sql = "SELECT c.id, c.format, c.startdate, c.enddate, fo.value AS automaticenddate, MAX(s.section) AS lastsection
|
||||
FROM {course} c
|
||||
$insql = "SELECT c.id, c.format, c.startdate, c.enddate, MAX(s.section) AS lastsection
|
||||
FROM {course} c
|
||||
JOIN {course_sections} s
|
||||
ON s.course = c.id
|
||||
WHERE c.format = :format
|
||||
AND c.id = :courseid
|
||||
GROUP BY c.id, c.format, c.startdate, c.enddate";
|
||||
$sql = "SELECT co.id, co.format, co.startdate, co.enddate, co.lastsection, fo.value AS automaticenddate
|
||||
FROM ($insql) co
|
||||
LEFT JOIN {course_format_options} fo
|
||||
ON fo.courseid = c.id
|
||||
AND fo.format = c.format
|
||||
ON fo.courseid = co.id
|
||||
AND fo.format = co.format
|
||||
AND fo.name = :optionname
|
||||
AND fo.sectionid = 0
|
||||
LEFT JOIN {course_sections} s
|
||||
ON s.course = c.id
|
||||
WHERE c.format = :format
|
||||
AND c.id = :courseid
|
||||
GROUP BY c.id, c.format, c.startdate, c.enddate, fo.value";
|
||||
AND fo.sectionid = 0";
|
||||
$course = $DB->get_record_sql($sql,
|
||||
['optionname' => 'automaticenddate', 'format' => 'weeks', 'courseid' => $courseid]);
|
||||
|
||||
@@ -543,7 +545,7 @@ class format_weeks extends format_base {
|
||||
// If automaticenddate is not specified take the default value.
|
||||
if (!isset($course->automaticenddate)) {
|
||||
$defaults = $format->course_format_options();
|
||||
$course->automaticenddate = $defaults['automaticenddate'];
|
||||
$course->automaticenddate = $defaults['automaticenddate']['default'];
|
||||
}
|
||||
|
||||
// Check that the course format for setting an automatic date is set.
|
||||
|
||||
@@ -148,6 +148,38 @@ class format_weeks_observer_testcase extends advanced_testcase {
|
||||
$this->assertEquals($enddate, $dates->end);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when we update a course without automatic end date set.
|
||||
*/
|
||||
public function test_create_section_without_automatic_end_date() {
|
||||
global $DB;
|
||||
|
||||
// Generate a course with some sections.
|
||||
$startdate = time();
|
||||
$enddate = $startdate + WEEKSECS;
|
||||
$course = $this->getDataGenerator()->create_course(array(
|
||||
'numsections' => 6,
|
||||
'format' => 'weeks',
|
||||
'startdate' => $startdate,
|
||||
'enddate' => $enddate,
|
||||
'automaticenddate' => 0));
|
||||
|
||||
// Delete automatic end date from the database.
|
||||
$DB->delete_records('course_format_options', ['courseid' => $course->id, 'name' => 'automaticenddate']);
|
||||
|
||||
// Create a new section.
|
||||
course_create_section($course->id, 0);
|
||||
|
||||
// Get the updated course end date.
|
||||
$updateenddate = $DB->get_field('course', 'enddate', array('id' => $course->id));
|
||||
|
||||
// Confirm enddate is automatic now - since automatic end date is not set it is assumed default (which is '1').
|
||||
$format = course_get_format($course->id);
|
||||
$this->assertEquals(7, $format->get_last_section_number());
|
||||
$dates = $format->get_section_dates(7);
|
||||
$this->assertEquals($dates->end, $updateenddate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests when we deleting a course section with automatic end date set.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user