diff --git a/mod/forum/classes/local/renderers/discussion.php b/mod/forum/classes/local/renderers/discussion.php index dcc59caffb0d6..500bc75e8f8d7 100644 --- a/mod/forum/classes/local/renderers/discussion.php +++ b/mod/forum/classes/local/renderers/discussion.php @@ -382,6 +382,11 @@ private function get_notifications($user) : array { get_string('cutoffdatereached', 'forum'), notification::NOTIFY_INFO ))->set_show_closebutton(); + } else if ($forum->is_due_date_reached()) { + $notifications[] = (new notification( + get_string('thisforumisdue', 'forum', userdate($forum->get_due_date())), + notification::NOTIFY_INFO + ))->set_show_closebutton(); } else if ($forum->has_due_date()) { $notifications[] = (new notification( get_string('thisforumhasduedate', 'forum', userdate($forum->get_due_date())), diff --git a/mod/forum/classes/local/renderers/discussion_list.php b/mod/forum/classes/local/renderers/discussion_list.php index f62a76986b46e..cd4ce425ef4a9 100644 --- a/mod/forum/classes/local/renderers/discussion_list.php +++ b/mod/forum/classes/local/renderers/discussion_list.php @@ -332,6 +332,11 @@ private function get_notifications(stdClass $user, ?int $groupid) : array { get_string('cutoffdatereached', 'forum'), notification::NOTIFY_INFO ))->set_show_closebutton(); + } else if ($forum->is_due_date_reached()) { + $notifications[] = (new notification( + get_string('thisforumisdue', 'forum', userdate($forum->get_due_date())), + notification::NOTIFY_INFO + ))->set_show_closebutton(); } else if ($forum->has_due_date()) { $notifications[] = (new notification( get_string('thisforumhasduedate', 'forum', userdate($forum->get_due_date())), diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php index c898e519ff204..7ae8c1c288652 100644 --- a/mod/forum/lang/en/forum.php +++ b/mod/forum/lang/en/forum.php @@ -589,6 +589,7 @@ $string['tagarea_forum_posts'] = 'Forum posts'; $string['tagsdeleted'] = 'Forum tags have been deleted'; $string['thisforumisthrottled'] = 'This forum has a limit to the number of forum postings you can make in a given time period - this is currently set at {$a->blockafter} posting(s) in {$a->blockperiod}'; +$string['thisforumisdue'] = 'The due date for posting to this forum was {$a}.'; $string['thisforumhasduedate'] = 'The due date for posting to this forum is {$a}.'; $string['timedhidden'] = 'Timed status: Hidden from students'; $string['timedposts'] = 'Timed posts'; diff --git a/mod/forum/lib.php b/mod/forum/lib.php index d7c8851b2abc3..57d8d717295c0 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -6337,6 +6337,26 @@ function forum_is_cutoff_date_reached($forum) { return $forumentity->is_cutoff_date_reached(); } +/** + * Determine whether the specified forum's due date is reached. + * + * @param stdClass $forum The forum + * @return bool + */ +function forum_is_due_date_reached($forum) { + $entityfactory = \mod_forum\local\container::get_entity_factory(); + $coursemoduleinfo = get_fast_modinfo($forum->course); + $cminfo = $coursemoduleinfo->instances['forum'][$forum->id]; + $forumentity = $entityfactory->get_forum_from_stdclass( + $forum, + context_module::instance($cminfo->id), + $cminfo->get_course_module_record(), + $cminfo->get_course() + ); + + return $forumentity->is_due_date_reached(); +} + /** * Determine whether the specified discussion is time-locked. * diff --git a/mod/forum/tests/lib_test.php b/mod/forum/tests/lib_test.php index 88f773272982d..496de01be5c41 100644 --- a/mod/forum/tests/lib_test.php +++ b/mod/forum/tests/lib_test.php @@ -3218,6 +3218,54 @@ public function forum_is_cutoff_date_reached_provider() { ]; } + /** + * Test the forum_is_due_date_reached function. + * + * @dataProvider forum_is_due_date_reached_provider + * @param stdClass $forum + * @param bool $expect + */ + public function test_forum_is_due_date_reached($forum, $expect) { + $this->resetAfterTest(); + + $this->setAdminUser(); + + $datagenerator = $this->getDataGenerator(); + $course = $datagenerator->create_course(); + $forum = $datagenerator->create_module('forum', (object) array_merge([ + 'course' => $course->id + ], $forum)); + + $this->assertEquals($expect, forum_is_due_date_reached($forum)); + } + + /** + * Dataprovider for forum_is_due_date_reached tests. + * + * @return array + */ + public function forum_is_due_date_reached_provider() { + $now = time(); + return [ + 'duedate is unset' => [ + [], + false + ], + 'duedate is 0' => [ + ['duedate' => 0], + false + ], + 'duedate is set and is in future' => [ + ['duedate' => $now + 86400], + false + ], + 'duedate is set and is in past' => [ + ['duedate' => $now - 86400], + true + ], + ]; + } + /** * Test that {@link forum_update_post()} keeps correct forum_discussions usermodified. */