# This patch file was generated by NetBeans IDE # This patch can be applied using context Tools: Apply Diff Patch action on respective folder. # It uses platform neutral UTF-8 encoding. # Above lines and this line are ignored by the patching process. Index: moodle/rating/module.js --- moodle/rating/module.js Base (1.6) +++ moodle/rating/module.js Locally Modified (Based On 1.6) @@ -42,15 +42,20 @@ var data = this.Y.JSON.parse(outcome.responseText); if (data.success){ //if the user has access to the aggregate then update it - if (data.itemid && data.aggregate && data.count) { + if (data.itemid) { //do not test data.aggregate or data.count otherwise it doesn't refresh value=0 or no value var itemid = data.itemid; var node = this.Y.one('#ratingaggregate'+itemid); node.set('innerHTML',data.aggregate); + //empty the count value if no ratings var node = this.Y.one('#ratingcount'+itemid); + if (data.count > 0) { node.set('innerHTML',"("+data.count+")"); + } else { + node.set('innerHTML',""); } + } \ No newline at end of file return true; } else if (data.error){ Index: moodle/rating/rate_ajax.php --- moodle/rating/rate_ajax.php Base (1.7) +++ moodle/rating/rate_ajax.php Locally Modified (Based On 1.7) @@ -58,6 +58,8 @@ die(); } +$rm = new rating_manager(); + //check the module rating permissions //doing this check here rather than within rating_manager::get_ratings so we can return a json error response $pluginrateallowed = true; @@ -65,7 +67,6 @@ if ($context->contextlevel==CONTEXT_MODULE) { $plugintype = 'mod'; $pluginname = $cm->modname; - $rm = new rating_manager(); $pluginpermissionsarray = $rm->get_plugin_permissions_array($context->id, $plugintype, $pluginname); $pluginrateallowed = $pluginpermissionsarray['rate']; @@ -93,8 +94,21 @@ $ratingoptions->userid = $USER->id; $rating = new rating($ratingoptions); +if ($userrating != RATING_UNSET_RATING) { $rating->update_rating($userrating); +} else { //delete the rating if the user set to Rate... + //Note: the JS could pass the rating id so we would not need + // to retrieve it from the db like I do following + $ratingoptions->aggregate = $aggregationmethod; + $ratingoptions->items[0]->id = $itemid; + $ratings = $rm->get_ratings($ratingoptions); + $options = new stdClass(); + $options->ratingid = $ratings[0]->rating->id; + $options->contextid = $context->id; + $rm->delete_ratings($options); +} + //Future possible enhancement: add a setting to turn grade updating off for those who don't want them in gradebook //note that this would need to be done in both rate.php and rate_ajax.php if(true){ @@ -125,7 +139,6 @@ $ratingoptions->items = $items; $ratingoptions->aggregate = $aggregationmethod; -$rm = new rating_manager(); $items = $rm->get_ratings($ratingoptions); //for custom scales return text not the value @@ -134,7 +147,8 @@ $aggregatetoreturn = round($items[0]->rating->aggregate,1); // Output a dash if aggregation method == COUNT as the count is output next to the aggregate anyway -if ($items[0]->rating->settings->aggregationmethod==RATING_AGGREGATE_COUNT) { \ No newline at end of file +if ($items[0]->rating->settings->aggregationmethod==RATING_AGGREGATE_COUNT + or $items[0]->rating->count == 0) { //missing check for count == 0 \ No newline at end of file $aggregatetoreturn = ' - '; } else if($rating->scaleid < 0) { //if its non-numeric scale //output the numeric aggregate is aggregation method is sum