Moodle  2.2.1
http://www.collinsharper.com
rating_manager Class Reference
Inheritance diagram for rating_manager:

Public Member Functions

 delete_ratings ($options)
 get_all_ratings_for_item ($options)
 get_ratings ($options)
 get_user_grades ($options)
 get_aggregate_types ()
 get_aggregation_method ($aggregate)
 get_plugin_permissions_array ($contextid, $component, $ratingarea)
 check_rating_is_valid ($params)
 initialise_rating_javascript (moodle_page $page)
 get_aggregate_label ($aggregationmethod)

Protected Member Functions

 generate_rating_settings_object ($options)
 generate_rating_scale_object ($scaleid)
 get_item_time_created ($item)

Protected Attributes

 $scales = array()

Detailed Description

The rating_manager class provides the ability to retrieve sets of ratings from the database

Since:
Moodle 2.0

Definition at line 391 of file lib.php.


Member Function Documentation

check_rating_is_valid ( params)

Validates a submitted rating

Parameters:
array$paramssubmitted data context => object the context in which the rated items exists [required] component => The component the rating belongs to [required] ratingarea => The ratingarea the rating is associated with [required] itemid => int the ID of the object being rated [required] scaleid => int the scale from which the user can select a rating. Used for bounds checking. [required] rating => int the submitted rating rateduserid => int the id of the user whose items have been rated. NOT the user who submitted the ratings. 0 to update all. [required] aggregation => int the aggregation method to apply when calculating grades ie RATING_AGGREGATE_AVERAGE [optional]
Returns:
boolean true if the rating is valid. False if callback wasnt found and will throw rating_exception if rating is invalid

Definition at line 971 of file lib.php.

Here is the call graph for this function:

delete_ratings ( options)

Delete one or more ratings. Specify either a rating id, an item id or just the context id.

moodle_database $DB

Parameters:
stdClass$options{ contextid => int the context in which the ratings exist [required] ratingid => int the id of an individual rating to delete [optional] userid => int delete the ratings submitted by this user. May be used in conjuction with itemid [optional] itemid => int delete all ratings attached to this item [optional] component => string The component to delete ratings from [optional] ratingarea => string The ratingarea to delete ratings from [optional] }
Returns:
void

Definition at line 413 of file lib.php.

generate_rating_scale_object ( scaleid) [protected]

Generates a scale object that can be returned

moodle_database $DB

Parameters:
type$scaleid
Returns:
stdClass

Definition at line 711 of file lib.php.

generate_rating_settings_object ( options) [protected]

Generates a rating settings object based upon the options it is provided.

Parameters:
stdClass$options{ context => context the context in which the ratings exists [required] component => string The component the items belong to [required] ratingarea => string The ratingarea the items belong to [required] aggregate => int what aggregation method should be applied. RATING_AGGREGATE_AVERAGE, RATING_AGGREGATE_MAXIMUM etc [required] scaleid => int the scale from which the user can select a rating [required] returnurl => string the url to return the user to after submitting a rating. Can be left null for ajax requests [optional] assesstimestart => int only allow rating of items created after this timestamp [optional] assesstimefinish => int only allow rating of items created before this timestamp [optional] plugintype => string plugin type ie 'mod' Used to find the permissions callback [optional] pluginname => string plugin name ie 'forum' Used to find the permissions callback [optional] }
Returns:
stdClass

Definition at line 650 of file lib.php.

Here is the call graph for this function:

get_aggregate_label ( aggregationmethod)

Returns a string that describes the aggregation method that was provided.

Parameters:
string$aggregationmethod
Returns:
string

Definition at line 1035 of file lib.php.

Returns array of aggregate types. Used by ratings.

Returns:
array

Definition at line 900 of file lib.php.

get_aggregation_method ( aggregate)

Converts an aggregation method constant into something that can be included in SQL

Parameters:
int$aggregateAn aggregation constant. For example, RATING_AGGREGATE_AVERAGE.
Returns:
string an SQL aggregation method

Definition at line 914 of file lib.php.

Here is the call graph for this function:

get_all_ratings_for_item ( options)

Returns an array of ratings for a given item (forum post, glossary entry etc) This returns all users ratings for a single item

Parameters:
stdClass$options{ context => context the context in which the ratings exists [required] component => component using ratings ie mod_forum [required] ratingarea => ratingarea to associate this rating with [required] itemid => int the id of the associated item (forum post, glossary item etc) [required] sort => string SQL sort by clause [optional] }
Returns:
array an array of ratings

Definition at line 448 of file lib.php.

Here is the call graph for this function:

get_item_time_created ( item) [protected]

Gets the time the given item was created

TODO: Find a better solution for this, its not ideal to test for fields really we should be asking the component the item belongs to what field to look for or even the value we are looking for.

Parameters:
stdClass$item
Returns:
mixed

Definition at line 760 of file lib.php.

get_plugin_permissions_array ( contextid,
component,
ratingarea 
)

Looks for a callback like forum_rating_permissions() to retrieve permissions from the plugin whose items are being rated

Parameters:
int$contextidThe current context id
stringcomponent the name of the component that is using ratings ie 'mod_forum'
stringratingarea The area the rating is associated with
Returns:
array rating related permissions

Reimplemented in mockup_rating_manager.

Definition at line 946 of file lib.php.

Here is the call graph for this function:

get_ratings ( options)

Adds rating objects to an array of items (forum posts, glossary entries etc) Rating objects are available at $item->rating

Parameters:
stdClass$options{ context => context the context in which the ratings exists [required] component => the component name ie mod_forum [required] ratingarea => the ratingarea we are interested in [required] items => array an array of items such as forum posts or glossary items. They must have an 'id' member ie $items[0]->id[required] aggregate => int what aggregation method should be applied. RATING_AGGREGATE_AVERAGE, RATING_AGGREGATE_MAXIMUM etc [required] scaleid => int the scale from which the user can select a rating [required] userid => int the id of the current user [optional] returnurl => string the url to return the user to after submitting a rating. Can be left null for ajax requests [optional] assesstimestart => int only allow rating of items created after this timestamp [optional] assesstimefinish => int only allow rating of items created before this timestamp [optional]
Returns:
array the array of items with their ratings attached at $items[0]->rating

Definition at line 504 of file lib.php.

Here is the call graph for this function:

get_user_grades ( options)

Returns an array of grades calculated by aggregating item ratings.

Parameters:
object$options{ userid => int the id of the user whose items have been rated. NOT the user who submitted the ratings. 0 to update all. [required] aggregationmethod => int the aggregation method to apply when calculating grades ie RATING_AGGREGATE_AVERAGE [required] scaleid => int the scale from which the user can select a rating. Used for bounds checking. [required] itemtable => int the table containing the items [required] itemtableusercolum => int the column of the user table containing the item owner's user id [required] component => The component for the ratings [required] ratingarea => The ratingarea for the ratings [required]

contextid => int the context in which the rated items exist [optional]

modulename => string the name of the module [optional] moduleid => int the id of the module instance [optional]

Returns:
array the array of the user's grades

Definition at line 790 of file lib.php.

Here is the call graph for this function:

Initialises JavaScript to enable AJAX ratings on the provided page

Parameters:
moodle_page$page
Returns:
true

Definition at line 1012 of file lib.php.


Field Documentation

$scales = array() [protected]

Definition at line 397 of file lib.php.


The documentation for this class was generated from the following file:
 All Data Structures Namespaces Files Functions Variables Enumerations