Permalink
Browse files

MDL-54729 mod_forum: clarify static variable usage

After some time discussing with integrators, we decided that this
slightly yukky solution probably fits safely, so just making its usage
better explained and speciifc.
  • Loading branch information...
danpoltawski committed Jun 7, 2016
1 parent 8dc6bb8 commit 906c52ee96899a31394cff787a6b79db62915550
Showing with 9 additions and 6 deletions.
  1. +9 −6 mod/forum/lib.php
View
@@ -3078,9 +3078,12 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
// String cache
static $str;
// As we should only have one element with the id of unread we keep track of whether this post is the first
// unread post.
static $firstunread = true;
// This is an extremely hacky way to ensure we only print the 'unread' anchor
// the first time we encounter an unread post on a page. Ideally this would
// be moved into the caller somehow, and be better testable. But at the time
// of dealing with this bug, this static workaround was the most surgical and
// it fits together with only printing th unread anchor id once on a given page.
static $firstunreadanchorprinted = false;
$modcontext = context_module::instance($cm->id);
@@ -3296,10 +3299,10 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
$forumpostclass = ' read';
} else {
$forumpostclass = ' unread';
// If this is the first unread post then give it an anchor and id of unread.
if ($firstunread) {
// If this is the first unread post printed then give it an anchor and id of unread.
if (!$firstunreadanchorprinted) {
$output .= html_writer::tag('a', '', array('id' => 'unread'));
$firstunread = false;
$firstunreadanchorprinted = true;
}
}
} else {

0 comments on commit 906c52e

Please sign in to comment.