diff --git a/course/externallib.php b/course/externallib.php index af884871d9834..6f94d142cc65a 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -941,6 +941,8 @@ public static function create_courses($courses) { $params = self::validate_parameters(self::create_courses_parameters(), array('courses' => $courses)); + $courseconfig = get_config('moodlecourse'); + $availablethemes = core_component::get_plugin_list('theme'); $availablelangs = get_string_manager()->get_list_of_translations(); @@ -967,6 +969,14 @@ public static function create_courses($courses) { throw new moodle_exception('errorinvalidparam', 'webservice', '', 'shortname'); } + // Make sure start/end date are correctly set. + if (!array_key_exists('startdate', $course)) { + $course['startdate'] = usergetmidnight(time()); + } + if (!array_key_exists('enddate', $course) && $courseconfig->courseenddateenabled) { + $course['enddate'] = $course['startdate'] + $courseconfig->courseduration; + } + // Make sure lang is valid if (array_key_exists('lang', $course)) { if (empty($availablelangs[$course['lang']])) { @@ -995,7 +1005,6 @@ public static function create_courses($courses) { } //set default value for completion - $courseconfig = get_config('moodlecourse'); if (completion_info::is_enabled_for_site()) { if (!array_key_exists('enablecompletion', $course)) { $course['enablecompletion'] = $courseconfig->enablecompletion;