Skip to content

Commit

Permalink
MDL-58659 enroll: Add start and end date fields required by overview
Browse files Browse the repository at this point in the history
Those fields are required to display the courses overview for final
users.
  • Loading branch information
jleyva committed Apr 20, 2017
1 parent ef83fc2 commit 01c2670
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
6 changes: 5 additions & 1 deletion enrol/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ public static function get_users_courses($userid) {
$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) {
Expand Down Expand Up @@ -346,6 +346,8 @@ public static function get_users_courses($userid) {
'enablecompletion' => $course->enablecompletion,
'category' => $course->category,
'progress' => $progress,
'startdate' => $course->startdate,
'enddate' => $course->enddate,
);
}

Expand Down Expand Up @@ -376,6 +378,8 @@ public static function get_users_courses_returns() {
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),
)
)
);
Expand Down
5 changes: 4 additions & 1 deletion enrol/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,14 +363,17 @@ public function test_get_users_courses() {

$this->resetAfterTest(true);

$timenow = time();
$coursedata1 = array(
'fullname' => '<b>Course 1</b>', // Adding tags here to check that external_format_string works.
'shortname' => '<b>Course 1</b>', // Adding tags here to check that external_format_string works.
'summary' => 'Lightwork Course 1 description',
'summaryformat' => FORMAT_MOODLE,
'lang' => 'en',
'enablecompletion' => true,
'showgrades' => true
'showgrades' => true,
'startdate' => $timenow,
'enddate' => $timenow + WEEKSECS
);

$course1 = self::getDataGenerator()->create_course($coursedata1);
Expand Down
4 changes: 4 additions & 0 deletions enrol/upgrade.txt
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 01c2670

Please sign in to comment.