Commit adc77f07 authored by Eloy Lafuente's avatar Eloy Lafuente
Browse files

Merge branch 'MDL-22078_master' of https://github.com/dmonllao/moodle

parents 4f110020 8643c576
......@@ -92,6 +92,9 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
$temp->add(new admin_setting_configselect('moodlecourse/coursedisplay', new lang_string('coursedisplay'),
new lang_string('coursedisplay_help'), COURSE_DISPLAY_SINGLEPAGE, $choices));
$temp->add(new admin_setting_configduration('moodlecourse/courseduration', get_string('courseduration'),
get_string('courseduration_desc'), YEARSECS));
// Appearance.
$temp->add(new admin_setting_heading('appearancehdr', new lang_string('appearance'), ''));
......
......@@ -93,7 +93,7 @@ class tool_uploadcourse_course {
protected $updatemode;
/** @var array fields allowed as course data. */
static protected $validfields = array('fullname', 'shortname', 'idnumber', 'category', 'visible', 'startdate',
static protected $validfields = array('fullname', 'shortname', 'idnumber', 'category', 'visible', 'startdate', 'enddate',
'summary', 'format', 'theme', 'lang', 'newsitems', 'showgrades', 'showreports', 'legacyfiles', 'maxbytes',
'groupmode', 'groupmodeforce', 'groupmodeforce', 'enablecompletion');
......@@ -587,6 +587,11 @@ class tool_uploadcourse_course {
$coursedata['startdate'] = strtotime($coursedata['startdate']);
}
// Course end date.
if (!empty($coursedata['enddate'])) {
$coursedata['enddate'] = strtotime($coursedata['enddate']);
}
// Ultimate check mode vs. existence.
switch ($mode) {
case tool_uploadcourse_processor::MODE_CREATE_NEW:
......@@ -636,6 +641,22 @@ class tool_uploadcourse_course {
$this->do = self::DO_CREATE;
}
// Validate course start and end dates.
if ($exists) {
// We also check existing start and end dates if we are updating an existing course.
$existingdata = $DB->get_record('course', array('shortname' => $this->shortname));
if (empty($coursedata['startdate'])) {
$coursedata['startdate'] = $existingdata->startdate;
}
if (empty($coursedata['enddate'])) {
$coursedata['enddate'] = $existingdata->enddate;
}
}
if ($errorcode = course_validate_dates($coursedata)) {
$this->error($errorcode, new lang_string($errorcode, 'error'));
return false;
}
// Add role renaming.
$errors = array();
$rolenames = tool_uploadcourse_helper::get_role_names($this->rawdata, $errors);
......@@ -897,6 +918,11 @@ class tool_uploadcourse_course {
}
$resetdata->reset_start_date_old = $course->startdate;
if (empty($course->enddate)) {
$course->enddate = $DB->get_field_select('course', 'enddate', 'id = :id', array('id' => $course->id));
}
$resetdata->reset_end_date_old = $course->enddate;
// Add roles.
$roles = tool_uploadcourse_helper::get_role_ids();
$resetdata->unenrol_users = array_values($roles);
......
......@@ -24,6 +24,8 @@
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/course/lib.php');
/**
* Specify course upload details.
*
......@@ -95,6 +97,9 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
$mform->addHelpButton('defaults[startdate]', 'startdate');
$mform->setDefault('defaults[startdate]', time() + 3600 * 24);
$mform->addElement('date_selector', 'defaults[enddate]', get_string('enddate'), array('optional' => true));
$mform->addHelpButton('defaults[enddate]', 'enddate');
$courseformats = get_sorted_course_formats(true);
$formcourseformats = array();
foreach ($courseformats as $courseformat) {
......@@ -190,4 +195,37 @@ class tool_uploadcourse_step2_form extends tool_uploadcourse_base_form {
$mform->closeHeaderBefore('buttonar');
}
/**
* Sets the enddate default after set_data is called.
*/
public function definition_after_data() {
$mform = $this->_form;
// The default end date depends on the course format.
$format = course_get_format((object)array('format' => get_config('moodlecourse', 'format')));
$enddate = $format->get_default_course_enddate($mform, array('startdate' => 'defaults[startdate]'));
// We add 1 day like we do above in startdate.
$mform->setDefault('defaults[enddate]', $enddate + 3600 * 24);
}
/**
* Validation.
*
* @param array $data
* @param array $files
* @return array the errors that were found
*/
public function validation($data, $files) {
global $DB;
$errors = parent::validation($data, $files);
if ($errorcode = course_validate_dates($data['defaults'])) {
$errors['defaults[enddate]'] = get_string($errorcode, 'error');
}
return $errors;
}
}
......@@ -156,6 +156,7 @@ if (!isset($encodings[$options['encoding']])) {
$defaults = array();
$defaults['category'] = $options['category'];
$defaults['startdate'] = time() + 3600 * 24;
$defaults['enddate'] = $defaults['startdate'] + intval(get_config('moodlecourse', 'courseduration'));
$defaults['newsitems'] = $courseconfig->newsitems;
$defaults['showgrades'] = $courseconfig->showgrades;
$defaults['showreports'] = $courseconfig->showreports;
......
......@@ -104,7 +104,15 @@ if ($form2data = $mform2->is_cancelled()) {
}
} else {
$processor = new tool_uploadcourse_processor($cir, $form1data->options, array());
if (!empty($form1data)) {
$options = $form1data->options;
} else if ($submitteddata = $mform2->get_submitted_data()) {
$options = (array)$submitteddata->options;
} else {
// Weird but we still need to provide a value, setting the default step1_form one.
$options = array('mode' => tool_uploadcourse_processor::MODE_CREATE_NEW);
}
$processor = new tool_uploadcourse_processor($cir, $options, array());
echo $OUTPUT->header();
echo $OUTPUT->heading(get_string('uploadcoursespreview', 'tool_uploadcourse'));
$processor->preview($previewrows, new tool_uploadcourse_tracker(tool_uploadcourse_tracker::OUTPUT_HTML));
......
......@@ -244,7 +244,6 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'fullname' => 'Fullname',
'category' => '1',
'visible' => '0',
'startdate' => '8 June 1990',
'idnumber' => '123abc',
'summary' => 'Summary',
'format' => 'weeks',
......@@ -270,6 +269,20 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'enrolment_3_disable' => '1',
);
// There should be a start date if there is a end date.
$data['enddate'] = '7 June 1990';
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
$this->assertArrayHasKey('nostartdatenoenddate', $co->get_errors());
$data['startdate'] = '8 June 1990';
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
$this->assertArrayHasKey('enddatebeforestartdate', $co->get_errors());
// They are correct now.
$data['enddate'] = '18 June 1990';
$this->assertFalse($DB->record_exists('course', array('shortname' => 'c1')));
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
......@@ -282,6 +295,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
$this->assertEquals($data['category'], $course->category);
$this->assertEquals($data['visible'], $course->visible);
$this->assertEquals(mktime(0, 0, 0, 6, 8, 1990), $course->startdate);
$this->assertEquals(mktime(0, 0, 0, 6, 18, 1990), $course->enddate);
$this->assertEquals($data['idnumber'], $course->idnumber);
$this->assertEquals($data['summary'], $course->summary);
$this->assertEquals($data['format'], $course->format);
......@@ -333,7 +347,6 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'fullname' => 'Fullname 2',
'category' => $cat->id,
'visible' => '1',
'startdate' => '11 June 1984',
'idnumber' => 'changeidn',
'summary' => 'Summary 2',
'format' => 'topics',
......@@ -360,6 +373,21 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
);
$this->assertTrue($DB->record_exists('course', array('shortname' => 'c1')));
$data['enddate'] = '31 June 1984';
// Previous start and end dates are 8 and 18 June 1990.
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
$this->assertArrayHasKey('enddatebeforestartdate', $co->get_errors());
$data['startdate'] = '19 June 1990';
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertFalse($co->prepare());
$this->assertArrayHasKey('enddatebeforestartdate', $co->get_errors());
// They are correct now.
$data['startdate'] = '11 June 1984';
$co = new tool_uploadcourse_course($mode, $updatemode, $data);
$this->assertTrue($co->prepare());
$co->proceed();
......@@ -370,6 +398,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
$this->assertEquals($data['category'], $course->category);
$this->assertEquals($data['visible'], $course->visible);
$this->assertEquals(mktime(0, 0, 0, 6, 11, 1984), $course->startdate);
$this->assertEquals(mktime(0, 0, 0, 6, 31, 1984), $course->enddate);
$this->assertEquals($data['idnumber'], $course->idnumber);
$this->assertEquals($data['summary'], $course->summary);
$this->assertEquals($data['format'], $course->format);
......@@ -425,6 +454,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'category' => '1',
'visible' => '0',
'startdate' => 644803200,
'enddate' => 645667200,
'idnumber' => '123abc',
'summary' => 'Summary',
'format' => 'weeks',
......@@ -452,6 +482,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
$this->assertEquals($defaultdata['category'], $course->category);
$this->assertEquals($defaultdata['visible'], $course->visible);
$this->assertEquals($defaultdata['startdate'], $course->startdate);
$this->assertEquals($defaultdata['enddate'], $course->enddate);
$this->assertEquals($defaultdata['idnumber'], $course->idnumber);
$this->assertEquals($defaultdata['summary'], $course->summary);
$this->assertEquals($defaultdata['format'], $course->format);
......@@ -478,6 +509,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
'category' => $cat->id,
'visible' => '1',
'startdate' => 455760000,
'enddate' => 457488000,
'idnumber' => 'changedid',
'summary' => 'Summary 2',
'format' => 'topics',
......@@ -505,6 +537,7 @@ class tool_uploadcourse_course_testcase extends advanced_testcase {
$this->assertEquals($defaultdata['category'], $course->category);
$this->assertEquals($defaultdata['visible'], $course->visible);
$this->assertEquals($defaultdata['startdate'], $course->startdate);
$this->assertEquals($defaultdata['enddate'], $course->enddate);
$this->assertEquals($defaultdata['idnumber'], $course->idnumber);
$this->assertEquals($defaultdata['summary'], $course->summary);
$this->assertEquals($defaultdata['format'], $course->format);
......
......@@ -375,7 +375,7 @@ class backup_course_structure_step extends backup_structure_step {
$course = new backup_nested_element('course', array('id', 'contextid'), array(
'shortname', 'fullname', 'idnumber',
'summary', 'summaryformat', 'format', 'showgrades',
'newsitems', 'startdate',
'newsitems', 'startdate', 'enddate',
'marker', 'maxbytes', 'legacyfiles', 'showreports',
'visible', 'groupmode', 'groupmodeforce',
'defaultgroupingid', 'lang', 'theme',
......@@ -1780,6 +1780,7 @@ class backup_main_structure_step extends backup_structure_step {
$info['original_course_fullname'] = $originalcourseinfo->fullname;
$info['original_course_shortname'] = $originalcourseinfo->shortname;
$info['original_course_startdate'] = $originalcourseinfo->startdate;
$info['original_course_enddate'] = $originalcourseinfo->enddate;
$info['original_course_contextid'] = context_course::instance($this->get_courseid())->id;
$info['original_system_contextid'] = context_system::instance()->id;
......@@ -1795,7 +1796,7 @@ class backup_main_structure_step extends backup_structure_step {
'name', 'moodle_version', 'moodle_release', 'backup_version',
'backup_release', 'backup_date', 'mnet_remoteusers', 'include_files', 'include_file_references_to_external_content', 'original_wwwroot',
'original_site_identifier_hash', 'original_course_id', 'original_course_format',
'original_course_fullname', 'original_course_shortname', 'original_course_startdate',
'original_course_fullname', 'original_course_shortname', 'original_course_startdate', 'original_course_enddate',
'original_course_contextid', 'original_system_contextid'));
$details = new backup_nested_element('details');
......
......@@ -1870,6 +1870,10 @@ class restore_course_structure_step extends restore_structure_step {
$this->legacyrestrictmodules = !empty($data->restrictmodules);
$data->startdate= $this->apply_date_offset($data->startdate);
if (isset($data->enddate)) {
$data->enddate = $this->apply_date_offset($data->enddate);
}
if ($data->defaultgroupingid) {
$data->defaultgroupingid = $this->get_mappingid('grouping', $data->defaultgroupingid);
}
......
......@@ -340,7 +340,9 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// Create a course with specific start date.
$generator = $this->getDataGenerator();
$course = $generator->create_course(array(
'startdate' => strtotime('1 Jan 2014 00:00 GMT')));
'startdate' => strtotime('1 Jan 2014 00:00 GMT'),
'enddate' => strtotime('3 Aug 2014 00:00 GMT')
));
// Add a forum with conditional availability date restriction, including
// one of them nested inside a tree.
......@@ -361,6 +363,9 @@ class core_backup_moodle2_testcase extends advanced_testcase {
// Do backup and restore.
$newcourseid = $this->backup_and_restore($course, strtotime('3 Jan 2015 00:00 GMT'));
$newcourse = $DB->get_record('course', array('id' => $newcourseid));
$this->assertEquals(strtotime('5 Aug 2015 00:00 GMT'), $newcourse->enddate);
$modinfo = get_fast_modinfo($newcourseid);
// Check forum dates are modified by the same amount as the course start.
......
......@@ -174,9 +174,9 @@ abstract class restore_check {
// settings so that they cannot change it.
$hasrolldatescap = has_capability('moodle/restore:rolldates', $coursectx, $userid);
if (!$hasrolldatescap) {
$datesetting = $restore_controller->get_plan()->get_setting('course_startdate');
if ($datesetting) {
$datesetting->set_status(base_setting::LOCKED_BY_PERMISSION);
$startdatesetting = $restore_controller->get_plan()->get_setting('course_startdate');
if ($startdatesetting) {
$startdatesetting->set_status(base_setting::LOCKED_BY_PERMISSION);
}
}
......
......@@ -530,7 +530,7 @@ abstract class backup_controller_dbops extends backup_dbops {
*/
public static function backup_get_original_course_info($courseid) {
global $DB;
return $DB->get_record('course', array('id' => $courseid), 'fullname, shortname, startdate, format');
return $DB->get_record('course', array('id' => $courseid), 'fullname, shortname, startdate, enddate, format');
}
/**
......
......@@ -152,12 +152,16 @@ abstract class backup_general_helper extends backup_helper {
$info->mnet_remoteusers = $infoarr['mnet_remoteusers'];
$info->original_wwwroot = $infoarr['original_wwwroot'];
$info->original_site_identifier_hash = $infoarr['original_site_identifier_hash'];
$info->original_course_id = $infoarr['original_course_id'];
$info->original_course_fullname = $infoarr['original_course_fullname'];
$info->original_course_shortname= $infoarr['original_course_shortname'];
$info->original_course_startdate= $infoarr['original_course_startdate'];
$info->original_course_contextid= $infoarr['original_course_contextid'];
$info->original_system_contextid= $infoarr['original_system_contextid'];
$info->original_course_id = $infoarr['original_course_id'];
$info->original_course_fullname = $infoarr['original_course_fullname'];
$info->original_course_shortname = $infoarr['original_course_shortname'];
$info->original_course_startdate = $infoarr['original_course_startdate'];
// Old versions may not have this.
if (isset($infoarr['original_course_enddate'])) {
$info->original_course_enddate = $infoarr['original_course_enddate'];
}
$info->original_course_contextid = $infoarr['original_course_contextid'];
$info->original_system_contextid = $infoarr['original_system_contextid'];
// Moodle backup file don't have this option before 2.3
if (!empty($infoarr['include_file_references_to_external_content'])) {
$info->include_file_references_to_external_content = 1;
......
......@@ -125,6 +125,9 @@ class course_edit_form extends moodleform {
$mform->addHelpButton('startdate', 'startdate');
$mform->setDefault('startdate', time() + 3600 * 24);
$mform->addElement('date_selector', 'enddate', get_string('enddate'), array('optional' => true));
$mform->addHelpButton('enddate', 'enddate');
$mform->addElement('text','idnumber', get_string('idnumbercourse'),'maxlength="100" size="10"');
$mform->addHelpButton('idnumber', 'idnumbercourse');
$mform->setType('idnumber', PARAM_RAW);
......@@ -339,7 +342,8 @@ class course_edit_form extends moodleform {
$mform = $this->_form;
// add available groupings
if ($courseid = $mform->getElementValue('id') and $mform->elementExists('defaultgroupingid')) {
$courseid = $mform->getElementValue('id');
if ($courseid and $mform->elementExists('defaultgroupingid')) {
$options = array();
if ($groupings = $DB->get_records('groupings', array('courseid'=>$courseid))) {
foreach ($groupings as $grouping) {
......@@ -354,7 +358,14 @@ class course_edit_form extends moodleform {
// add course format options
$formatvalue = $mform->getElementValue('format');
if (is_array($formatvalue) && !empty($formatvalue)) {
$courseformat = course_get_format((object)array('format' => $formatvalue[0]));
$params = array('format' => $formatvalue[0]);
// Load the course as well if it is available, course formats may need it to work out
// they preferred course end date.
if ($courseid) {
$params['id'] = $courseid;
}
$courseformat = course_get_format((object)$params);
$elements = $courseformat->create_edit_form_elements($mform);
for ($i = 0; $i < count($elements); $i++) {
......@@ -392,6 +403,10 @@ class course_edit_form extends moodleform {
}
}
if ($errorcode = course_validate_dates($data)) {
$errors['enddate'] = get_string($errorcode, 'error');
}
$errors = array_merge($errors, enrol_course_edit_validation($data, $this->context));
$courseformat = course_get_format((object)array('format' => $data['format']));
......
......@@ -441,6 +441,7 @@ class core_course_external extends external_api {
external_format_text($course->summary, $course->summaryformat, $context->id, 'course', 'summary', 0);
$courseinfo['format'] = $course->format;
$courseinfo['startdate'] = $course->startdate;
$courseinfo['enddate'] = $course->enddate;
if (array_key_exists('numsections', $courseformatoptions)) {
// For backward-compartibility
$courseinfo['numsections'] = $courseformatoptions['numsections'];
......@@ -515,6 +516,8 @@ class core_course_external extends external_api {
'number of recent items appearing on the course page', VALUE_OPTIONAL),
'startdate' => new external_value(PARAM_INT,
'timestamp when the course start'),
'enddate' => new external_value(PARAM_INT,
'timestamp when the course end'),
'numsections' => new external_value(PARAM_INT,
'(deprecated, use courseformatoptions) number of weeks/topics',
VALUE_OPTIONAL),
......@@ -590,6 +593,8 @@ class core_course_external extends external_api {
VALUE_DEFAULT, $courseconfig->newsitems),
'startdate' => new external_value(PARAM_INT,
'timestamp when the course start', VALUE_OPTIONAL),
'enddate' => new external_value(PARAM_INT,
'timestamp when the course end', VALUE_OPTIONAL),
'numsections' => new external_value(PARAM_INT,
'(deprecated, use courseformatoptions) number of weeks/topics',
VALUE_OPTIONAL),
......@@ -765,6 +770,8 @@ class core_course_external extends external_api {
'number of recent items appearing on the course page', VALUE_OPTIONAL),
'startdate' => new external_value(PARAM_INT,
'timestamp when the course start', VALUE_OPTIONAL),
'enddate' => new external_value(PARAM_INT,
'timestamp when the course end', VALUE_OPTIONAL),
'numsections' => new external_value(PARAM_INT,
'(deprecated, use courseformatoptions) number of weeks/topics', VALUE_OPTIONAL),
'maxbytes' => new external_value(PARAM_INT,
......
......@@ -679,6 +679,13 @@ abstract class format_base {
$mform->setDefault($optionname, $option['default']);
}
}
if (!$forsection && empty($this->courseid)) {
// At this stage (this is called from definition_after_data) course data is already set as default.
// We can not overwrite what is in the database.
$mform->setDefault('enddate', $this->get_default_course_enddate($mform));
}
return $elements;
}
......@@ -1100,6 +1107,46 @@ abstract class format_base {
return $this->inplace_editable_render_section_name($section, ($itemtype === 'sectionname'), true);
}
}
/**
* Returns the default end date value based on the start date.
*
* This is the default implementation for course formats, it is based on
* moodlecourse/courseduration setting. Course formats like format_weeks for
* example can overwrite this method and return a value based on their internal options.
*
* @param moodleform $mform
* @param array $fieldnames The form - field names mapping.
* @return int
*/
public function get_default_course_enddate($mform, $fieldnames = array()) {
if (empty($fieldnames)) {
$fieldnames = array('startdate' => 'startdate');
}
$startdate = $this->get_form_start_date($mform, $fieldnames);
$courseduration = intval(get_config('moodlecourse', 'courseduration'));
if (!$courseduration) {
// Default, it should be already set during upgrade though.
$courseduration = YEARSECS;
}
return $startdate + $courseduration;
}
/**
* Get the start date value from the course settings page form.
*
* @param moodleform $mform
* @param array $fieldnames The form - field names mapping.
* @return int
*/
protected function get_form_start_date($mform, $fieldnames) {
$startdate = $mform->getElementValue($fieldnames['startdate']);
return $mform->getElement($fieldnames['startdate'])->exportValue($startdate);
}
}
/**
......
......@@ -211,4 +211,43 @@ class format_topics_testcase extends advanced_testcase {
$this->assertEquals(1, preg_match('/^Can not find data record in database/', $e->getMessage()));
}
}
/**
* Test get_default_course_enddate.
*
* @return void
*/
public function test_default_course_enddate() {
global $CFG, $DB;
$this->resetAfterTest(true);
require_once($CFG->dirroot . '/course/tests/fixtures/testable_course_edit_form.php');
$this->setTimezone('UTC');
$params = array('format' => 'topics', 'numsections' => 5, 'startdate' => 1445644800);
$course = $this->getDataGenerator()->create_course($params);
$category = $DB->get_record('course_categories', array('id' => $course->category));
$args = [
'course' => $course,
'category' => $category,
'editoroptions' => [
'context' => context_course::instance($course->id),
'subdirs' => 0
],
'returnto' => new moodle_url('/'),
'returnurl' => new moodle_url('/'),
];
$courseform = new testable_course_edit_form(null, $args);
$courseform->definition_after_data();
$enddate = $params['startdate'] + get_config('moodlecourse', 'courseduration');
$weeksformat = course_get_format($course->id);
$this->assertEquals($enddate, $weeksformat->get_default_course_enddate($courseform->get_quick_form()));
}
}
......@@ -4,6 +4,9 @@ Overview of this plugin type at http://docs.moodle.org/dev/Course_formats
=== 3.2 ===
* Callback delete_course is deprecated and should be replaced with observer for event \core\event\course_content_deleted
* Course formats can overwrite get_default_course_enddate function to set the default course end date for new courses.
format_base::get_default_course_enddate uses the new "Course duration" site setting to calculate the default course end date
from the default course start date.
=== 3.1 ===
* Course format may use the inplace_editable template to allow quick editing of section names, see
......
......@@ -380,10 +380,16 @@ class format_weeks extends format_base {
* Return the start and end date of the passed section
*
* @param int|stdClass|section_info $section section to get the dates for
* @param int $startdate Force course start date, useful when the course is not yet created
* @return stdClass property start for startdate, property end for enddate
*/
public function get_section_dates($section) {
$course = $this->get_course();
public function get_section_dates($section, $startdate = false) {
if ($startdate === false) {
$course = $this->get_course();
$startdate = $course->startdate;
}
if (is_object($section)) {
$sectionnum = $section->section;
} else {
......@@ -392,7 +398,7 @@ class format_weeks extends format_base {
$oneweekseconds = 604800;
// Hack alert. We add 2 hours to avoid possible DST problems. (e.g. we go into daylight
// savings and the date changes.
$startdate = $course->startdate + 7200;
$startdate = $startdate + 7200;
$dates = new stdClass();
$dates->start = $startdate + ($oneweekseconds * ($sectionnum - 1));
......@@ -454,6 +460,37 @@ class format_weeks extends format_base {
}
return parent::inplace_editable_render_section_name($section, $linkifneeded, $editable, $edithint, $editlabel);
}
/**
* Returns the default end date for weeks course format.
*
* @param moodleform $mform
* @param array $fieldnames The form - field names mapping.
* @return int
*/