Skip to content

Commit

Permalink
MDL-9070 forum: Show timed post display period
Browse files Browse the repository at this point in the history
This adds the following changes when viewing a list of discussions and
forum_enabletimedposts is turned on.

* Discussions a student wouldnt see right now are dimmed (timestart in
  future or timeend in the past).
* A icon appears next to the discussion subject, the tooltip for this
  icon displays the display start and/or end time. This only appears for
  the user that made the discussion or has permission to
  viewhiddentimedposts.

These two changes achieve a couple of important things, namely, teachers
will not mistakenly think their students can see a discussion when
viewing the list if they've later forgot that they set a time limit on
it (or indeed if someone else put it on their discussion without them
realising). Additionally it makes it easy to see from the list when
different discussions are set to be released without having to go in and
edit them to find out.

Change-Id: Ia1818b33c00adae0dad72df8e170a078fb66cd76
  • Loading branch information
aolley committed Sep 29, 2015
1 parent fd57d68 commit 05f1455
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 5 deletions.
2 changes: 2 additions & 0 deletions mod/forum/lang/en/forum.php
Expand Up @@ -483,7 +483,9 @@
$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';
Expand Down
25 changes: 20 additions & 5 deletions mod/forum/lib.php
Expand Up @@ -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;
Expand All @@ -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 '<tr class="discussion r'.$rowcount.'">';
echo '<tr class="discussion r'.$rowcount.$timedoutsidewindow.'">';

// Topic
echo '<td class="topic starter">';

$canalwaysseetimedpost = $USER->id == $post->userid || $canviewhiddentimedposts;
if ($timeddiscussion && $canalwaysseetimedpost) {
echo $PAGE->get_renderer('mod_forum')->timed_discussion_tooltip($post, empty($timedoutsidewindow));
}

echo '<a href="'.$CFG->wwwroot.'/mod/forum/discuss.php?d='.$post->discussion.'">'.$post->subject.'</a>';
echo "</td>\n";

Expand Down Expand Up @@ -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');

Expand Down Expand Up @@ -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;
Expand Down
22 changes: 22 additions & 0 deletions mod/forum/renderer.php
Expand Up @@ -160,5 +160,27 @@ public function subscribed_users(user_selector_base $existingusers) {
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'));
}
}
10 changes: 10 additions & 0 deletions mod/forum/styles.css
Expand Up @@ -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;
}
58 changes: 58 additions & 0 deletions 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"

0 comments on commit 05f1455

Please sign in to comment.