Skip to content
Permalink
Browse files

MDL-31355 mod_forum: different message when duedate has passed

  • Loading branch information...
rezaies committed Mar 19, 2019
1 parent cbf63d8 commit 82482e3d3e826d93feb8ffd95b2227544922a4ee
@@ -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())),
@@ -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())),
@@ -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';
@@ -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.
*
@@ -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.
*/

0 comments on commit 82482e3

Please sign in to comment.
You can’t perform that action at this time.