<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
	<id>http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ARatings_2.0</id>
	<title>Development:Ratings 2.0 - История изменений</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.mipt.ru/index.php?action=history&amp;feed=atom&amp;title=Development%3ARatings_2.0"/>
	<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Ratings_2.0&amp;action=history"/>
	<updated>2026-05-07T06:01:10Z</updated>
	<subtitle>История изменений этой страницы в вики</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Ratings_2.0&amp;diff=11756&amp;oldid=prev</id>
		<title>Олег Давидович: 1 версия импортирована</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Ratings_2.0&amp;diff=11756&amp;oldid=prev"/>
		<updated>2024-10-21T08:53:06Z</updated>

		<summary type="html">&lt;p&gt;1 версия импортирована&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;← Предыдущая версия&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;Версия от 08:53, 21 октября 2024&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-notice&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
		<author><name>Олег Давидович</name></author>
	</entry>
	<entry>
		<id>http://wiki.mipt.ru/index.php?title=Development:Ratings_2.0&amp;diff=11755&amp;oldid=prev</id>
		<title>1&gt;Mudrd8mz: Text replacement - &quot;class=&quot;nicetable&quot;&quot; to &quot;class=&quot;wikitable&quot;&quot;</title>
		<link rel="alternate" type="text/html" href="http://wiki.mipt.ru/index.php?title=Development:Ratings_2.0&amp;diff=11755&amp;oldid=prev"/>
		<updated>2021-07-14T13:24:11Z</updated>

		<summary type="html">&lt;p&gt;Text replacement - &amp;quot;class=&amp;quot;nicetable&amp;quot;&amp;quot; to &amp;quot;class=&amp;quot;wikitable&amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Moodle 2.0}}==Objectives==&lt;br /&gt;
