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