MDL-48822 mod_forum: Add lastpost class to final post in discussion
authorAndrew Nicols <andrew@nicols.co.uk>
Fri, 30 Jan 2015 02:14:01 +0000 (10:14 +0800)
committerAndrew Nicols <andrew@nicols.co.uk>
Thu, 5 Feb 2015 05:09:42 +0000 (13:09 +0800)
Thanks to Lior Gil for the basis of the suggested fix.

mod/forum/lib.php

index d400f47..e2b0f59 100644 (file)
@@ -1950,6 +1950,20 @@ function forum_get_all_discussion_posts($discussionid, $sort, $tracking=false) {
         $posts[$p->parent]->children[$pid] =& $posts[$pid];
     }
 
+    // Start with the last child of the first post.
+    $post = &$posts[reset($posts)->id];
+
+    $lastpost = false;
+    while (!$lastpost) {
+        if (!isset($post->children)) {
+            $post->lastpost = true;
+            $lastpost = true;
+        } else {
+             // Go to the last child of this post.
+            $post = &$posts[end($post->children)->id];
+        }
+    }
+
     return $posts;
 }
 
@@ -3377,6 +3391,10 @@ function forum_print_post($post, $discussion, $forum, &$cm, $course, $ownpost=fa
         $topicclass = ' firstpost starter';
     }
 
+    if (!empty($post->lastpost)) {
+        $forumpostclass = ' lastpost';
+    }
+
     $postbyuser = new stdClass;
     $postbyuser->post = $post->subject;
     $postbyuser->user = $postuser->fullname;