From 9d1b97c5d4c827f75c2205d38d3cf80eb9ba5dd2 Mon Sep 17 00:00:00 2001 From: martin Date: Tue, 6 Aug 2002 06:09:44 +0000 Subject: [PATCH] forum_print_discussion now checks to see whether there are any ratings that haven't been done yet on a discussion. If not, then it won't print the ratings form. This avoids a slight confusion about the interface that existed previously. --- mod/forum/lib.php | 42 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 38 insertions(+), 4 deletions(-) diff --git a/mod/forum/lib.php b/mod/forum/lib.php index 5b521bbc1c..bb52159574 100644 --- a/mod/forum/lib.php +++ b/mod/forum/lib.php @@ -305,6 +305,7 @@ function forum_print_search_form($course, $search="") { function forum_count_discussion_replies($forum="0") { +// Returns an array of counts of replies to each discussion (optionally in one forum) if ($forum) { $forumselect = " AND d.forum = '$forum'"; } @@ -314,6 +315,31 @@ function forum_count_discussion_replies($forum="0") { GROUP BY p.discussion"); } +function forum_count_unrated_posts($discussionid, $userid) { +// How many unrated posts are in the given discussion for a given user? + if ($posts = get_record_sql("SELECT count(*) as num + FROM forum_posts + WHERE parent > 0 AND + discussion = '$discussionid' AND + user <> '$userid' ")) { + + if ($rated = get_record_sql("SELECT count(*) as num + FROM forum_posts p, forum_ratings r + WHERE p.id = r.post AND r.user = '$userid'")) { + $difference = $posts->num - $rated->num; + if ($difference > 0) { + return $difference; + } else { + return 0; // Just in case there was a counting error + } + } else { + return $posts->num; + } + } else { + return 0; + } +} + function forum_set_return() { global $SESSION, $HTTP_REFERER; @@ -872,7 +898,15 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { forum_print_mode_form($discussion->id, $mode); + $ratingform = false; if ($forum->assessed && $USER->id) { + $unrated = forum_count_unrated_posts($discussion->id, $USER->id); + if ($unrated > 0) { + $ratingform = true; + } + } + + if ($ratingform) { echo "
"; echo "id\">"; } @@ -882,20 +916,20 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) { case -1 : // Flat descending default: echo ""; break; case 2 : // Threaded - forum_print_posts_threaded($post->id, $course->id, 0, $forum->assessed); + forum_print_posts_threaded($post->id, $course->id, 0, $ratingform); break; case 3 : // Nested - forum_print_posts_nested($post->id, $course->id, $forum->assessed); + forum_print_posts_nested($post->id, $course->id, $ratingform); break; } - if ($forum->assessed && $USER->id) { + if ($ratingform) { echo "

"; echo "
"; } -- 2.39.5