question import/export: MDL-22100 ' / etc. in category names confuse the import/export.
[moodle.git] / rating / index.php
blobe3c41ba7778311dae10b047635c01c5848352ef4
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
9 //
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/>.
18 /**
19 * A page to display a list of ratings for a given item (forum post etc)
21 * @package moodlecore
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);
33 $popup = optional_param('popup', 0, PARAM_INT);//==1 if in a popup window?
35 list($context, $course, $cm) = get_context_info_array($contextid);
36 require_login($course, false, $cm);
38 $url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'itemid'=>$itemid,'scaleid'=>$scaleid));
39 if ($sort !== 0) {
40 $url->param('sort', $sort);
42 $PAGE->set_url($url);
43 if ($popup) {
44 $PAGE->set_pagelayout('popup');
47 if (!has_capability('moodle/rating:view',$context)) {
48 print_error('noviewrate', 'rating');
50 if (!has_capability('moodle/rating:viewall',$context) and $USER->id != $item->userid) {
51 print_error('noviewanyrate', 'rating');
54 switch ($sort) {
55 case 'firstname': $sqlsort = "u.firstname ASC"; break;
56 case 'rating': $sqlsort = "r.rating ASC"; break;
57 default: $sqlsort = "r.timemodified ASC";
60 $scalemenu = make_grades_menu($scaleid);
62 $strratings = get_string('ratings', 'rating');
63 $strrating = get_string('rating', 'rating');
64 $strname = get_string('name');
65 $strtime = get_string('time');
67 //Is there something more meaningful we can put in the title? It used to be forum post title
68 $PAGE->set_title("$strratings: ".format_string($itemid));
69 echo $OUTPUT->header();
71 $ratingoptions = new stdclass();
72 $ratingoptions->context = $context;
73 $ratingoptions->itemid = $itemid;
74 $ratingoptions->sort = $sqlsort;
76 $rm = new rating_manager();
77 $ratings = $rm->get_all_ratings_for_item($ratingoptions);
78 if (!$ratings) {
79 print_error('noresult', 'forum', '', format_string($itemid));
80 } else {
81 $sortargs = "contextid=$contextid&amp;itemid=$itemid&amp;scaleid=$scaleid";
82 if($popup) {
83 $sortargs.="&amp;popup=$popup";
85 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
86 echo "<tr>";
87 echo "<th class=\"header\" scope=\"col\">&nbsp;</th>";
88 echo "<th class=\"header\" scope=\"col\"><a href=\"index.php?$sortargs&amp;sort=firstname\">$strname</a></th>";
89 echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"index.php?$sortargs&amp;sort=rating\">$strrating</a></th>";
90 echo "<th class=\"header\" scope=\"col\"><a href=\"index.php?$sortargs&amp;sort=time\">$strtime</a></th>";
91 echo "</tr>";
93 foreach ($ratings as $rating) {
94 //Undo the aliasing of the user id column from user_picture::fields()
95 //we could clone the rating object or preserve the rating id if we needed it again
96 //but we don't
97 $rating->id = $rating->uid;
99 echo '<tr class="ratingitemheader">';
100 echo "<td>";
101 if($course && $course->id) {
102 echo $OUTPUT->user_picture($rating, array('courseid'=>$course->id));
103 } else {
104 echo $OUTPUT->user_picture($rating);
106 echo '</td><td>'.fullname($rating).'</td>';
107 echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating]."</td>";
108 echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->timemodified)."</td>";
109 echo "</tr>\n";
111 echo "</table>";
112 echo "<br />";
115 if ($popup) {
116 echo $OUTPUT->close_window_button();
118 echo $OUTPUT->footer();