[ Index ] |
PHP Cross Reference of moodle-2.8 |
[Summary view] [Print] [Text view]
1 <?php 2 // This file is part of Moodle - http://moodle.org/ 3 // 4 // Moodle is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // Moodle is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU General Public License for more details. 13 // 14 // You should have received a copy of the GNU General Public License 15 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 16 17 /** 18 * A page to display a list of ratings for a given item (forum post etc) 19 * 20 * @package core_rating 21 * @category rating 22 * @copyright 2010 Andrew Davis 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 */ 25 26 require_once("../config.php"); 27 require_once ("lib.php"); 28 29 $contextid = required_param('contextid', PARAM_INT); 30 $component = required_param('component', PARAM_COMPONENT); 31 $ratingarea = optional_param('ratingarea', null, PARAM_AREA); 32 $itemid = required_param('itemid', PARAM_INT); 33 $scaleid = required_param('scaleid', PARAM_INT); 34 $sort = optional_param('sort', '', PARAM_ALPHA); 35 $popup = optional_param('popup', 0, PARAM_INT); // Any non-zero value if in a popup window. 36 37 list($context, $course, $cm) = get_context_info_array($contextid); 38 require_login($course, false, $cm); 39 40 $url = new moodle_url('/rating/index.php', array('contextid' => $contextid, 41 'component' => $component, 42 'itemid' => $itemid, 43 'scaleid' => $scaleid)); 44 if (!empty($ratingarea)) { 45 $url->param('ratingarea', $ratingarea); 46 } 47 if (!empty($sort)) { 48 $url->param('sort', $sort); 49 } 50 if (!empty($popup)) { 51 $url->param('popup', $popup); 52 } 53 $PAGE->set_url($url); 54 $PAGE->set_context($context); 55 56 if ($popup) { 57 $PAGE->set_pagelayout('popup'); 58 } 59 60 if (!has_capability('moodle/rating:view', $context)) { 61 print_error('noviewrate', 'rating'); 62 } 63 if (!has_capability('moodle/rating:viewall', $context) and $USER->id != $item->userid) { 64 print_error('noviewanyrate', 'rating'); 65 } 66 67 switch ($sort) { 68 case 'firstname': 69 $sqlsort = "u.firstname ASC"; 70 break; 71 case 'rating': 72 $sqlsort = "r.rating ASC"; 73 break; 74 default: 75 $sqlsort = "r.timemodified ASC"; 76 } 77 78 $scalemenu = make_grades_menu($scaleid); 79 80 $strrating = get_string('rating', 'rating'); 81 $strname = get_string('name'); 82 $strtime = get_string('time'); 83 84 $PAGE->set_title(get_string('allratingsforitem', 'rating')); 85 echo $OUTPUT->header(); 86 87 $ratingoptions = new stdClass; 88 $ratingoptions->context = $context; 89 $ratingoptions->component = $component; 90 $ratingoptions->ratingarea = $ratingarea; 91 $ratingoptions->itemid = $itemid; 92 $ratingoptions->sort = $sqlsort; 93 94 $rm = new rating_manager(); 95 $ratings = $rm->get_all_ratings_for_item($ratingoptions); 96 if (!$ratings) { 97 $msg = get_string('noratings', 'rating'); 98 echo html_writer::tag('div', $msg, array('class' => 'mdl-align')); 99 } else { 100 // To get the sort URL, copy the current URL and remove any previous sort. 101 $sorturl = new moodle_url($url); 102 $sorturl->remove_params('sort'); 103 104 $table = new html_table; 105 $table->cellpadding = 3; 106 $table->cellspacing = 3; 107 $table->attributes['class'] = 'generalbox ratingtable'; 108 $table->head = array( 109 '', 110 html_writer::link(new moodle_url($sorturl, array('sort' => 'firstname')), $strname), 111 html_writer::link(new moodle_url($sorturl, array('sort' => 'rating')), $strrating), 112 html_writer::link(new moodle_url($sorturl, array('sort' => 'time')), $strtime) 113 ); 114 $table->colclasses = array('', 'firstname', 'rating', 'time'); 115 $table->data = array(); 116 117 // If the scale was changed after ratings were submitted some ratings may have a value above the current maximum. 118 // We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0. 119 $maxrating = max(array_keys($scalemenu)); 120 121 foreach ($ratings as $rating) { 122 // Undo the aliasing of the user id column from user_picture::fields(). 123 // We could clone the rating object or preserve the rating id if we needed it again 124 // but we don't. 125 $rating->id = $rating->userid; 126 127 $row = new html_table_row(); 128 $row->attributes['class'] = 'ratingitemheader'; 129 if ($course && $course->id) { 130 $row->cells[] = $OUTPUT->user_picture($rating, array('courseid' => $course->id)); 131 } else { 132 $row->cells[] = $OUTPUT->user_picture($rating); 133 } 134 $row->cells[] = fullname($rating); 135 if ($rating->rating > $maxrating) { 136 $rating->rating = $maxrating; 137 } 138 $row->cells[] = $scalemenu[$rating->rating]; 139 $row->cells[] = userdate($rating->timemodified); 140 $table->data[] = $row; 141 } 142 echo html_writer::table($table); 143 } 144 if ($popup) { 145 echo $OUTPUT->close_window_button(); 146 } 147 echo $OUTPUT->footer();
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Fri Nov 28 20:29:05 2014 | Cross-referenced by PHPXref 0.7.1 |