diff --git a/mod/forum/lang/en/forum.php b/mod/forum/lang/en/forum.php
index e5f2e4c232f..e7e7da0d7fc 100644
--- a/mod/forum/lang/en/forum.php
+++ b/mod/forum/lang/en/forum.php
@@ -483,7 +483,9 @@ $string['subscriptionauto'] = 'Auto subscription';
$string['subscriptiondisabled'] = 'Subscription disabled';
$string['subscriptions'] = 'Subscriptions';
$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['timedhidden'] = 'Timed status: Hidden from students';
$string['timedposts'] = 'Timed posts';
+$string['timedvisible'] = 'Timed status: Visible to all users';
$string['timestartenderror'] = 'Display end date cannot be earlier than the start date';
$string['trackforum'] = 'Track unread posts';
$string['tracking'] = 'Track';
diff --git a/mod/forum/lib.php b/mod/forum/lib.php
index 42f6db39301..016a47cf819 100644
--- a/mod/forum/lib.php
+++ b/mod/forum/lib.php
@@ -3722,11 +3722,13 @@ function mod_forum_rating_can_see_item_ratings($params) {
* @param boolean $cantrack Is tracking enabled for this forum.
* @param boolean $forumtracked Is the user tracking this forum.
* @param boolean $canviewparticipants True if user has the viewparticipants permission for this course
+ * @param boolean $canviewhiddentimedposts True if user has the viewhiddentimedposts permission for this forum
*/
-function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring="",
- $cantrack=true, $forumtracked=true, $canviewparticipants=true, $modcontext=NULL) {
+function forum_print_discussion_header(&$post, $forum, $group = -1, $datestring = "",
+ $cantrack = true, $forumtracked = true, $canviewparticipants = true, $modcontext = null,
+ $canviewhiddentimedposts = false) {
- global $COURSE, $USER, $CFG, $OUTPUT;
+ global $COURSE, $USER, $CFG, $OUTPUT, $PAGE;
static $rowcount;
static $strmarkalldread;
@@ -3747,11 +3749,23 @@ function forum_print_discussion_header(&$post, $forum, $group=-1, $datestring=""
$post->subject = format_string($post->subject,true);
+ $timeddiscussion = !empty($CFG->forum_enabletimedposts) && ($post->timestart || $post->timeend);
+ $timedoutsidewindow = '';
+ if ($timeddiscussion && ($post->timestart > time() || ($post->timeend != 0 && $post->timeend < time()))) {
+ $timedoutsidewindow = ' dimmed_text';
+ }
+
echo "\n\n";
- echo '
';
+ echo '
';
// Topic
echo '';
+
+ $canalwaysseetimedpost = $USER->id == $post->userid || $canviewhiddentimedposts;
+ if ($timeddiscussion && $canalwaysseetimedpost) {
+ echo $PAGE->get_renderer('mod_forum')->timed_discussion_tooltip($post, empty($timedoutsidewindow));
+ }
+
echo ''.$post->subject.'';
echo " | \n";
@@ -5437,6 +5451,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions = -1, $
}
$canviewparticipants = has_capability('moodle/course:viewparticipants',$context);
+ $canviewhiddentimedposts = has_capability('mod/forum:viewhiddentimedposts', $context);
$strdatestring = get_string('strftimerecentfull');
@@ -5536,7 +5551,7 @@ function forum_print_latest_discussions($course, $forum, $maxdiscussions = -1, $
$group = -1;
}
forum_print_discussion_header($discussion, $forum, $group, $strdatestring, $cantrack, $forumtracked,
- $canviewparticipants, $context);
+ $canviewparticipants, $context, $canviewhiddentimedposts);
break;
default:
$link = false;
diff --git a/mod/forum/renderer.php b/mod/forum/renderer.php
index bcfb656c2f7..c38ebc94ba6 100644
--- a/mod/forum/renderer.php
+++ b/mod/forum/renderer.php
@@ -160,5 +160,27 @@ class mod_forum_renderer extends plugin_renderer_base {
return $output;
}
+ /**
+ * Generate the HTML for an icon to be displayed beside the subject of a timed discussion.
+ *
+ * @param object $discussion
+ * @param bool $visiblenow Indicicates that the discussion is currently
+ * visible to all users.
+ * @return string
+ */
+ public function timed_discussion_tooltip($discussion, $visiblenow) {
+ $dates = array();
+ if ($discussion->timestart) {
+ $dates[] = get_string('displaystart', 'mod_forum').': '.userdate($discussion->timestart);
+ }
+ if ($discussion->timeend) {
+ $dates[] = get_string('displayend', 'mod_forum').': '.userdate($discussion->timeend);
+ }
+ $str = $visiblenow ? 'timedvisible' : 'timedhidden';
+ $dates[] = get_string($str, 'mod_forum');
+
+ $tooltip = implode("\n", $dates);
+ return $this->pix_icon('i/calendar', $tooltip, 'moodle', array('class' => 'smallicon timedpost'));
+ }
}
diff --git a/mod/forum/styles.css b/mod/forum/styles.css
index a5914d712fd..2d1b0b3854e 100644
--- a/mod/forum/styles.css
+++ b/mod/forum/styles.css
@@ -165,3 +165,13 @@ span.unread {
.dir-rtl .path-mod-forum .discussionsubscription {
text-align: left;
}
+
+#page-mod-forum-view img.timedpost {
+ margin-right: 5px;
+}
+
+.dir-rtl#page-mod-forum-view img.timedpost {
+ margin-right: 0px;
+ margin-left: 5px;
+ float: right;
+}
diff --git a/mod/forum/tests/behat/timed_discussions.feature b/mod/forum/tests/behat/timed_discussions.feature
new file mode 100644
index 00000000000..8af7bd14b14
--- /dev/null
+++ b/mod/forum/tests/behat/timed_discussions.feature
@@ -0,0 +1,58 @@
+@mod @mod_forum
+Feature: Users can choose to set start and end time for display of their discussions
+ In order to see timed forum discussions
+ As a user
+ I need to view the page within the window
+ As a user with viewhiddentimedposts
+ I need to see the timed discussion tooltips
+
+ Background:
+ Given the following "users" exist:
+ | username | firstname | lastname | email |
+ | student1 | Student | 1 | student1@example.com |
+ And the following "courses" exist:
+ | fullname | shortname | category |
+ | Course 1 | C1 | 0 |
+ And the following "course enrolments" exist:
+ | user | course | role |
+ | student1 | C1 | student |
+ And I log in as "admin"
+ And the following config values are set as admin:
+ | forum_enabletimedposts | 1 |
+ And I am on site homepage
+ And I follow "Course 1"
+ And I turn editing mode on
+ And I add a "Forum" to section "1" and I fill the form with:
+ | Forum name | Test forum name |
+ | Description | Test forum description |
+ And I add a new discussion to "Test forum name" forum with:
+ | Subject | Discussion 1 |
+ | Message | Discussion contents 1, first message |
+ And I add a new discussion to "Test forum name" forum with:
+ | Subject | Discussion 2 timed not visible |
+ | Message | Discussion contents 2, first message |
+ | timeend[enabled] | 1 |
+ | timeend[year] | 2014 |
+ And I add a new discussion to "Test forum name" forum with:
+ | Subject | Discussion 3 timed visible now |
+ | Message | Discussion contents 3, first message |
+ | timestart[enabled] | 1 |
+
+
+ Scenario: Creator of the discussion should see the tooltip
+ Given I am on site homepage
+ And I follow "Course 1"
+ And I follow "Test forum name"
+ Then I should see "Discussion 2 timed"
+ And I should see "Discussion 3 timed"
+ And ".timedpost" "css_element" should exist
+
+ Scenario: Student should not see the tooltip or the discussion
+ Given I log out
+ And I log in as "student1"
+ And I follow "Course 1"
+ Given I follow "Test forum name"
+ And I should see "Discussion 1"
+ Then I should not see "Discussion 2 timed"
+ And ".timedpost" "css_element" should not exist
+ But I should see "Discussion 3 timed"