3 // For a given post, shows a report of all the ratings it has
5 require_once("../../config.php");
6 require_once("lib.php");
8 $id = required_param('id', PARAM_INT
);
9 $sort = optional_param('sort', '', PARAM_ALPHA
);
11 if (! $post = get_record('forum_posts', 'id', $id)) {
12 error("Post ID was incorrect");
15 if (! $discussion = get_record('forum_discussions', 'id', $post->discussion
)) {
16 error("Discussion ID was incorrect");
19 if (! $forum = get_record('forum', 'id', $discussion->forum
)) {
20 error("Forum ID was incorrect");
23 if (! $course = get_record('course', 'id', $forum->course
)) {
24 error("Course ID was incorrect");
27 if (! $cm = get_coursemodule_from_instance('forum', $forum->id
, $course->id
)) {
28 error("Course Module ID was incorrect");
31 require_login($course, false, $cm);
32 $context = get_context_instance(CONTEXT_MODULE
, $cm->id
);
34 if (!$forum->assessed
) {
35 error("This activity does not use ratings");
38 if (!has_capability('mod/forum:viewrating', $context)) {
39 error("You do not have the capability to view post ratings");
41 if (!has_capability('mod/forum:viewanyrating', $context) and $USER->id
!= $post->userid
) {
42 error("You can only look at results for posts that you made");
46 case 'firstname': $sqlsort = "u.firstname ASC"; break;
47 case 'rating': $sqlsort = "r.rating ASC"; break;
48 default: $sqlsort = "r.time ASC";
51 $scalemenu = make_grades_menu($forum->scale
);
53 $strratings = get_string('ratings', 'forum');
54 $strrating = get_string('rating', 'forum');
55 $strname = get_string('name');
56 $strtime = get_string('time');
58 print_header("$strratings: ".format_string($post->subject
));
60 if (!$ratings = forum_get_ratings($post->id
, $sqlsort)) {
61 error("No ratings for this post: \"".format_string($post->subject
)."\"");
64 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
66 echo "<th class=\"header\" scope=\"col\"> </th>";
67 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$post->id&sort=firstname\">$strname</a></th>";
68 echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$post->id&sort=rating\">$strrating</a></th>";
69 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$post->id&sort=time\">$strtime</a></th>";
71 foreach ($ratings as $rating) {
72 echo '<tr class="forumpostheader">';
74 print_user_picture($rating->id
, $forum->course
, $rating->picture
);
75 echo '</td><td>'.fullname($rating).'</td>';
76 echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating
]."</td>";
77 echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->time
)."</td>";
84 close_window_button();