Skip to content

Commit f9af45e

Browse files
committed
Merge branch 'MDL-75058-master' of https://github.com/jleyva/moodle
2 parents 4afcb0d + 51c9c70 commit f9af45e

File tree

22 files changed

+192
-97
lines changed

22 files changed

+192
-97
lines changed

course/externallib.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -478,6 +478,9 @@ public static function get_course_contents_returns() {
478478
array(
479479
'label' => new external_value(PARAM_TEXT, 'date label'),
480480
'timestamp' => new external_value(PARAM_INT, 'date timestamp'),
481+
'relativeto' => new external_value(PARAM_INT, 'relative date timestamp',
482+
VALUE_OPTIONAL),
483+
'dataid' => new external_value(PARAM_NOTAGS, 'cm data id', VALUE_OPTIONAL),
481484
)
482485
),
483486
VALUE_DEFAULT,

course/tests/externallib_test.php

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1655,6 +1655,59 @@ public function test_get_course_contents_hiddensections() {
16551655
$this->assertEquals(-1, $sections[5]['id']);
16561656
}
16571657

1658+
/**
1659+
* Test get course contents dates.
1660+
*/
1661+
public function test_get_course_contents_dates() {
1662+
$this->resetAfterTest(true);
1663+
1664+
$this->setAdminUser();
1665+
set_config('enablecourserelativedates', 1);
1666+
1667+
// Course with just main section.
1668+
$timenow = time();
1669+
$course = self::getDataGenerator()->create_course(
1670+
['numsections' => 0, 'relativedatesmode' => true, 'startdate' => $timenow - DAYSECS]);
1671+
1672+
$teacher = self::getDataGenerator()->create_user();
1673+
self::getDataGenerator()->enrol_user($teacher->id, $course->id, 'editingteacher');
1674+
1675+
$this->setUser($teacher);
1676+
1677+
// Create resource (empty dates).
1678+
$resource = self::getDataGenerator()->create_module('resource', ['course' => $course->id]);
1679+
// Create activities with dates.
1680+
$resource = self::getDataGenerator()->create_module('forum', ['course' => $course->id, 'duedate' => $timenow]);
1681+
$resource = self::getDataGenerator()->create_module('choice',
1682+
['course' => $course->id, 'timeopen' => $timenow, 'timeclose' => $timenow + DAYSECS]);
1683+
$resource = self::getDataGenerator()->create_module('assign',
1684+
['course' => $course->id, 'allowsubmissionsfromdate' => $timenow]);
1685+
1686+
$result = core_course_external::get_course_contents($course->id);
1687+
$result = external_api::clean_returnvalue(core_course_external::get_course_contents_returns(), $result);
1688+
1689+
foreach ($result[0]['modules'] as $module) {
1690+
if ($module['modname'] == 'resource') {
1691+
$this->assertEmpty($module['dates']);
1692+
} else if ($module['modname'] == 'forum') {
1693+
$this->assertCount(1, $module['dates']);
1694+
$this->assertEquals('duedate', $module['dates'][0]['dataid']);
1695+
$this->assertEquals($timenow, $module['dates'][0]['timestamp']);
1696+
} else if ($module['modname'] == 'choice') {
1697+
$this->assertCount(2, $module['dates']);
1698+
$this->assertEquals('timeopen', $module['dates'][0]['dataid']);
1699+
$this->assertEquals($timenow, $module['dates'][0]['timestamp']);
1700+
$this->assertEquals('timeclose', $module['dates'][1]['dataid']);
1701+
$this->assertEquals($timenow + DAYSECS, $module['dates'][1]['timestamp']);
1702+
} else if ($module['modname'] == 'assign') {
1703+
$this->assertCount(1, $module['dates']);
1704+
$this->assertEquals('allowsubmissionsfromdate', $module['dates'][0]['dataid']);
1705+
$this->assertEquals($timenow, $module['dates'][0]['timestamp']);
1706+
$this->assertEquals($course->startdate, $module['dates'][0]['relativeto']);
1707+
}
1708+
}
1709+
}
1710+
16581711
/**
16591712
* Test duplicate_course
16601713
*/

