From 51c9c709a9bd193322d309c1b78721b6113927dc Mon Sep 17 00:00:00 2001 From: Juan Leyva Date: Mon, 27 Jun 2022 10:49:31 +0200 Subject: [PATCH] MDL-75058 course: Fix support for dates on WebServices --- course/externallib.php | 3 ++ course/tests/externallib_test.php | 53 +++++++++++++++++++++++++++++++ mod/assign/classes/dates.php | 2 ++ mod/assign/tests/dates_test.php | 42 ++++++++++++++++-------- mod/chat/classes/dates.php | 1 + mod/chat/tests/dates_test.php | 15 ++++++--- mod/choice/classes/dates.php | 2 ++ mod/choice/tests/dates_test.php | 16 +++++----- mod/data/classes/dates.php | 2 ++ mod/data/tests/dates_test.php | 16 +++++----- mod/feedback/classes/dates.php | 2 ++ mod/feedback/tests/dates_test.php | 16 +++++----- mod/forum/classes/dates.php | 1 + mod/forum/tests/dates_test.php | 4 +-- mod/lesson/classes/dates.php | 2 ++ mod/lesson/tests/dates_test.php | 28 ++++++++-------- mod/quiz/classes/dates.php | 2 ++ mod/quiz/tests/dates_test.php | 28 ++++++++-------- mod/scorm/classes/dates.php | 2 ++ mod/scorm/tests/dates_test.php | 16 +++++----- mod/workshop/classes/dates.php | 4 +++ mod/workshop/tests/dates_test.php | 32 +++++++++---------- 22 files changed, 192 insertions(+), 97 deletions(-) diff --git a/course/externallib.php b/course/externallib.php index f9c192241cd..95a43cf5094 100644 --- a/course/externallib.php +++ b/course/externallib.php @@ -478,6 +478,9 @@ class core_course_external extends external_api { array( 'label' => new external_value(PARAM_TEXT, 'date label'), 'timestamp' => new external_value(PARAM_INT, 'date timestamp'), + 'relativeto' => new external_value(PARAM_INT, 'relative date timestamp', + VALUE_OPTIONAL), + 'dataid' => new external_value(PARAM_NOTAGS, 'cm data id', VALUE_OPTIONAL), ) ), VALUE_DEFAULT, diff --git a/course/tests/externallib_test.php b/course/tests/externallib_test.php index 2dc265d3c68..4f97c8568bc 100644 --- a/course/tests/externallib_test.php +++ b/course/tests/externallib_test.php @@ -1655,6 +1655,59 @@ class externallib_test extends externallib_advanced_testcase { $this->assertEquals(-1, $sections[5]['id']); } + /** + * Test get course contents dates. + */ + public function test_get_course_contents_dates() { + $this->resetAfterTest(true); + + $this->setAdminUser(); + set_config('enablecourserelativedates', 1); + + // Course with just main section. + $timenow = time(); + $course = self::getDataGenerator()->create_course( + ['numsections' => 0, 'relativedatesmode' => true, 'startdate' => $timenow - DAYSECS]); + + $teacher = self::getDataGenerator()->create_user(); + self::getDataGenerator()->enrol_user($teacher->id, $course->id, 'editingteacher'); + + $this->setUser($teacher); + + // Create resource (empty dates). + $resource = self::getDataGenerator()->create_module('resource', ['course' => $course->id]); + // Create activities with dates. + $resource = self::getDataGenerator()->create_module('forum', ['course' => $course->id, 'duedate' => $timenow]); + $resource = self::getDataGenerator()->create_module('choice', + ['course' => $course->id, 'timeopen' => $timenow, 'timeclose' => $timenow + DAYSECS]); + $resource = self::getDataGenerator()->create_module('assign', + ['course' => $course->id, 'allowsubmissionsfromdate' => $timenow]); + + $result = core_course_external::get_course_contents($course->id); + $result = external_api::clean_returnvalue(core_course_external::get_course_contents_returns(), $result); + + foreach ($result[0]['modules'] as $module) { + if ($module['modname'] == 'resource') { + $this->assertEmpty($module['dates']); + } else if ($module['modname'] == 'forum') { + $this->assertCount(1, $module['dates']); + $this->assertEquals('duedate', $module['dates'][0]['dataid']); + $this->assertEquals($timenow, $module['dates'][0]['timestamp']); + } else if ($module['modname'] == 'choice') { + $this->assertCount(2, $module['dates']); + $this->assertEquals('timeopen', $module['dates'][0]['dataid']); + $this->assertEquals($timenow, $module['dates'][0]['timestamp']); + $this->assertEquals('timeclose', $module['dates'][1]['dataid']); + $this->assertEquals($timenow + DAYSECS, $module['dates'][1]['timestamp']); + } else if ($module['modname'] == 'assign') { + $this->assertCount(1, $module['dates']); + $this->assertEquals('allowsubmissionsfromdate', $module['dates'][0]['dataid']); + $this->assertEquals($timenow, $module['dates'][0]['timestamp']); + $this->assertEquals($course->startdate, $module['dates'][0]['relativeto']); + } + } + } + /** * Test duplicate_course */ diff --git a/mod/assign/classes/dates.php b/mod/assign/classes/dates.php index fa284deccc1..d171d43ad4c 100644 --- a/mod/assign/classes/dates.php +++ b/mod/assign/classes/dates.php @@ -72,6 +72,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened'; $date = [ + 'dataid' => 'allowsubmissionsfromdate', 'label' => get_string($openlabelid, 'mod_assign'), 'timestamp' => (int) $timeopen, ]; @@ -83,6 +84,7 @@ class dates extends activity_dates { if ($timedue) { $date = [ + 'dataid' => 'duedate', 'label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => (int) $timedue, ]; diff --git a/mod/assign/tests/dates_test.php b/mod/assign/tests/dates_test.php index 35bb7e9787f..57fbaa05cd3 100644 --- a/mod/assign/tests/dates_test.php +++ b/mod/assign/tests/dates_test.php @@ -56,48 +56,62 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, null, null, null, null, [ - ['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after], + ['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after, + 'dataid' => 'allowsubmissionsfromdate'], ] ], 'only with closing time' => [ null, $after, null, null, null, null, [ - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after, + 'dataid' => 'duedate'], ] ], 'with both times' => [ $after, $later, null, null, null, null, [ - ['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after], - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later], + ['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after, + 'dataid' => 'allowsubmissionsfromdate'], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later, + 'dataid' => 'duedate'], ] ], 'between the dates' => [ $before, $after, null, null, null, null, [ - ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $before], - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after], + ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $before, + 'dataid' => 'allowsubmissionsfromdate'], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after, + 'dataid' => 'duedate'], ] ], 'dates are past' => [ $earlier, $before, null, null, null, null, [ - ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $before], + ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier, + 'dataid' => 'allowsubmissionsfromdate'], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $before, + 'dataid' => 'duedate'], ] ], 'with user override' => [ $before, $after, $earlier, $later, null, null, [ - ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later], + ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier, + 'dataid' => 'allowsubmissionsfromdate'], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later, + 'dataid' => 'duedate'], ] ], 'with group override' => [ $before, $after, null, null, $earlier, $later, [ - ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later], + ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier, + 'dataid' => 'allowsubmissionsfromdate'], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later, + 'dataid' => 'duedate'], ] ], 'with both user and group overrides' => [ $before, $after, $earlier, $later, $earlier - DAYSECS, $later + DAYSECS, [ - ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later], + ['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier, + 'dataid' => 'allowsubmissionsfromdate'], + ['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later, + 'dataid' => 'duedate'], ] ], ]; diff --git a/mod/chat/classes/dates.php b/mod/chat/classes/dates.php index 21f6058f91c..cffdd87a092 100644 --- a/mod/chat/classes/dates.php +++ b/mod/chat/classes/dates.php @@ -46,6 +46,7 @@ class dates extends activity_dates { if (!empty($chat->schedule) && $chattime > $now) { return [ [ + 'dataid' => 'chattime', 'label' => get_string('nextchattime', 'mod_chat'), 'timestamp' => (int) $chattime ] diff --git a/mod/chat/tests/dates_test.php b/mod/chat/tests/dates_test.php index dd8d3407612..86a19b1bde0 100644 --- a/mod/chat/tests/dates_test.php +++ b/mod/chat/tests/dates_test.php @@ -62,7 +62,8 @@ class dates_test extends advanced_testcase { $future, CHAT_SCHEDULE_SINGLE, [ [ 'label' => $label, - 'timestamp' => $future + 'timestamp' => $future, + 'dataid' => 'chattime', ], ] ], @@ -70,7 +71,8 @@ class dates_test extends advanced_testcase { $future, CHAT_SCHEDULE_WEEKLY, [ [ 'label' => $label, - 'timestamp' => $future + 'timestamp' => $future, + 'dataid' => 'chattime', ] ] ], @@ -78,7 +80,8 @@ class dates_test extends advanced_testcase { $future, CHAT_SCHEDULE_DAILY, [ [ 'label' => $label, - 'timestamp' => $future + 'timestamp' => $future, + 'dataid' => 'chattime', ] ] ], @@ -86,7 +89,8 @@ class dates_test extends advanced_testcase { $past, CHAT_SCHEDULE_DAILY, [ [ 'label' => $label, - 'timestamp' => $dailynextchattime + 'timestamp' => $dailynextchattime, + 'dataid' => 'chattime', ], ] ], @@ -94,7 +98,8 @@ class dates_test extends advanced_testcase { $past, CHAT_SCHEDULE_WEEKLY, [ [ 'label' => $label, - 'timestamp' => $weeklynextchattime + 'timestamp' => $weeklynextchattime, + 'dataid' => 'chattime', ], ] ], diff --git a/mod/choice/classes/dates.php b/mod/choice/classes/dates.php index ede2d4ffcbb..05b89652c75 100644 --- a/mod/choice/classes/dates.php +++ b/mod/choice/classes/dates.php @@ -50,6 +50,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; $dates[] = [ + 'dataid' => 'timeopen', 'label' => get_string($openlabelid, 'course'), 'timestamp' => (int) $timeopen, ]; @@ -58,6 +59,7 @@ class dates extends activity_dates { if ($timeclose) { $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; $dates[] = [ + 'dataid' => 'timeclose', 'label' => get_string($closelabelid, 'course'), 'timestamp' => (int) $timeclose, ]; diff --git a/mod/choice/tests/dates_test.php b/mod/choice/tests/dates_test.php index a6ff4f9e9f8..b5c0d27f92e 100644 --- a/mod/choice/tests/dates_test.php +++ b/mod/choice/tests/dates_test.php @@ -56,30 +56,30 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, [ - ['label' => 'Opens:', 'timestamp' => $after], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'], ] ], 'only with closing time' => [ null, $after, [ - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'with both times' => [ $after, $later, [ - ['label' => 'Opens:', 'timestamp' => $after], - ['label' => 'Closes:', 'timestamp' => $later], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'], + ['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], 'between the dates' => [ $before, $after, [ - ['label' => 'Opened:', 'timestamp' => $before], - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeopen'], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'dates are past' => [ $earlier, $before, [ - ['label' => 'Opened:', 'timestamp' => $earlier], - ['label' => 'Closed:', 'timestamp' => $before], + ['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeclose'], ] ], ]; diff --git a/mod/data/classes/dates.php b/mod/data/classes/dates.php index 908662c5ad7..248bd30f38d 100644 --- a/mod/data/classes/dates.php +++ b/mod/data/classes/dates.php @@ -50,6 +50,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; $dates[] = [ + 'dataid' => 'timeavailablefrom', 'label' => get_string($openlabelid, 'course'), 'timestamp' => (int) $timeopen, ]; @@ -58,6 +59,7 @@ class dates extends activity_dates { if ($timeclose) { $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; $dates[] = [ + 'dataid' => 'timeavailableto', 'label' => get_string($closelabelid, 'course'), 'timestamp' => (int) $timeclose, ]; diff --git a/mod/data/tests/dates_test.php b/mod/data/tests/dates_test.php index 62f841eca0e..6fdd3494079 100644 --- a/mod/data/tests/dates_test.php +++ b/mod/data/tests/dates_test.php @@ -56,30 +56,30 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, [ - ['label' => 'Opens:', 'timestamp' => $after], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeavailablefrom'], ] ], 'only with closing time' => [ null, $after, [ - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeavailableto'], ] ], 'with both times' => [ $after, $later, [ - ['label' => 'Opens:', 'timestamp' => $after], - ['label' => 'Closes:', 'timestamp' => $later], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeavailablefrom'], + ['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeavailableto'], ] ], 'between the dates' => [ $before, $after, [ - ['label' => 'Opened:', 'timestamp' => $before], - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeavailablefrom'], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeavailableto'], ] ], 'dates are past' => [ $earlier, $before, [ - ['label' => 'Opened:', 'timestamp' => $earlier], - ['label' => 'Closed:', 'timestamp' => $before], + ['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeavailablefrom'], + ['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeavailableto'], ] ], ]; diff --git a/mod/feedback/classes/dates.php b/mod/feedback/classes/dates.php index b814cd871aa..e1e5db3d711 100644 --- a/mod/feedback/classes/dates.php +++ b/mod/feedback/classes/dates.php @@ -50,6 +50,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; $dates[] = [ + 'dataid' => 'timeopen', 'label' => get_string($openlabelid, 'course'), 'timestamp' => (int) $timeopen, ]; @@ -58,6 +59,7 @@ class dates extends activity_dates { if ($timeclose) { $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; $dates[] = [ + 'dataid' => 'timeclose', 'label' => get_string($closelabelid, 'course'), 'timestamp' => (int) $timeclose, ]; diff --git a/mod/feedback/tests/dates_test.php b/mod/feedback/tests/dates_test.php index 17e19851488..f37ba28a05f 100644 --- a/mod/feedback/tests/dates_test.php +++ b/mod/feedback/tests/dates_test.php @@ -56,30 +56,30 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, [ - ['label' => 'Opens:', 'timestamp' => $after], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'], ] ], 'only with closing time' => [ null, $after, [ - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'with both times' => [ $after, $later, [ - ['label' => 'Opens:', 'timestamp' => $after], - ['label' => 'Closes:', 'timestamp' => $later], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'], + ['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], 'between the dates' => [ $before, $after, [ - ['label' => 'Opened:', 'timestamp' => $before], - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeopen'], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'dates are past' => [ $earlier, $before, [ - ['label' => 'Opened:', 'timestamp' => $earlier], - ['label' => 'Closed:', 'timestamp' => $before], + ['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeclose'], ] ], ]; diff --git a/mod/forum/classes/dates.php b/mod/forum/classes/dates.php index 18814f996f1..4d44e8a05bc 100644 --- a/mod/forum/classes/dates.php +++ b/mod/forum/classes/dates.php @@ -47,6 +47,7 @@ class dates extends activity_dates { if ($duedate) { $dates[] = [ + 'dataid' => 'duedate', 'label' => get_string('activitydate:due', 'mod_forum'), 'timestamp' => (int) $duedate, ]; diff --git a/mod/forum/tests/dates_test.php b/mod/forum/tests/dates_test.php index e53517a95a4..6a304e3e867 100644 --- a/mod/forum/tests/dates_test.php +++ b/mod/forum/tests/dates_test.php @@ -54,12 +54,12 @@ class dates_test extends advanced_testcase { ], 'future due date' => [ $after, [ - ['label' => 'Due:', 'timestamp' => $after], + ['label' => 'Due:', 'timestamp' => $after, 'dataid' => 'duedate'], ] ], 'due date is past' => [ $before, [ - ['label' => 'Due:', 'timestamp' => $before], + ['label' => 'Due:', 'timestamp' => $before, 'dataid' => 'duedate'], ] ], ]; diff --git a/mod/lesson/classes/dates.php b/mod/lesson/classes/dates.php index cf18db24bd9..72f6d571a0b 100644 --- a/mod/lesson/classes/dates.php +++ b/mod/lesson/classes/dates.php @@ -50,6 +50,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; $dates[] = [ + 'dataid' => 'available', 'label' => get_string($openlabelid, 'course'), 'timestamp' => (int) $timeopen, ]; @@ -58,6 +59,7 @@ class dates extends activity_dates { if ($timeclose) { $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; $dates[] = [ + 'dataid' => 'deadline', 'label' => get_string($closelabelid, 'course'), 'timestamp' => (int) $timeclose, ]; diff --git a/mod/lesson/tests/dates_test.php b/mod/lesson/tests/dates_test.php index dbe906709cf..4d4345cb665 100644 --- a/mod/lesson/tests/dates_test.php +++ b/mod/lesson/tests/dates_test.php @@ -56,48 +56,48 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, null, null, null, null, [ - ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after], + ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after, 'dataid' => 'available'], ] ], 'only with closing time' => [ null, $after, null, null, null, null, [ - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after, 'dataid' => 'deadline'], ] ], 'with both times' => [ $after, $later, null, null, null, null, [ - ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after, 'dataid' => 'available'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'deadline'], ] ], 'between the dates' => [ $before, $after, null, null, null, null, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $before], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $before, 'dataid' => 'available'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after, 'dataid' => 'deadline'], ] ], 'dates are past' => [ $earlier, $before, null, null, null, null, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closed', 'course'), 'timestamp' => $before], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'available'], + ['label' => get_string('activitydate:closed', 'course'), 'timestamp' => $before, 'dataid' => 'deadline'], ] ], 'with user override' => [ $before, $after, $earlier, $later, null, null, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'available'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'deadline'], ] ], 'with group override' => [ $before, $after, null, null, $earlier, $later, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'available'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'deadline'], ] ], 'with both user and group overrides' => [ $before, $after, $earlier, $later, $earlier - DAYSECS, $later + DAYSECS, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'available'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'deadline'], ] ], ]; diff --git a/mod/quiz/classes/dates.php b/mod/quiz/classes/dates.php index ce0f6058406..4401d65dd14 100644 --- a/mod/quiz/classes/dates.php +++ b/mod/quiz/classes/dates.php @@ -50,6 +50,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; $dates[] = [ + 'dataid' => 'timeopen', 'label' => get_string($openlabelid, 'core_course'), 'timestamp' => (int) $timeopen, ]; @@ -58,6 +59,7 @@ class dates extends activity_dates { if ($timeclose) { $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; $dates[] = [ + 'dataid' => 'timeclose', 'label' => get_string($closelabelid, 'core_course'), 'timestamp' => (int) $timeclose, ]; diff --git a/mod/quiz/tests/dates_test.php b/mod/quiz/tests/dates_test.php index 372ba729d14..b550f1690ed 100644 --- a/mod/quiz/tests/dates_test.php +++ b/mod/quiz/tests/dates_test.php @@ -56,48 +56,48 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, null, null, null, null, [ - ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after], + ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after, 'dataid' => 'timeopen'], ] ], 'only with closing time' => [ null, $after, null, null, null, null, [ - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'with both times' => [ $after, $later, null, null, null, null, [ - ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opens', 'course'), 'timestamp' => $after, 'dataid' => 'timeopen'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], 'between the dates' => [ $before, $after, null, null, null, null, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $before], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $before, 'dataid' => 'timeopen'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'dates are past' => [ $earlier, $before, null, null, null, null, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closed', 'course'), 'timestamp' => $before], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => get_string('activitydate:closed', 'course'), 'timestamp' => $before, 'dataid' => 'timeclose'], ] ], 'with user override' => [ $before, $after, $earlier, $later, null, null, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], 'with group override' => [ $before, $after, null, null, $earlier, $later, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], 'with both user and group overrides' => [ $before, $after, $earlier, $later, $earlier - DAYSECS, $later + DAYSECS, [ - ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier], - ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later], + ['label' => get_string('activitydate:opened', 'course'), 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => get_string('activitydate:closes', 'course'), 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], ]; diff --git a/mod/scorm/classes/dates.php b/mod/scorm/classes/dates.php index 4b1bf7d9c50..e662ef87475 100644 --- a/mod/scorm/classes/dates.php +++ b/mod/scorm/classes/dates.php @@ -50,6 +50,7 @@ class dates extends activity_dates { if ($timeopen) { $openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened'; $dates[] = [ + 'dataid' => 'timeopen', 'label' => get_string($openlabelid, 'core_course'), 'timestamp' => (int) $timeopen, ]; @@ -58,6 +59,7 @@ class dates extends activity_dates { if ($timeclose) { $closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed'; $dates[] = [ + 'dataid' => 'timeclose', 'label' => get_string($closelabelid, 'core_course'), 'timestamp' => (int) $timeclose, ]; diff --git a/mod/scorm/tests/dates_test.php b/mod/scorm/tests/dates_test.php index 01a87888058..363e5444af9 100644 --- a/mod/scorm/tests/dates_test.php +++ b/mod/scorm/tests/dates_test.php @@ -56,30 +56,30 @@ class dates_test extends advanced_testcase { ], 'only with opening time' => [ $after, null, [ - ['label' => 'Opens:', 'timestamp' => $after], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'], ] ], 'only with closing time' => [ null, $after, [ - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'with both times' => [ $after, $later, [ - ['label' => 'Opens:', 'timestamp' => $after], - ['label' => 'Closes:', 'timestamp' => $later], + ['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'], + ['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeclose'], ] ], 'between the dates' => [ $before, $after, [ - ['label' => 'Opened:', 'timestamp' => $before], - ['label' => 'Closes:', 'timestamp' => $after], + ['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeopen'], + ['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'], ] ], 'dates are past' => [ $earlier, $before, [ - ['label' => 'Opened:', 'timestamp' => $earlier], - ['label' => 'Closed:', 'timestamp' => $before], + ['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeopen'], + ['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeclose'], ] ], ]; diff --git a/mod/workshop/classes/dates.php b/mod/workshop/classes/dates.php index b3ed3a6a6ed..ef328468ea3 100644 --- a/mod/workshop/classes/dates.php +++ b/mod/workshop/classes/dates.php @@ -53,6 +53,7 @@ class dates extends activity_dates { if ($submissionstart) { $openlabelid = $submissionstart > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened'; $dates[] = [ + 'dataid' => 'submissionstart', 'label' => get_string($openlabelid, 'mod_workshop'), 'timestamp' => (int) $submissionstart, ]; @@ -61,6 +62,7 @@ class dates extends activity_dates { if ($submissionend) { $closelabelid = $submissionend > $now ? 'activitydate:submissionsclose' : 'activitydate:submissionsclosed'; $dates[] = [ + 'dataid' => 'submissionend', 'label' => get_string($closelabelid, 'mod_workshop'), 'timestamp' => (int) $submissionend, ]; @@ -69,6 +71,7 @@ class dates extends activity_dates { if ($assessmentstart) { $openlabelid = $assessmentstart > $now ? 'activitydate:assessmentsopen' : 'activitydate:assessmentsopened'; $dates[] = [ + 'dataid' => 'assessmentstart', 'label' => get_string($openlabelid, 'mod_workshop'), 'timestamp' => (int) $assessmentstart, ]; @@ -77,6 +80,7 @@ class dates extends activity_dates { if ($assessmentend) { $closelabelid = $assessmentend > $now ? 'activitydate:assessmentsclose' : 'activitydate:assessmentsclosed'; $dates[] = [ + 'dataid' => 'assessmentend', 'label' => get_string($closelabelid, 'mod_workshop'), 'timestamp' => (int) $assessmentend, ]; diff --git a/mod/workshop/tests/dates_test.php b/mod/workshop/tests/dates_test.php index bf733302439..0484a5d146f 100644 --- a/mod/workshop/tests/dates_test.php +++ b/mod/workshop/tests/dates_test.php @@ -58,46 +58,46 @@ class dates_test extends advanced_testcase { ], 'only with start time for submissions' => [ $after, null, null, null, [ - ['label' => 'Submissions open:', 'timestamp' => $after], + ['label' => 'Submissions open:', 'timestamp' => $after, 'dataid' => 'submissionstart'], ] ], 'only with end time for submissions' => [ null, $after, null, null, [ - ['label' => 'Submissions close:', 'timestamp' => $after], + ['label' => 'Submissions close:', 'timestamp' => $after, 'dataid' => 'submissionend'], ] ], 'only with start time for assessments' => [ null, null, $after, null, [ - ['label' => 'Assessments open:', 'timestamp' => $after], + ['label' => 'Assessments open:', 'timestamp' => $after, 'dataid' => 'assessmentstart'], ] ], 'only with end time for assessments' => [ null, null, null, $after, [ - ['label' => 'Assessments close:', 'timestamp' => $after], + ['label' => 'Assessments close:', 'timestamp' => $after, 'dataid' => 'assessmentend'], ] ], 'all times in future' => [ $after, $later, $latest, $latest + DAYSECS, [ - ['label' => 'Submissions open:', 'timestamp' => $after], - ['label' => 'Submissions close:', 'timestamp' => $later], - ['label' => 'Assessments open:', 'timestamp' => $latest], - ['label' => 'Assessments close:', 'timestamp' => $latest + DAYSECS], + ['label' => 'Submissions open:', 'timestamp' => $after, 'dataid' => 'submissionstart'], + ['label' => 'Submissions close:', 'timestamp' => $later, 'dataid' => 'submissionend'], + ['label' => 'Assessments open:', 'timestamp' => $latest, 'dataid' => 'assessmentstart'], + ['label' => 'Assessments close:', 'timestamp' => $latest + DAYSECS, 'dataid' => 'assessmentend'], ] ], 'all times in the past' => [ $earliest - DAYSECS, $earliest, $earlier, $before, [ - ['label' => 'Submissions opened:', 'timestamp' => $earliest - DAYSECS], - ['label' => 'Submissions closed:', 'timestamp' => $earliest], - ['label' => 'Assessments opened:', 'timestamp' => $earlier], - ['label' => 'Assessments closed:', 'timestamp' => $before], + ['label' => 'Submissions opened:', 'timestamp' => $earliest - DAYSECS, 'dataid' => 'submissionstart'], + ['label' => 'Submissions closed:', 'timestamp' => $earliest, 'dataid' => 'submissionend'], + ['label' => 'Assessments opened:', 'timestamp' => $earlier, 'dataid' => 'assessmentstart'], + ['label' => 'Assessments closed:', 'timestamp' => $before, 'dataid' => 'assessmentend'], ] ], 'between submission and assessment' => [ $earlier, $before, $after, $later, [ - ['label' => 'Submissions opened:', 'timestamp' => $earlier], - ['label' => 'Submissions closed:', 'timestamp' => $before], - ['label' => 'Assessments open:', 'timestamp' => $after], - ['label' => 'Assessments close:', 'timestamp' => $later], + ['label' => 'Submissions opened:', 'timestamp' => $earlier, 'dataid' => 'submissionstart'], + ['label' => 'Submissions closed:', 'timestamp' => $before, 'dataid' => 'submissionend'], + ['label' => 'Assessments open:', 'timestamp' => $after, 'dataid' => 'assessmentstart'], + ['label' => 'Assessments close:', 'timestamp' => $later, 'dataid' => 'assessmentend'], ] ], ];