3 // This file is part of Moodle - http://moodle.org/
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
19 * A page to display a list of ratings for a given item (forum post etc)
22 * @copyright 2010 Andrew Davis
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require_once("../config.php");
27 require_once("lib.php");
29 $contextid = required_param('contextid', PARAM_INT);
30 $itemid = required_param('itemid', PARAM_INT);
31 $scaleid = required_param('scaleid', PARAM_INT);
32 $sort = optional_param('sort', '', PARAM_ALPHA);
34 list($context, $course, $cm) = get_context_info_array($contextid);
35 require_login($course, false, $cm);
37 $url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'itemid'=>$itemid,'scaleid'=>$scaleid));
39 $url->param('sort', $sort);
43 $permissions = rating::get_rating_permissions(context);
44 if (!$permissions[RATING_VIEW]) {
45 print_error('noviewrate', 'rating');
47 if (!$permissions[RATING_VIEW_ALL] and $USER->id != $item->userid) {
48 print_error('noviewanyrate', 'rating');
52 case 'firstname': $sqlsort = "u.firstname ASC"; break;
53 case 'rating': $sqlsort = "r.rating ASC"; break;
54 default: $sqlsort = "r.timemodified ASC";
57 $scalemenu = make_grades_menu($scaleid);
59 $strratings = get_string('ratings', 'rating');
60 $strrating = get_string('rating', 'rating');
61 $strname = get_string('name');
62 $strtime = get_string('time');
64 //Is there something more meaningful we can put in the title?
65 //$PAGE->set_title("$strratings: ".format_string($post->subject));
66 $PAGE->set_title("$strratings: ".format_string($itemid));
67 echo $OUTPUT->header();
69 //if (!$ratings = forum_get_ratings($post->id, $sqlsort)) {
70 $ratings = rating::load_ratings_for_item($context, $itemid, $sort);
72 //print_error('noresult', 'forum', '', format_string($post->subject));
73 print_error('noresult');
75 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
77 echo "<th class=\"header\" scope=\"col\"> </th>";
78 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$itemid&sort=firstname\">$strname</a></th>";
79 echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"report.php?id=$itemid&sort=rating\">$strrating</a></th>";
80 echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$itemid&sort=time\">$strtime</a></th>";
82 foreach ($ratings as $rating) {
83 echo '<tr class="ratingitemheader">';
86 echo $OUTPUT->user_picture($rating, array('courseid'=>$courseid));
88 echo $OUTPUT->user_picture($rating);
90 echo '</td><td>'.fullname($rating).'</td>';
91 echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating]."</td>";
92 echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->timemodified)."</td>";
99 echo $OUTPUT->close_window_button();
100 echo $OUTPUT->footer();