From ef83fc2a33af8eae36cd14d225a69cc6872ea3eb Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 20 Apr 2017 12:53:10 +0200 Subject: [PATCH 1/2] MDL-58659 course: Add missing enddate field in get_courses_by_field --- course/externallib.php | 3 ++- course/tests/externallib_test.php | 16 ++++++++-------- course/upgrade.txt | 1 + 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/course/externallib.php b/course/externallib.php index 27733fcf52e..469cb1cf1ec 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -2398,6 +2398,7 @@ class core_course_external extends external_api { 'showgrades' => new external_value(PARAM_INT, '1 if grades are shown, otherwise 0', VALUE_OPTIONAL), 'newsitems' => new external_value(PARAM_INT, '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), 'maxbytes' => new external_value(PARAM_INT, 'Largest size of file that can be uploaded into', VALUE_OPTIONAL), 'showreports' => new external_value(PARAM_INT, 'Are activity report shown (yes = 1, no =0)', VALUE_OPTIONAL), 'visible' => new external_value(PARAM_INT, '1: available to student, 0:not available', VALUE_OPTIONAL), @@ -3025,7 +3026,7 @@ class core_course_external extends external_api { continue; } // Return information for any user that can access the course. - $coursefields = array('format', 'showgrades', 'newsitems', 'startdate', 'maxbytes', 'showreports', 'visible', + $coursefields = array('format', 'showgrades', 'newsitems', 'startdate', 'enddate', 'maxbytes', 'showreports', 'visible', 'groupmode', 'groupmodeforce', 'defaultgroupingid', 'enablecompletion', 'completionnotify', 'lang', 'theme', 'marker'); diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 9d0cb22fc25..52e6d7551d1 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -2001,16 +2001,16 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result); $this->assertCount(3, $result['courses']); // Expect to receive all the fields. - $this->assertCount(36, $result['courses'][0]); - $this->assertCount(36, $result['courses'][1]); - $this->assertCount(36, $result['courses'][2]); + $this->assertCount(37, $result['courses'][0]); + $this->assertCount(37, $result['courses'][1]); + $this->assertCount(37, $result['courses'][2]); $result = core_course_external::get_courses_by_field('id', $course1->id); $result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result); $this->assertCount(1, $result['courses']); $this->assertEquals($course1->id, $result['courses'][0]['id']); // Expect to receive all the fields. - $this->assertCount(36, $result['courses'][0]); + $this->assertCount(37, $result['courses'][0]); $result = core_course_external::get_courses_by_field('id', $course2->id); $result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result); @@ -2052,15 +2052,15 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $result = core_course_external::get_courses_by_field(); $result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result); $this->assertCount(2, $result['courses']); - $this->assertCount(29, $result['courses'][0]); - $this->assertCount(29, $result['courses'][1]); + $this->assertCount(30, $result['courses'][0]); + $this->assertCount(30, $result['courses'][1]); $result = core_course_external::get_courses_by_field('id', $course1->id); $result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result); $this->assertCount(1, $result['courses']); $this->assertEquals($course1->id, $result['courses'][0]['id']); // Expect to receive all the files that a student can see. - $this->assertCount(29, $result['courses'][0]); + $this->assertCount(30, $result['courses'][0]); // Check default filters. $filters = $result['courses'][0]['filters']; @@ -2105,7 +2105,7 @@ class core_course_externallib_testcase extends externallib_advanced_testcase { $result = core_course_external::get_courses_by_field(); $result = external_api::clean_returnvalue(core_course_external::get_courses_by_field_returns(), $result); $this->assertCount(2, $result['courses']); - $this->assertCount(29, $result['courses'][0]); // Site course. + $this->assertCount(30, $result['courses'][0]); // Site course. $this->assertCount(13, $result['courses'][1]); // Only public information, not enrolled. $result = core_course_external::get_courses_by_field('id', $course1->id); diff --git a/course/upgrade.txt b/course/upgrade.txt index 1c53aa75916..3e05828df4d 100644 --- a/course/upgrade.txt +++ b/course/upgrade.txt @@ -4,6 +4,7 @@ information provided here is intended especially for developers. === 3.3 === * External function core_course_external::get_courses_by_field now returns the course filters list and status. + * External function core_course_external::get_courses_by_field now returns the end date of the course. * External function core_course_external::get_course_contents now return the following additional file fields: - mimetype (the file mime type) - isexternalfile (if is a file reference to a external repository) From 01c26702d3fbfb47dac25bc2c33061276c4b53f0 Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Thu, 20 Apr 2017 12:54:33 +0200 Subject: [PATCH 2/2] MDL-58659 enroll: Add start and end date fields required by overview Those fields are required to display the courses overview for final users. --- enrol/externallib.php | 6 +++++- enrol/tests/externallib_test.php | 5 ++++- enrol/upgrade.txt | 4 ++++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/enrol/externallib.php b/enrol/externallib.php index 588fbf96f69..83cb31e3cc5 100644 --- a/enrol/externallib.php +++ b/enrol/externallib.php @@ -300,7 +300,7 @@ class core_enrol_external extends external_api { $params = self::validate_parameters(self::get_users_courses_parameters(), array('userid'=>$userid)); $courses = enrol_get_users_courses($params['userid'], true, 'id, shortname, fullname, idnumber, visible, - summary, summaryformat, format, showgrades, lang, enablecompletion, category'); + summary, summaryformat, format, showgrades, lang, enablecompletion, category, startdate, enddate'); $result = array(); foreach ($courses as $course) { @@ -346,6 +346,8 @@ class core_enrol_external extends external_api { 'enablecompletion' => $course->enablecompletion, 'category' => $course->category, 'progress' => $progress, + 'startdate' => $course->startdate, + 'enddate' => $course->enddate, ); } @@ -376,6 +378,8 @@ class core_enrol_external extends external_api { VALUE_OPTIONAL), 'category' => new external_value(PARAM_INT, 'course category id', VALUE_OPTIONAL), 'progress' => new external_value(PARAM_FLOAT, 'Progress percentage', 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), ) ) ); diff --git a/enrol/tests/externallib_test.php b/enrol/tests/externallib_test.php index 7695e3c7bc7..b3e061dda80 100644 --- a/enrol/tests/externallib_test.php +++ b/enrol/tests/externallib_test.php @@ -363,6 +363,7 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { $this->resetAfterTest(true); + $timenow = time(); $coursedata1 = array( 'fullname' => 'Course 1', // Adding tags here to check that external_format_string works. 'shortname' => 'Course 1', // Adding tags here to check that external_format_string works. @@ -370,7 +371,9 @@ class core_enrol_externallib_testcase extends externallib_advanced_testcase { 'summaryformat' => FORMAT_MOODLE, 'lang' => 'en', 'enablecompletion' => true, - 'showgrades' => true + 'showgrades' => true, + 'startdate' => $timenow, + 'enddate' => $timenow + WEEKSECS ); $course1 = self::getDataGenerator()->create_course($coursedata1); diff --git a/enrol/upgrade.txt b/enrol/upgrade.txt index 4dc90ca41a5..f170c7ab625 100644 --- a/enrol/upgrade.txt +++ b/enrol/upgrade.txt @@ -1,6 +1,10 @@ This files describes API changes in /enrol/* - plugins, information provided here is intended especially for developers. +=== 3.3 === + +* External function core_enrol_external::get_users_courses now return the user progress, start and the end course dates. + === 3.2 === * External function core_enrol_external::get_users_courses now return the category id as an additional optional field.