mod/assign/classes/dates.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ protected function get_dates(): array {
7272
if ($timeopen) {
7373
$openlabelid = $timeopen > $now ? 'activitydate:submissionsopen' : 'activitydate:submissionsopened';
7474
$date = [
75+
'dataid' => 'allowsubmissionsfromdate',
7576
'label' => get_string($openlabelid, 'mod_assign'),
7677
'timestamp' => (int) $timeopen,
7778
];
@@ -83,6 +84,7 @@ protected function get_dates(): array {
8384

8485
if ($timedue) {
8586
$date = [
87+
'dataid' => 'duedate',
8688
'label' => get_string('activitydate:submissionsdue', 'mod_assign'),
8789
'timestamp' => (int) $timedue,
8890
];

mod/assign/tests/dates_test.php

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,48 +56,62 @@ public function get_dates_for_module_provider(): array {
5656
],
5757
'only with opening time' => [
5858
$after, null, null, null, null, null, [
59-
['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after],
59+
['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after,
60+
'dataid' => 'allowsubmissionsfromdate'],
6061
]
6162
],
6263
'only with closing time' => [
6364
null, $after, null, null, null, null, [
64-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after],
65+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after,
66+
'dataid' => 'duedate'],
6567
]
6668
],
6769
'with both times' => [
6870
$after, $later, null, null, null, null, [
69-
['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after],
70-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later],
71+
['label' => get_string('activitydate:submissionsopen', 'mod_assign'), 'timestamp' => $after,
72+
'dataid' => 'allowsubmissionsfromdate'],
73+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later,
74+
'dataid' => 'duedate'],
7175
]
7276
],
7377
'between the dates' => [
7478
$before, $after, null, null, null, null, [
75-
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $before],
76-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after],
79+
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $before,
80+
'dataid' => 'allowsubmissionsfromdate'],
81+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $after,
82+
'dataid' => 'duedate'],
7783
]
7884
],
7985
'dates are past' => [
8086
$earlier, $before, null, null, null, null, [
81-
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier],
82-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $before],
87+
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier,
88+
'dataid' => 'allowsubmissionsfromdate'],
89+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $before,
90+
'dataid' => 'duedate'],
8391
]
8492
],
8593
'with user override' => [
8694
$before, $after, $earlier, $later, null, null, [
87-
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier],
88-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later],
95+
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier,
96+
'dataid' => 'allowsubmissionsfromdate'],
97+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later,
98+
'dataid' => 'duedate'],
8999
]
90100
],
91101
'with group override' => [
92102
$before, $after, null, null, $earlier, $later, [
93-
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier],
94-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later],
103+
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier,
104+
'dataid' => 'allowsubmissionsfromdate'],
105+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later,
106+
'dataid' => 'duedate'],
95107
]
96108
],
97109
'with both user and group overrides' => [
98110
$before, $after, $earlier, $later, $earlier - DAYSECS, $later + DAYSECS, [
99-
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier],
100-
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later],
111+
['label' => get_string('activitydate:submissionsopened', 'mod_assign'), 'timestamp' => $earlier,
112+
'dataid' => 'allowsubmissionsfromdate'],
113+
['label' => get_string('activitydate:submissionsdue', 'mod_assign'), 'timestamp' => $later,
114+
'dataid' => 'duedate'],
101115
]
102116
],
103117
];

