NOBUG: Removed deprecated mktime arg from dayofweek func in moodlelib
[moodle.git] / rating / index.php
CommitLineData
a09aeee4
AD
1<?php
2
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.
14//
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/>.
17
18/**
19 * A page to display a list of ratings for a given item (forum post etc)
20 *
5d354ded
PS
21 * @package core
22 * @subpackage rating
23 * @copyright 2010 Andrew Davis
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
a09aeee4
AD
25 */
26
27require_once("../config.php");
9c1f9627 28require_once("lib.php");
a09aeee4 29
f1f6a755 30$contextid = required_param('contextid', PARAM_INT);
a09aeee4
AD
31$itemid = required_param('itemid', PARAM_INT);
32$scaleid = required_param('scaleid', PARAM_INT);
33$sort = optional_param('sort', '', PARAM_ALPHA);
63e87951 34$popup = optional_param('popup', 0, PARAM_INT);//==1 if in a popup window?
a09aeee4 35
f1f6a755
AD
36list($context, $course, $cm) = get_context_info_array($contextid);
37require_login($course, false, $cm);
a09aeee4 38
7ac928a7 39$url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'itemid'=>$itemid,'scaleid'=>$scaleid));
a09aeee4
AD
40if ($sort !== 0) {
41 $url->param('sort', $sort);
42}
43$PAGE->set_url($url);
c8e142dd
AD
44$PAGE->set_context($context);
45
63e87951
AD
46if ($popup) {
47 $PAGE->set_pagelayout('popup');
48}
a09aeee4 49
63e87951 50if (!has_capability('moodle/rating:view',$context)) {
6c5fcef7 51 print_error('noviewrate', 'rating');
a09aeee4 52}
63e87951 53if (!has_capability('moodle/rating:viewall',$context) and $USER->id != $item->userid) {
6c5fcef7 54 print_error('noviewanyrate', 'rating');
a09aeee4
AD
55}
56
57switch ($sort) {
58 case 'firstname': $sqlsort = "u.firstname ASC"; break;
59 case 'rating': $sqlsort = "r.rating ASC"; break;
60 default: $sqlsort = "r.timemodified ASC";
61}
62
63$scalemenu = make_grades_menu($scaleid);
64
6c5fcef7
AD
65$strratings = get_string('ratings', 'rating');
66$strrating = get_string('rating', 'rating');
a09aeee4
AD
67$strname = get_string('name');
68$strtime = get_string('time');
69
63e87951 70//Is there something more meaningful we can put in the title? It used to be forum post title
a09aeee4
AD
71$PAGE->set_title("$strratings: ".format_string($itemid));
72echo $OUTPUT->header();
73
b1721f67
AD
74$ratingoptions = new stdclass();
75$ratingoptions->context = $context;
76$ratingoptions->itemid = $itemid;
63e87951 77$ratingoptions->sort = $sqlsort;
a8e85df6
AD
78
79$rm = new rating_manager();
63e87951 80$ratings = $rm->get_all_ratings_for_item($ratingoptions);
a09aeee4 81if (!$ratings) {
63e87951 82 print_error('noresult', 'forum', '', format_string($itemid));
a09aeee4 83} else {
63e87951
AD
84 $sortargs = "contextid=$contextid&amp;itemid=$itemid&amp;scaleid=$scaleid";
85 if($popup) {
86 $sortargs.="&amp;popup=$popup";
87 }
a09aeee4
AD
88 echo "<table border=\"0\" cellpadding=\"3\" cellspacing=\"3\" class=\"generalbox\" style=\"width:100%\">";
89 echo "<tr>";
90 echo "<th class=\"header\" scope=\"col\">&nbsp;</th>";
63e87951
AD
91 echo "<th class=\"header\" scope=\"col\"><a href=\"index.php?$sortargs&amp;sort=firstname\">$strname</a></th>";
92 echo "<th class=\"header\" scope=\"col\" style=\"width:100%\"><a href=\"index.php?$sortargs&amp;sort=rating\">$strrating</a></th>";
93 echo "<th class=\"header\" scope=\"col\"><a href=\"index.php?$sortargs&amp;sort=time\">$strtime</a></th>";
a09aeee4 94 echo "</tr>";
61b00708 95
a09aeee4 96 foreach ($ratings as $rating) {
61b00708
AD
97 //Undo the aliasing of the user id column from user_picture::fields()
98 //we could clone the rating object or preserve the rating id if we needed it again
99 //but we don't
100 $rating->id = $rating->uid;
5d354ded 101
7ac928a7 102 echo '<tr class="ratingitemheader">';
a09aeee4 103 echo "<td>";
2d10c085
AD
104 if($course && $course->id) {
105 echo $OUTPUT->user_picture($rating, array('courseid'=>$course->id));
a09aeee4
AD
106 } else {
107 echo $OUTPUT->user_picture($rating);
108 }
109 echo '</td><td>'.fullname($rating).'</td>';
110 echo '<td style="white-space:nowrap" align="center" class="rating">'.$scalemenu[$rating->rating]."</td>";
111 echo '<td style="white-space:nowrap" align="center" class="time">'.userdate($rating->timemodified)."</td>";
112 echo "</tr>\n";
113 }
114 echo "</table>";
115 echo "<br />";
116}
117
63e87951
AD
118if ($popup) {
119 echo $OUTPUT->close_window_button();
120}
a09aeee4 121echo $OUTPUT->footer();