&lt;br /&gt;
Ratings are grades entered away from the gradebook. They can be entered by students and teachers and are aggregated into grades.&lt;br /&gt;
&lt;br /&gt;
The goals of ratings 2.0:&lt;br /&gt;
&lt;br /&gt;
* Manage ratings centrally&lt;br /&gt;
* Use a consistent approach for all ratings throughout Moodle&lt;br /&gt;
* Easily integrate ratings 2.0 with existing modules&lt;br /&gt;
* Remove duplicate implementations of ratings functionality&lt;br /&gt;
&lt;br /&gt;
==Overview==&lt;br /&gt;
&lt;br /&gt;
The ratings 2.0 provides APIs to:&lt;br /&gt;
# Add ratings&lt;br /&gt;
# Update ratings&lt;br /&gt;
# Access collected ratings for grade calculation purposes&lt;br /&gt;
# Delete ratings&lt;br /&gt;
&lt;br /&gt;
==Current tracker issues==&lt;br /&gt;
MDL-21389 Write spec for separate Ratings 2.0&lt;br /&gt;
&lt;br /&gt;
MDL-20514 Allow Aggregate Type in Glossary Activity&lt;br /&gt;
&lt;br /&gt;
MDL-21657 Implement Ratings 2.0&lt;br /&gt;
&lt;br /&gt;
==Interface==&lt;br /&gt;
&lt;br /&gt;
[[Image:RatingUI.gif]]&lt;br /&gt;
&lt;br /&gt;
When Javascript is enabled ajax submission means the button can be removed. In the future it would be possible to automatically interpret a 1 to 5 rating as a star rating style UI element.&lt;br /&gt;
&lt;br /&gt;
If the user has &amp;#039;post&amp;#039; permission as returned by modname_rating_permissions() the dropdown box and submission button will be displayed.&lt;br /&gt;
&lt;br /&gt;
If the user has &amp;#039;view&amp;#039; permissions the text to the left of the dropdown box will be displayed. The displayed text consists of the aggregate of the ratings, 4 out of 5 in the example. The number in brackets is the number of ratings that have been submitted. There have been two ratings submitted in the example.&lt;br /&gt;
&lt;br /&gt;
If the user has &amp;#039;viewall&amp;#039; permissions they can click on the aggregate summary to view a list of all of the ratings that have been submitted. This is a listing of each user&amp;#039;s profile pic, their name and the rating they submitted.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Database changes==&lt;br /&gt;
===New tables===&lt;br /&gt;
&lt;br /&gt;
====Ratings====&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Default&lt;br /&gt;
! Info&lt;br /&gt;
|-&lt;br /&gt;
| id&lt;br /&gt;
| int(10)&lt;br /&gt;
| auto-incrementing&lt;br /&gt;
| The unique ID for this comment.&lt;br /&gt;
|-&lt;br /&gt;
| contextid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| The context id defined in context table - identifies the instance of plugin owning the comment.&lt;br /&gt;
|-&lt;br /&gt;
| itemid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| Some plugin specific item id (eg. forum post blog entry)&lt;br /&gt;
|-&lt;br /&gt;
| scaleid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| ID of the scale (1-5, 0-100, custom) from which the user selected their rating. Including this allows smarter handling of previously entered ratings should the scales be changed.&lt;br /&gt;
|-&lt;br /&gt;
| rating&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| The user&amp;#039;s rating&lt;br /&gt;
|-&lt;br /&gt;
| userid&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| The user who submitted the rating&lt;br /&gt;
|-&lt;br /&gt;
| timecreated&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| timemodified&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
|&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Altered tables===&lt;br /&gt;
The forum, glossary and data tables need to be altered to contain the required fields specificed in [https://docs.moodle.org/en/Development:Ratings_2.0#Ratings_Settings]&lt;br /&gt;
&lt;br /&gt;
===Removed database tables===&lt;br /&gt;
&lt;br /&gt;
The following tables will have their data migrated to the above ratings table and then be removed:&lt;br /&gt;
&lt;br /&gt;
data_ratings&lt;br /&gt;
&lt;br /&gt;
forum_ratings&lt;br /&gt;
&lt;br /&gt;
glossary_ratings&lt;br /&gt;
&lt;br /&gt;
===Scales===&lt;br /&gt;
&lt;br /&gt;
Course modules will continue to store the scale associated with their ratings. For example the glossary table has a scale column.&lt;br /&gt;
&lt;br /&gt;
Scales are going to be refactored as part of a separate issue. See MDL-17258.&lt;br /&gt;
&lt;br /&gt;
==Ratings code changes==&lt;br /&gt;
&lt;br /&gt;
rating/lib.php will contain...&lt;br /&gt;
&lt;br /&gt;
===class rating===&lt;br /&gt;
&lt;br /&gt;
====__construct($options)====&lt;br /&gt;
&lt;br /&gt;
Initialize a class instance. Requires context, itemid, scaleid and userid.&lt;br /&gt;
&lt;br /&gt;
====update_rating($rating)====&lt;br /&gt;
&lt;br /&gt;
Add or update the numerical value of the rating in the database&lt;br /&gt;
&lt;br /&gt;
====get_rating()====&lt;br /&gt;
&lt;br /&gt;
get the numerical value of the rating&lt;br /&gt;
&lt;br /&gt;
====delete_rating()====&lt;br /&gt;
&lt;br /&gt;
delete the rating. Not implemented yet as it hasn&amp;#039;t been required.&lt;br /&gt;
&lt;br /&gt;
===class rating_manager===&lt;br /&gt;
&lt;br /&gt;
====public get_ratings($options)====&lt;br /&gt;
Returns the supplied set of items with a rating instance attached to each item.&lt;br /&gt;
&lt;br /&gt;
$items is an array of objects with an id member variable ie $items[0]-&amp;gt;id.&lt;br /&gt;
$options requires context, items, aggregate and scaleid.&lt;br /&gt;
&lt;br /&gt;
items is an array of items such as forum posts or glossary items. They must have an &amp;#039;id&amp;#039; member ie $items[0]-&amp;gt;id.&lt;br /&gt;
aggregate is the the aggregation method to apply. RATING_AGGREGATE_AVERAGE etc.&lt;br /&gt;
&lt;br /&gt;
Optionally options may include userid, returnurl, assesstimestart and assesstimefinish.&lt;br /&gt;
&lt;br /&gt;
If userid is omitted the current user&amp;#039;s id will be used.&lt;br /&gt;
returnurl is the url to return the user to after submitting a rating. Can be left null for ajax requests.&lt;br /&gt;
assesstimestart. Only allow rating of items created after this timestamp.&lt;br /&gt;
assesstimefinish. Only allow rating of items created before this timestamp.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function get_ratings($options) {&lt;br /&gt;
 global $DB, $USER;&lt;br /&gt;
 &lt;br /&gt;
    if (isnull($userid)) {&lt;br /&gt;
        $userid = $USER-&amp;gt;id;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
    $itemids = array();&lt;br /&gt;
    foreach($items as $item) {&lt;br /&gt;
        $itemids[] = $item-&amp;gt;id;&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    list($itemidtest, $params) = $DB-&amp;gt;get_in_or_equal(&lt;br /&gt;
            $itemids, SQL_PARAMS_NAMED, &amp;#039;itemid0000&amp;#039;);&lt;br /&gt;
 &lt;br /&gt;
    $sql = &amp;quot;SELECT r.itemid, ur.id, ur.userid, ur.scaleid,&lt;br /&gt;
    $aggregatestr(r.rating) AS aggrrating,&lt;br /&gt;
    COUNT(r.rating) AS numratings,&lt;br /&gt;
    ur.rating AS usersrating&lt;br /&gt;
FROM {ratings} r&lt;br /&gt;
LEFT JOIN {ratings} ur ON ur.contextid = r.contextid AND&lt;br /&gt;
        ur.itemid = r.itemid AND&lt;br /&gt;
        ur.userid = :userid&lt;br /&gt;
WHERE&lt;br /&gt;
    r.contextid = :contextid AND&lt;br /&gt;
    r.itemid $itemidtest&lt;br /&gt;
GROUP BY r.itemid, ur.rating&lt;br /&gt;
ORDER BY r.itemid&amp;quot;;&lt;br /&gt;
 &lt;br /&gt;
    $params[&amp;#039;userid&amp;#039;] = $userid;&lt;br /&gt;
    $params[&amp;#039;contextid&amp;#039;] = $context-&amp;gt;id;&lt;br /&gt;
 &lt;br /&gt;
    //add ratings to the items at $item-&amp;gt;rating. Similar to make_context_subobj().&lt;br /&gt;
    //Iterate over forum $items (forum posts, glossary items etc) and create the  $item-&amp;gt;rating objects. Properties of the individual ratings, such as $item-&amp;gt;rating-&amp;gt;aggregate and $item-&amp;gt;rating-&amp;gt;rating, are stored on the rating object directly.&lt;br /&gt;
    //Settings common to the ratings are stored at $item-&amp;gt;rating-&amp;gt;settings-&amp;gt;aggregationmethod (for example).&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====get_aggregation_method($aggregate)====&lt;br /&gt;
Converts the aggregation method constants to a string that can be included in SQL&lt;br /&gt;
&lt;br /&gt;
====get_all_ratings_for_item($options)====&lt;br /&gt;
Load all ratings for a given item. Used to display a listing of submitted ratings to users with &amp;#039;viewall&amp;#039; permission.&lt;br /&gt;
&lt;br /&gt;
Requires context, itemid and optionally accepts an SQL order by clause.&lt;br /&gt;
&lt;br /&gt;
====get_user_grades($options)====&lt;br /&gt;
Returns a grade for a user based on other user&amp;#039;s rating of their items.&lt;br /&gt;
&lt;br /&gt;
===Rendering ratings===&lt;br /&gt;
&lt;br /&gt;
As rendering a rating will consist of only a single function call a new method called render_rating() will be added to the core renderer.&lt;br /&gt;
&lt;br /&gt;
If necessary a ratings renderer could be added. Located in mod/ratings/renderer.php this new class core_rating_renderer should extend plugin_renderer_base defined in lib/outputrenderers.php Almost all renderers appear to inherit from plugin_renderer_base rather than core_renderer.&lt;br /&gt;
&lt;br /&gt;
=====core_renderer::render_rating(rating $rating)=====&lt;br /&gt;
&lt;br /&gt;
returns rating UI html snippet. Used to include ratings in pages.&lt;br /&gt;
&lt;br /&gt;
===Using the rating renderer===&lt;br /&gt;
&lt;br /&gt;
The process to render ratings is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
// in mod/forum/discuss.php (for example)&lt;br /&gt;
$posts = // Some forum/lib.php function call.&lt;br /&gt;
&lt;br /&gt;
//these are supplied by the calling module (forum etc)&lt;br /&gt;
$aggregate = &lt;br /&gt;
$scaleid = &lt;br /&gt;
$userid =&lt;br /&gt;
$returnurl = &lt;br /&gt;
&lt;br /&gt;
//The current scaleid comes from the forum or glossary object and may be changed at any time so supply it each time&lt;br /&gt;
//Also, a user should only see their own ratings&lt;br /&gt;
$posts = rating::load_ratings($context, &lt;br /&gt;
    $posts/* Optional array of items (forum posts or glossary items) with an &amp;#039;id&amp;#039; property. If null returns all ratings for the context by the user*/, &lt;br /&gt;
    $aggregate, &lt;br /&gt;
    $scaleid, &lt;br /&gt;
    $userid, &lt;br /&gt;
    $returnurl);&lt;br /&gt;
&lt;br /&gt;
//ratings are now attached to the post objects. $posts[0]-&amp;gt;rating&lt;br /&gt;
&lt;br /&gt;
foreach ($posts as $postid =&amp;gt; $post) {&lt;br /&gt;
    $forumoutput-&amp;gt;post($post);//access the rating info at $post-&amp;gt;rating, $post-&amp;gt;rating-&amp;gt;aggregate and $post-&amp;gt;rating-&amp;gt;count&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
// in mod/forum/renderer.php, in the post($post) method:&lt;br /&gt;
&lt;br /&gt;
// ... output most of the post ... starts around line 5813 of mod/forum/lib.php&lt;br /&gt;
echo $OUTPUT-&amp;gt;render($item-&amp;gt;rating);&lt;br /&gt;
// ... output the rest.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
// and finally in rating/lib.php in the rating class:&lt;br /&gt;
&lt;br /&gt;
public function core_renderer::render_rating(rating $rating) {&lt;br /&gt;
    //return html representation of the rating&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
===Ratings Aggregation===&lt;br /&gt;
Forums currently support multiple forms of rating aggregation such as average, maximum, sum etc. These options should be available everywhere that ratings are available.&lt;br /&gt;
&lt;br /&gt;
They are calculated within rating::ratings_load_ratings()&lt;br /&gt;
&lt;br /&gt;
===Ratings Settings===&lt;br /&gt;
Settings for ratings are stored by the module. Each module table, for example forum, must contain the following columns.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Default&lt;br /&gt;
! Info&lt;br /&gt;
|-&lt;br /&gt;
| assessed&lt;br /&gt;
| int(10)&lt;br /&gt;
| &lt;br /&gt;
| The aggregation method to apply. A value of 0 means ratings should be disabled. Currently the glossary stores an &amp;quot;allcanrate&amp;quot; flag in the assessed column. &amp;quot;allcanrate&amp;quot; will disappear in favour of proper permissions.&lt;br /&gt;
|-&lt;br /&gt;
| assesstimestart&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| From when can users submit ratings&lt;br /&gt;
|-&lt;br /&gt;
| assesstimefinish&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| When must users submit ratings by&lt;br /&gt;
|-&lt;br /&gt;
| scale&lt;br /&gt;
| int(10)&lt;br /&gt;
|&lt;br /&gt;
| What scale to use&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The &amp;quot;Restrict ratings to posts with dates in this range&amp;quot; flag is calculated in the course/moodleforum_mod.php method moodleform::data_preprocessing() and is not stored in the database.&lt;br /&gt;
&lt;br /&gt;
====Settings interface====&lt;br /&gt;
=====moodleform_mod::standard_coursemodule_elements()=====&lt;br /&gt;
Adds elements to an instance of moodle form. The ratings elements should appear in a separate block from Common Module Settings.&lt;br /&gt;
&lt;br /&gt;
It will determine whether to include ratings settings by calling plugin_supports() found in lib/moodlelib.php like this...&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (plugin_supports(&amp;#039;mod&amp;#039;, $this-&amp;gt;_modname, FEATURE_RATINGS, false)) {&lt;br /&gt;
    //include ratings elements&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
mod/%modulename%/lib.php defines a function called %modulename%_supports() that lists the elements that the module supports.&lt;br /&gt;
&lt;br /&gt;
FEATURE_MOD_RATINGS will have to be added to lib/moodlelib.php&lt;br /&gt;
&lt;br /&gt;
===Rating Submission===&lt;br /&gt;
&lt;br /&gt;
rating/rate.php will be the target for posted ratings. Previously each module implemented their own ratings submission. For example mod/glossary/rate.php within the glossary module.&lt;br /&gt;
&lt;br /&gt;
The supplied fields should consist of&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
! Field&lt;br /&gt;
! Type&lt;br /&gt;
! Default&lt;br /&gt;
! Info&lt;br /&gt;
|-&lt;br /&gt;
| contextid&lt;br /&gt;
| PARAM_INT&lt;br /&gt;
|&lt;br /&gt;
| The context id defined in context table - identifies the instance of plugin owning the comment.&lt;br /&gt;
|-&lt;br /&gt;
| itemid&lt;br /&gt;
| PARAM_INT&lt;br /&gt;
|&lt;br /&gt;
| Some plugin specific item id (eg. forum post blog entry)&lt;br /&gt;
|-&lt;br /&gt;
| scaleid&lt;br /&gt;
| PARAM_INT&lt;br /&gt;
|&lt;br /&gt;
| ID of the scale (1-5, 0-100, custom) from which the user selected their rating. Including this allows smarter handling of scales being changed.&lt;br /&gt;
|-&lt;br /&gt;
| rating&lt;br /&gt;
| PARAM_INT&lt;br /&gt;
|&lt;br /&gt;
| for example, in user profile, you can comment user&amp;#039;s description or interests, but they share the same itemid(==userid), we need comment_area to separate them&lt;br /&gt;
|-&lt;br /&gt;
| returnurl&lt;br /&gt;
| PARAM_LOCALURL&lt;br /&gt;
|&lt;br /&gt;
| Null for ajax requests. If not null the url to which the user should be redirected after recording the rating&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
The process to record a rating is as follows:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
$permissions = forum_rating_permission();&lt;br /&gt;
if($permissions[&amp;#039;post&amp;#039;]) {&lt;br /&gt;
$rating = N; //the actual rating from the user&lt;br /&gt;
$ratingObj = new rating($contextid, $scaleid, $userid, array($itemid));&lt;br /&gt;
$ratingObj-&amp;gt;set_rating($rating);&lt;br /&gt;
//redirect to return url if supplied&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
//within the class rating&lt;br /&gt;
function Rating::update_rating($rating) {&lt;br /&gt;
$ratings = rating_system::load_ratings($scaleid, $userid, $contextid, array($itemid));&lt;br /&gt;
if( !$ratings || sizeof($ratings)==0) {&lt;br /&gt;
$data-&amp;gt;contextid    = $this-&amp;gt;contextid;&lt;br /&gt;
$data-&amp;gt;scaleid      = $this-&amp;gt;scaleid;&lt;br /&gt;
$data-&amp;gt;userid       = $this-&amp;gt;userid;&lt;br /&gt;
$data-&amp;gt;rating       = $rating;&lt;br /&gt;
$DB-&amp;gt;insert_record($this-&amp;gt;table, $data);&lt;br /&gt;
}&lt;br /&gt;
else {&lt;br /&gt;
$data-&amp;gt;id       = $this-&amp;gt;id;&lt;br /&gt;
$data-&amp;gt;rating   = $rating;&lt;br /&gt;
$DB-&amp;gt;update_record($this-&amp;gt;table, $data);&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
====Ajax submission====&lt;br /&gt;
Ajax submission of ratings must be possible for sites with ajax enabled. ForumNG (http://moodle.org/mod/data/view.php?d=13&amp;amp;rid=2927) written by Sam Marshall contains an ajax implementation of the rating UI elements that may be useful to reference.&lt;br /&gt;
&lt;br /&gt;
Check if ajax is enabled like this...&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
if (empty($CFG-&amp;gt;enableajax)) {&lt;br /&gt;
    //no ajax&lt;br /&gt;
}&lt;br /&gt;
else {&lt;br /&gt;
    //add ajax stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Permissions changes ===&lt;br /&gt;
&lt;br /&gt;
Ratings is dependent on two things: core capabilities and the result of a module callback (which may itself use module capabilities).&lt;br /&gt;
&lt;br /&gt;
====New ratings permissions====&lt;br /&gt;
&lt;br /&gt;
New system-wide ratings permissions will be added.  These will be checked IN ADDITION to local permissions in existing modules.&lt;br /&gt;
&lt;br /&gt;
It is anticipated most new modules will just use these.&lt;br /&gt;
&lt;br /&gt;
The new capabilities are:&lt;br /&gt;
&lt;br /&gt;
moodle/rating:view - allows the user to view aggregated ratings made on their own items&lt;br /&gt;
&lt;br /&gt;
moodle/rating:viewany - allows the user to view aggregated ratings made on other people&amp;#039;s items&lt;br /&gt;
&lt;br /&gt;
moodle/rating:viewall - allows the user to see individual ratings&lt;br /&gt;
&lt;br /&gt;
moodle/rating:rate - allows the user to make ratings on other people&amp;#039;s items&lt;br /&gt;
&lt;br /&gt;
====Handling of old permissions====&lt;br /&gt;
&lt;br /&gt;
Pre-existing module-specific permissions will be extended to have matching names/behaviour with the new rating permissions.&lt;br /&gt;
&lt;br /&gt;
*mod/data:rate  - unchanged&lt;br /&gt;
*mod/data:viewrating   - unchanged &lt;br /&gt;
*mod/data:viewanyrating - cloned from old mod/data:viewrating&lt;br /&gt;
*mod/data:viewallratings - cloned from old mod/data:viewrating&lt;br /&gt;
*mod/forum:rate - unchanged&lt;br /&gt;
*mod/forum:viewrating - unchanged&lt;br /&gt;
*mod/forum:viewanyrating - unchanged&lt;br /&gt;
*mod/forum:viewallratings - cloned from old mod/forum:viewanyrating&lt;br /&gt;
*mod/glossary:rate   - unchanged&lt;br /&gt;
*mod/glossary:viewrating   - unchanged&lt;br /&gt;
*mod/glossary:viewanyrating - cloned from old mod/glossary:viewrating&lt;br /&gt;
*mod/glossary:viewallratings - cloned from old mod/glossary:viewrating&lt;br /&gt;
&lt;br /&gt;
===Module callbacks===&lt;br /&gt;
&lt;br /&gt;
These allow modules to control how ratings behave.&lt;br /&gt;
&lt;br /&gt;
====modname_rating_validate====&lt;br /&gt;
&lt;br /&gt;
As of Moodle 2.0.3 modules must implement a function named &amp;#039;&amp;#039;&amp;#039;modname_rating_validate&amp;#039;&amp;#039;&amp;#039; to verify the validity of submitted ratings.&lt;br /&gt;
&lt;br /&gt;
This function must return true if the rating is valid or throw an instance of rating_exception if the rating is invalid. Note: false is used to indicate that the module hasn&amp;#039;t implemented this callback.&lt;br /&gt;
&lt;br /&gt;
This example shows how this would work for the forum module&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function forum_rating_validate($params) {&lt;br /&gt;
    if (!array_key_exists(&amp;#039;itemid&amp;#039;, $params) || !array_key_exists(&amp;#039;context&amp;#039;, $params) || !array_key_exists(&amp;#039;rateduserid&amp;#039;, $params)) {&lt;br /&gt;
        throw new rating_exception(&amp;#039;missingparameter&amp;#039;);&lt;br /&gt;
    }&lt;br /&gt;
    return true;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
The rating_exception argument is the name of a string in the error language file.&lt;br /&gt;
&lt;br /&gt;
The $params argument contains:&lt;br /&gt;
* context - object the context in which the rated items exists [required]&lt;br /&gt;
* itemid - int the ID of the object being rated&lt;br /&gt;
* scaleid - int the scale from which the user can select a rating. Used for bounds checking. [required]&lt;br /&gt;
* rating - int the submitted rating&lt;br /&gt;
* rateduserid - int the id of the user whose items have been rated. NOT the user who submitted the ratings. 0 to update all. [required]&lt;br /&gt;
* aggregation - int the aggregation method to apply when calculating grades ie RATING_AGGREGATE_AVERAGE [required]&lt;br /&gt;
&lt;br /&gt;
====modname_rating_permissions====&lt;br /&gt;
Modules must implement a function named &amp;#039;&amp;#039;&amp;#039;modname_rating_permissions&amp;#039;&amp;#039;&amp;#039; to control post and view permission. This is called prior to rendering a set of ratings. It is also called by rating/rate.php and rate/rate_ajax.php when they receive rating submissions.&lt;br /&gt;
&lt;br /&gt;
Modules do not need to implement this.  It&amp;#039;s mostly provided for backward compatibility with modules that had complicated ratings related logic or for modules that use settings other than capabilities to control ratings behavior.&lt;br /&gt;
&lt;br /&gt;
This function will return an array: array(&amp;#039;view&amp;#039;=&amp;gt;true, &amp;#039;viewany&amp;#039;=&amp;gt;true, &amp;#039;viewall&amp;#039;=&amp;gt;true, &amp;#039;rate&amp;#039;=&amp;gt;true)&lt;br /&gt;
&lt;br /&gt;
This example shows how this would work for the forum module&lt;br /&gt;
&amp;lt;code php&amp;gt;&lt;br /&gt;
function forum_rating_permissions($context) {&lt;br /&gt;
    return array(&amp;#039;view&amp;#039;=&amp;gt;has_capability(&amp;#039;mod/forum:viewrating&amp;#039;,$context), &lt;br /&gt;
                 &amp;#039;viewany&amp;#039;=&amp;gt;has_capability(&amp;#039;mod/forum:viewanyrating&amp;#039;,$context), &lt;br /&gt;
                 &amp;#039;viewall&amp;#039;=&amp;gt;has_capability(&amp;#039;mod/forum:viewallratings&amp;#039;,$context), &lt;br /&gt;
                 &amp;#039;rate&amp;#039;=&amp;gt;has_capability(&amp;#039;mod/forum:rate&amp;#039;,$context));&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==See also==&lt;br /&gt;
&lt;br /&gt;
* MDL-21657 Implement Ratings 2.0&lt;br /&gt;
&lt;br /&gt;
[[Category:Grades]]&lt;/div&gt;</summary>
		<author><name>1&gt;Mudrd8mz</name></author>
	</entry>
</feed>