Skip to content

Commit

Permalink
MDL-31355 mod_forum: different message when duedate has passed
Browse files Browse the repository at this point in the history
  • Loading branch information
rezaies committed Apr 11, 2019
1 parent cbf63d8 commit 82482e3
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mod/forum/classes/local/renderers/discussion.php
Expand Up @@ -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())),
Expand Down
5 changes: 5 additions & 0 deletions mod/forum/classes/local/renderers/discussion_list.php
Expand Up @@ -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())),
Expand Down
1 change: 1 addition & 0 deletions mod/forum/lang/en/forum.php
Expand Up @@ -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';
Expand Down
20 changes: 20 additions & 0 deletions mod/forum/lib.php
Expand Up @@ -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.
*
Expand Down
48 changes: 48 additions & 0 deletions mod/forum/tests/lib_test.php
Expand Up @@ -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.
*/
Expand Down

0 comments on commit 82482e3

Please sign in to comment.