mod/chat/classes/dates.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ protected function get_dates(): array {
4646
if (!empty($chat->schedule) && $chattime > $now) {
4747
return [
4848
[
49+
'dataid' => 'chattime',
4950
'label' => get_string('nextchattime', 'mod_chat'),
5051
'timestamp' => (int) $chattime
5152
]

mod/chat/tests/dates_test.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,39 +62,44 @@ public function get_dates_for_module_provider(): array {
6262
$future, CHAT_SCHEDULE_SINGLE, [
6363
[
6464
'label' => $label,
65-
'timestamp' => $future
65+
'timestamp' => $future,
66+
'dataid' => 'chattime',
6667
],
6768
]
6869
],
6970
'future chattime weekly' => [
7071
$future, CHAT_SCHEDULE_WEEKLY, [
7172
[
7273
'label' => $label,
73-
'timestamp' => $future
74+
'timestamp' => $future,
75+
'dataid' => 'chattime',
7476
]
7577
]
7678
],
7779
'future chattime daily' => [
7880
$future, CHAT_SCHEDULE_DAILY, [
7981
[
8082
'label' => $label,
81-
'timestamp' => $future
83+
'timestamp' => $future,
84+
'dataid' => 'chattime',
8285
]
8386
]
8487
],
8588
'past chattime daily' => [
8689
$past, CHAT_SCHEDULE_DAILY, [
8790
[
8891
'label' => $label,
89-
'timestamp' => $dailynextchattime
92+
'timestamp' => $dailynextchattime,
93+
'dataid' => 'chattime',
9094
],
9195
]
9296
],
9397
'past chattime weekly' => [
9498
$past, CHAT_SCHEDULE_WEEKLY, [
9599
[
96100
'label' => $label,
97-
'timestamp' => $weeklynextchattime
101+
'timestamp' => $weeklynextchattime,
102+
'dataid' => 'chattime',
98103
],
99104
]
100105
],

mod/choice/classes/dates.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function get_dates(): array {
5050
if ($timeopen) {
5151
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
5252
$dates[] = [
53+
'dataid' => 'timeopen',
5354
'label' => get_string($openlabelid, 'course'),
5455
'timestamp' => (int) $timeopen,
5556
];
@@ -58,6 +59,7 @@ protected function get_dates(): array {
5859
if ($timeclose) {
5960
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
6061
$dates[] = [
62+
'dataid' => 'timeclose',
6163
'label' => get_string($closelabelid, 'course'),
6264
'timestamp' => (int) $timeclose,
6365
];

mod/choice/tests/dates_test.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ public function get_dates_for_module_provider(): array {
5656
],
5757
'only with opening time' => [
5858
$after, null, [
59-
['label' => 'Opens:', 'timestamp' => $after],
59+
['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'],
6060
]
6161
],
6262
'only with closing time' => [
6363
null, $after, [
64-
['label' => 'Closes:', 'timestamp' => $after],
64+
['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'],
6565
]
6666
],
6767
'with both times' => [
6868
$after, $later, [
69-
['label' => 'Opens:', 'timestamp' => $after],
70-
['label' => 'Closes:', 'timestamp' => $later],
69+
['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'],
70+
['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeclose'],
7171
]
7272
],
7373
'between the dates' => [
7474
$before, $after, [
75-
['label' => 'Opened:', 'timestamp' => $before],
76-
['label' => 'Closes:', 'timestamp' => $after],
75+
['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeopen'],
76+
['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'],
7777
]
7878
],
7979
'dates are past' => [
8080
$earlier, $before, [
81-
['label' => 'Opened:', 'timestamp' => $earlier],
82-
['label' => 'Closed:', 'timestamp' => $before],
81+
['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeopen'],
82+
['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeclose'],
8383
]
8484
],
8585
];

mod/data/classes/dates.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function get_dates(): array {
5050
if ($timeopen) {
5151
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
5252
$dates[] = [
53+
'dataid' => 'timeavailablefrom',
5354
'label' => get_string($openlabelid, 'course'),
5455
'timestamp' => (int) $timeopen,
5556
];
@@ -58,6 +59,7 @@ protected function get_dates(): array {
5859
if ($timeclose) {
5960
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
6061
$dates[] = [
62+
'dataid' => 'timeavailableto',
6163
'label' => get_string($closelabelid, 'course'),
6264
'timestamp' => (int) $timeclose,
6365
];

mod/data/tests/dates_test.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ public function get_dates_for_module_provider(): array {
5656
],
5757
'only with opening time' => [
5858
$after, null, [
59-
['label' => 'Opens:', 'timestamp' => $after],
59+
['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeavailablefrom'],
6060
]
6161
],
6262
'only with closing time' => [
6363
null, $after, [
64-
['label' => 'Closes:', 'timestamp' => $after],
64+
['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeavailableto'],
6565
]
6666
],
6767
'with both times' => [
6868
$after, $later, [
69-
['label' => 'Opens:', 'timestamp' => $after],
70-
['label' => 'Closes:', 'timestamp' => $later],
69+
['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeavailablefrom'],
70+
['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeavailableto'],
7171
]
7272
],
7373
'between the dates' => [
7474
$before, $after, [
75-
['label' => 'Opened:', 'timestamp' => $before],
76-
['label' => 'Closes:', 'timestamp' => $after],
75+
['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeavailablefrom'],
76+
['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeavailableto'],
7777
]
7878
],
7979
'dates are past' => [
8080
$earlier, $before, [
81-
['label' => 'Opened:', 'timestamp' => $earlier],
82-
['label' => 'Closed:', 'timestamp' => $before],
81+
['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeavailablefrom'],
82+
['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeavailableto'],
8383
]
8484
],
8585
];

mod/feedback/classes/dates.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ protected function get_dates(): array {
5050
if ($timeopen) {
5151
$openlabelid = $timeopen > $now ? 'activitydate:opens' : 'activitydate:opened';
5252
$dates[] = [
53+
'dataid' => 'timeopen',
5354
'label' => get_string($openlabelid, 'course'),
5455
'timestamp' => (int) $timeopen,
5556
];
@@ -58,6 +59,7 @@ protected function get_dates(): array {
5859
if ($timeclose) {
5960
$closelabelid = $timeclose > $now ? 'activitydate:closes' : 'activitydate:closed';
6061
$dates[] = [
62+
'dataid' => 'timeclose',
6163
'label' => get_string($closelabelid, 'course'),
6264
'timestamp' => (int) $timeclose,
6365
];

mod/feedback/tests/dates_test.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -56,30 +56,30 @@ public function get_dates_for_module_provider(): array {
5656
],
5757
'only with opening time' => [
5858
$after, null, [
59-
['label' => 'Opens:', 'timestamp' => $after],
59+
['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'],
6060
]
6161
],
6262
'only with closing time' => [
6363
null, $after, [
64-
['label' => 'Closes:', 'timestamp' => $after],
64+
['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'],
6565
]
6666
],
6767
'with both times' => [
6868
$after, $later, [
69-
['label' => 'Opens:', 'timestamp' => $after],
70-
['label' => 'Closes:', 'timestamp' => $later],
69+
['label' => 'Opens:', 'timestamp' => $after, 'dataid' => 'timeopen'],
70+
['label' => 'Closes:', 'timestamp' => $later, 'dataid' => 'timeclose'],
7171
]
7272
],
7373
'between the dates' => [
7474
$before, $after, [
75-
['label' => 'Opened:', 'timestamp' => $before],
76-
['label' => 'Closes:', 'timestamp' => $after],
75+
['label' => 'Opened:', 'timestamp' => $before, 'dataid' => 'timeopen'],
76+
['label' => 'Closes:', 'timestamp' => $after, 'dataid' => 'timeclose'],
7777
]
7878
],
7979
'dates are past' => [
8080
$earlier, $before, [
81-
['label' => 'Opened:', 'timestamp' => $earlier],
82-
['label' => 'Closed:', 'timestamp' => $before],
81+
['label' => 'Opened:', 'timestamp' => $earlier, 'dataid' => 'timeopen'],
82+
['label' => 'Closed:', 'timestamp' => $before, 'dataid' => 'timeclose'],
8383
]
8484
],
8585
];

mod/forum/classes/dates.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ protected function get_dates(): array {
4747

4848
if ($duedate) {
4949
$dates[] = [
50+
'dataid' => 'duedate',
5051
'label' => get_string('activitydate:due', 'mod_forum'),
5152
'timestamp' => (int) $duedate,
5253
];

0 commit comments

Comments
 (0)