Skip to content

Commit

Permalink
MDL-46448 core_rating: now only formats rating aggregate if user can …
Browse files Browse the repository at this point in the history
…see it
  • Loading branch information
andyjdavis committed Aug 6, 2014
1 parent d29fb4a commit c568d47
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions rating/rate_ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -142,27 +142,28 @@
$items = $rm->get_ratings($ratingoptions);
$firstrating = $items[0]->rating;

// For custom scales return text not the value.
// This scales weirdness will go away when scales are refactored.
$scalearray = null;
$aggregatetoreturn = round($firstrating->aggregate, 1);

// Output a dash if aggregation method == COUNT as the count is output next to the aggregate anyway.
if ($firstrating->settings->aggregationmethod == RATING_AGGREGATE_COUNT or $firstrating->count == 0) {
$aggregatetoreturn = ' - ';
} else if ($firstrating->settings->scale->id < 0) { // If its non-numeric scale.
// Dont use the scale item if the aggregation method is sum as adding items from a custom scale makes no sense.
if ($firstrating->settings->aggregationmethod != RATING_AGGREGATE_SUM) {
$scalerecord = $DB->get_record('scale', array('id' => -$firstrating->settings->scale->id));
if ($scalerecord) {
$scalearray = explode(',', $scalerecord->scale);
$aggregatetoreturn = $scalearray[$aggregatetoreturn - 1];
// See if the user has permission to see the rating aggregate.
if ($firstrating->user_can_view_aggregate()) {

// For custom scales return text not the value.
// This scales weirdness will go away when scales are refactored.
$scalearray = null;
$aggregatetoreturn = round($firstrating->aggregate, 1);

// Output a dash if aggregation method == COUNT as the count is output next to the aggregate anyway.
if ($firstrating->settings->aggregationmethod == RATING_AGGREGATE_COUNT or $firstrating->count == 0) {
$aggregatetoreturn = ' - ';
} else if ($firstrating->settings->scale->id < 0) { // If its non-numeric scale.
// Dont use the scale item if the aggregation method is sum as adding items from a custom scale makes no sense.
if ($firstrating->settings->aggregationmethod != RATING_AGGREGATE_SUM) {
$scalerecord = $DB->get_record('scale', array('id' => -$firstrating->settings->scale->id));
if ($scalerecord) {
$scalearray = explode(',', $scalerecord->scale);
$aggregatetoreturn = $scalearray[$aggregatetoreturn - 1];
}
}
}
}

// See if the user has permission to see the rating aggregate.
if ($firstrating->user_can_view_aggregate()) {
$result->aggregate = $aggregatetoreturn;
$result->count = $firstrating->count;
$result->itemid = $itemid;
Expand Down

0 comments on commit c568d47

Please sign in to comment.