Only print the ratings button if there are ratings to be made.

This commit is contained in:
moodler 2003-10-09 16:36:09 +00:00
parent be7a0ebb09
commit 74f5d1e381

View file

@ -1097,6 +1097,7 @@ function forum_make_mail_post(&$post, $user, $touser, $course,
function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false, function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link=false,
$ratings=NULL, $footer="", $highlight="") { $ratings=NULL, $footer="", $highlight="") {
global $THEME, $USER, $CFG; global $THEME, $USER, $CFG;
static $stredit, $strdelete, $strreply, $strparent, $threadedmode; static $stredit, $strdelete, $strreply, $strparent, $threadedmode;
@ -1194,6 +1195,8 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
echo "</p>"; echo "</p>";
echo "<div align=right><p align=right>"; echo "<div align=right><p align=right>";
$ratingsmenuused = false;
if (!empty($ratings) and !empty($USER->id)) { if (!empty($ratings) and !empty($USER->id)) {
$useratings = true; $useratings = true;
if ($ratings->assesstimestart and $ratings->assesstimefinish) { if ($ratings->assesstimestart and $ratings->assesstimefinish) {
@ -1206,11 +1209,13 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
forum_print_ratings_mean($post->id, $ratings->scale); forum_print_ratings_mean($post->id, $ratings->scale);
if ($USER->id != $post->userid) { if ($USER->id != $post->userid) {
forum_print_rating_menu($post->id, $USER->id, $ratings->scale); forum_print_rating_menu($post->id, $USER->id, $ratings->scale);
$ratingsmenuused = true;
} }
} else if ($USER->id == $post->userid) { } else if ($USER->id == $post->userid) {
forum_print_ratings_mean($post->id, $ratings->scale); forum_print_ratings_mean($post->id, $ratings->scale);
} else if (!empty($ratings->allow) ) { } else if (!empty($ratings->allow) ) {
forum_print_rating_menu($post->id, $USER->id, $ratings->scale); forum_print_rating_menu($post->id, $USER->id, $ratings->scale);
$ratingsmenuused = true;
} }
} }
} }
@ -1221,7 +1226,8 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
} else { } else {
$replystring = get_string("repliesmany", "forum", $post->replies); $replystring = get_string("repliesmany", "forum", $post->replies);
} }
echo "<a href=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><b>".get_string("discussthistopic", "forum")."</b></a> ($replystring)&nbsp;&nbsp;"; echo "<a href=\"$CFG->wwwroot/mod/forum/discuss.php?d=$post->discussion\"><b>".
get_string("discussthistopic", "forum")."</b></a> ($replystring)&nbsp;&nbsp;";
} }
echo "</p>"; echo "</p>";
if ($footer) { if ($footer) {
@ -1229,6 +1235,8 @@ function forum_print_post(&$post, $courseid, $ownpost=false, $reply=false, $link
} }
echo "</div>"; echo "</div>";
echo "</td></tr>\n</table>\n\n"; echo "</td></tr>\n</table>\n\n";
return $ratingsmenuused;
} }
@ -2077,6 +2085,7 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) {
$reply = forum_user_can_post($forum); $reply = forum_user_can_post($forum);
$ratings = NULL; $ratings = NULL;
$ratingsmenuused = false;
if ($forum->assessed and !empty($USER->id)) { if ($forum->assessed and !empty($USER->id)) {
if ($ratings->scale = make_grades_menu($forum->scale)) { if ($ratings->scale = make_grades_menu($forum->scale)) {
$ratings->assesstimestart = $forum->assesstimestart; $ratings->assesstimestart = $forum->assesstimestart;
@ -2091,27 +2100,35 @@ function forum_print_discussion($course, $forum, $discussion, $post, $mode) {
} }
} }
forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $ratings); if (forum_print_post($post, $course->id, $ownpost, $reply, $link=false, $ratings)) {
$ratingsmenuused = true;
}
switch ($mode) { switch ($mode) {
case FORUM_MODE_FLATOLDEST : case FORUM_MODE_FLATOLDEST :
case FORUM_MODE_FLATNEWEST : case FORUM_MODE_FLATNEWEST :
default: default:
echo "<ul>"; echo "<ul>";
forum_print_posts_flat($post->discussion, $course->id, $mode, $ratings, $reply); if (forum_print_posts_flat($post->discussion, $course->id, $mode, $ratings, $reply)) {
$ratingsmenuused = true;
}
echo "</ul>"; echo "</ul>";
break; break;
case FORUM_MODE_THREADED : case FORUM_MODE_THREADED :
forum_print_posts_threaded($post->id, $course->id, 0, $ratings, $reply); if (forum_print_posts_threaded($post->id, $course->id, 0, $ratings, $reply)) {
$ratingsmenuused = true;
}
break; break;
case FORUM_MODE_NESTED : case FORUM_MODE_NESTED :
forum_print_posts_nested($post->id, $course->id, $ratings, $reply); if (forum_print_posts_nested($post->id, $course->id, $ratings, $reply)) {
$ratingsmenuused = true;
}
break; break;
} }
if ($ratings) { if ($ratingsmenuused) {
echo "<center><input type=\"submit\" value=\"".get_string("sendinratings", "forum")."\">"; echo "<center><input type=\"submit\" value=\"".get_string("sendinratings", "forum")."\">";
if ($forum->scale < 0) { if ($forum->scale < 0) {
if ($scale = get_record("scale", "id", abs($forum->scale))) { if ($scale = get_record("scale", "id", abs($forum->scale))) {
@ -2127,6 +2144,7 @@ function forum_print_posts_flat($discussion, $course, $direction, $ratings, $rep
global $USER; global $USER;
$link = false; $link = false;
$ratingsmenuused = false;
if ($direction < 0) { if ($direction < 0) {
$sort = "ORDER BY created DESC"; $sort = "ORDER BY created DESC";
@ -2137,17 +2155,20 @@ function forum_print_posts_flat($discussion, $course, $direction, $ratings, $rep
if ($posts = forum_get_discussion_posts($discussion, $sort)) { if ($posts = forum_get_discussion_posts($discussion, $sort)) {
foreach ($posts as $post) { foreach ($posts as $post) {
$ownpost = ($USER->id == $post->userid); $ownpost = ($USER->id == $post->userid);
forum_print_post($post, $course, $ownpost, $reply, $link, $ratings); if (forum_print_post($post, $course, $ownpost, $reply, $link, $ratings)) {
$ratingsmenuused = true;
} }
} else {
return;
} }
}
return $ratingsmenuused;
} }
function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply) { function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply) {
global $USER; global $USER;
$link = false; $link = false;
$ratingsmenuused = false;
if ($posts = forum_get_child_posts($parent)) { if ($posts = forum_get_child_posts($parent)) {
foreach ($posts as $post) { foreach ($posts as $post) {
@ -2155,7 +2176,9 @@ function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply)
echo "<ul>"; echo "<ul>";
if ($depth > 0) { if ($depth > 0) {
$ownpost = ($USER->id == $post->userid); $ownpost = ($USER->id == $post->userid);
forum_print_post($post, $course, $ownpost, $reply, $link, $ratings); // link=true? if (forum_print_post($post, $course, $ownpost, $reply, $link, $ratings)) {
$ratingsmenuused = true;
}
echo "<br />"; echo "<br />";
} else { } else {
$by->name = "$post->firstname $post->lastname"; $by->name = "$post->firstname $post->lastname";
@ -2165,18 +2188,20 @@ function forum_print_posts_threaded($parent, $course, $depth, $ratings, $reply)
echo "</font></p></li>"; echo "</font></p></li>";
} }
forum_print_posts_threaded($post->id, $course, $depth-1, $ratings, $reply); if (forum_print_posts_threaded($post->id, $course, $depth-1, $ratings, $reply)) {
$ratingsmenuused = true;
}
echo "</ul>\n"; echo "</ul>\n";
} }
} else {
return;
} }
return $ratingsmenuused;
} }
function forum_print_posts_nested($parent, $course, $ratings, $reply) { function forum_print_posts_nested($parent, $course, $ratings, $reply) {
global $USER; global $USER;
$link = false; $link = false;
$ratingsmenuused = false;
if ($posts = forum_get_child_posts($parent)) { if ($posts = forum_get_child_posts($parent)) {
foreach ($posts as $post) { foreach ($posts as $post) {
@ -2187,15 +2212,18 @@ function forum_print_posts_nested($parent, $course, $ratings, $reply) {
$ownpost = ($USER->id == $post->userid); $ownpost = ($USER->id == $post->userid);
} }
echo "<UL>"; echo "<ul>";
forum_print_post($post, $course, $ownpost, $reply, $link, $ratings); if (forum_print_post($post, $course, $ownpost, $reply, $link, $ratings)) {
echo "<BR>"; $ratingsmenuused = true;
forum_print_posts_nested($post->id, $course, $ratings, $reply);
echo "</UL>\n";
} }
} else { echo "<br />";
return; if (forum_print_posts_nested($post->id, $course, $ratings, $reply)) {
$ratingsmenuused = true;
} }
echo "</ul>\n";
}
}
return $ratingsmenuused;
} }
function forum_set_display_mode($mode=0) { function forum_set_display_mode($mode=0) {