|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00003 // This file is part of Moodle - http://moodle.org/ 00004 // 00005 // Moodle is free software: you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation, either version 3 of the License, or 00008 // (at your option) any later version. 00009 // 00010 // Moodle is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with Moodle. If not, see <http://www.gnu.org/licenses/>. 00017 00027 require_once("../config.php"); 00028 require_once("lib.php"); 00029 00030 $contextid = required_param('contextid', PARAM_INT); 00031 $component = required_param('component', PARAM_COMPONENT); 00032 $ratingarea = optional_param('ratingarea', null, PARAM_AREA); 00033 $itemid = required_param('itemid', PARAM_INT); 00034 $scaleid = required_param('scaleid', PARAM_INT); 00035 $sort = optional_param('sort', '', PARAM_ALPHA); 00036 $popup = optional_param('popup', 0, PARAM_INT); //==1 if in a popup window? 00037 00038 list($context, $course, $cm) = get_context_info_array($contextid); 00039 require_login($course, false, $cm); 00040 00041 $url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'itemid'=>$itemid,'scaleid'=>$scaleid)); 00042 if ($sort !== 0) { 00043 $url->param('sort', $sort); 00044 } 00045 $PAGE->set_url($url); 00046 $PAGE->set_context($context); 00047 00048 if ($popup) { 00049 $PAGE->set_pagelayout('popup'); 00050 } 00051 00052 if (!has_capability('moodle/rating:view',$context)) { 00053 print_error('noviewrate', 'rating'); 00054 } 00055 if (!has_capability('moodle/rating:viewall',$context) and $USER->id != $item->userid) { 00056 print_error('noviewanyrate', 'rating'); 00057 } 00058 00059 switch ($sort) { 00060 case 'firstname': $sqlsort = "u.firstname ASC"; break; 00061 case 'rating': $sqlsort = "r.rating ASC"; break; 00062 default: $sqlsort = "r.timemodified ASC"; 00063 } 00064 00065 $scalemenu = make_grades_menu($scaleid); 00066 00067 $strrating = get_string('rating', 'rating'); 00068 $strname = get_string('name'); 00069 $strtime = get_string('time'); 00070 00071 $PAGE->set_title(get_string('allratingsforitem','rating')); 00072 echo $OUTPUT->header(); 00073 00074 $ratingoptions = new stdClass; 00075 $ratingoptions->context = $context; 00076 $ratingoptions->component = $component; 00077 $ratingoptions->ratingarea = $ratingarea; 00078 $ratingoptions->itemid = $itemid; 00079 $ratingoptions->sort = $sqlsort; 00080 00081 $rm = new rating_manager(); 00082 $ratings = $rm->get_all_ratings_for_item($ratingoptions); 00083 if (!$ratings) { 00084 $msg = get_string('noratings','rating'); 00085 echo html_writer::tag('div', $msg, array('class'=>'mdl-align')); 00086 } else { 00087 $sorturl = new moodle_url('/index.php', array('contextid' => $contextid, 'itemid' => $itemid, 'scaleid' => $scaleid)); 00088 if ($popup) { 00089 $sorturl->param('popup', $popup); 00090 } 00091 00092 $table = new html_table; 00093 $table->cellpadding = 3; 00094 $table->cellspacing = 3; 00095 $table->attributes['class'] = 'generalbox ratingtable'; 00096 $table->head = array( 00097 '', 00098 html_writer::link(new moodle_url($sorturl, array('sort' => 'firstname')), $strname), 00099 html_writer::link(new moodle_url($sorturl, array('sort' => 'rating')), $strrating), 00100 html_writer::link(new moodle_url($sorturl, array('sort' => 'time')), $strtime) 00101 ); 00102 $table->colclasses = array('', 'firstname', 'rating', 'time'); 00103 $table->data = array(); 00104 00105 //if the scale was changed after ratings were submitted some ratings may have a value above the current maximum 00106 $maxrating = count($scalemenu) - 1; 00107 foreach ($ratings as $rating) { 00108 //Undo the aliasing of the user id column from user_picture::fields() 00109 //we could clone the rating object or preserve the rating id if we needed it again 00110 //but we don't 00111 $rating->id = $rating->userid; 00112 00113 $row = new html_table_row(); 00114 $row->attributes['class'] = 'ratingitemheader'; 00115 if ($course && $course->id) { 00116 $row->cells[] = $OUTPUT->user_picture($rating, array('courseid' => $course->id)); 00117 } else { 00118 $row->cells[] = $OUTPUT->user_picture($rating); 00119 } 00120 $row->cells[] = fullname($rating); 00121 if ($rating->rating > $maxrating) { 00122 $rating->rating = $maxrating; 00123 } 00124 $row->cells[] = $scalemenu[$rating->rating]; 00125 $row->cells[] = userdate($rating->timemodified); 00126 $table->data[] = $row; 00127 } 00128 echo html_writer::table($table); 00129 } 00130 if ($popup) { 00131 echo $OUTPUT->close_window_button(); 00132 } 00133 echo $OUTPUT->footer();