Skip to content

Commit

Permalink
Merge branch 'MDL-46446_rating_style' of https://github.com/andyjdavi…
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Hemelryk committed Jul 28, 2014
2 parents 70acf83 + d28a6a5 commit 72655d0
Show file tree
Hide file tree
Showing 6 changed files with 321 additions and 253 deletions.
41 changes: 24 additions & 17 deletions rating/index.php
@@ -1,5 +1,4 @@
<?php

// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -33,12 +32,15 @@
$itemid = required_param('itemid', PARAM_INT);
$scaleid = required_param('scaleid', PARAM_INT);
$sort = optional_param('sort', '', PARAM_ALPHA);
$popup = optional_param('popup', 0, PARAM_INT); //==1 if in a popup window?
$popup = optional_param('popup', 0, PARAM_INT); // Any non-zero value if in a popup window.

list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);

$url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'component'=>$component,'itemid'=>$itemid,'scaleid'=>$scaleid));
$url = new moodle_url('/rating/index.php', array('contextid' => $contextid,
'component' => $component,
'itemid' => $itemid,
'scaleid' => $scaleid));
if (!empty($ratingarea)) {
$url->param('ratingarea', $ratingarea);
}
Expand All @@ -55,17 +57,22 @@
$PAGE->set_pagelayout('popup');
}

if (!has_capability('moodle/rating:view',$context)) {
if (!has_capability('moodle/rating:view', $context)) {
print_error('noviewrate', 'rating');
}
if (!has_capability('moodle/rating:viewall',$context) and $USER->id != $item->userid) {
if (!has_capability('moodle/rating:viewall', $context) and $USER->id != $item->userid) {
print_error('noviewanyrate', 'rating');
}

switch ($sort) {
case 'firstname': $sqlsort = "u.firstname ASC"; break;
case 'rating': $sqlsort = "r.rating ASC"; break;
default: $sqlsort = "r.timemodified ASC";
case 'firstname':
$sqlsort = "u.firstname ASC";
break;
case 'rating':
$sqlsort = "r.rating ASC";
break;
default:
$sqlsort = "r.timemodified ASC";
}

$scalemenu = make_grades_menu($scaleid);
Expand All @@ -74,7 +81,7 @@
$strname = get_string('name');
$strtime = get_string('time');

$PAGE->set_title(get_string('allratingsforitem','rating'));
$PAGE->set_title(get_string('allratingsforitem', 'rating'));
echo $OUTPUT->header();

$ratingoptions = new stdClass;
Expand All @@ -87,10 +94,10 @@
$rm = new rating_manager();
$ratings = $rm->get_all_ratings_for_item($ratingoptions);
if (!$ratings) {
$msg = get_string('noratings','rating');
echo html_writer::tag('div', $msg, array('class'=>'mdl-align'));
$msg = get_string('noratings', 'rating');
echo html_writer::tag('div', $msg, array('class' => 'mdl-align'));
} else {
// To get the sort URL, copy the current URL and remove any previous sort
// To get the sort URL, copy the current URL and remove any previous sort.
$sorturl = new moodle_url($url);
$sorturl->remove_params('sort');

Expand All @@ -107,14 +114,14 @@
$table->colclasses = array('', 'firstname', 'rating', 'time');
$table->data = array();

// If the scale was changed after ratings were submitted some ratings may have a value above the current maximum
// We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0
// If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
// We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
$maxrating = max(array_keys($scalemenu));

foreach ($ratings as $rating) {
//Undo the aliasing of the user id column from user_picture::fields()
//we could clone the rating object or preserve the rating id if we needed it again
//but we don't
// Undo the aliasing of the user id column from user_picture::fields().
// We could clone the rating object or preserve the rating id if we needed it again
// but we don't.
$rating->id = $rating->userid;

$row = new html_table_row();
Expand Down

0 comments on commit 72655d0

Please sign in to comment.