Moodle PHP Documentation 4.5
Moodle 4.5dev (Build: 20240606) (d3ae1391abe)
rating Class Reference

The rating class represents a single rating by a single user. More...

Inheritance diagram for rating:
renderable

Public Member Functions

 __construct ($options)
 Constructor.
 
 get_aggregate_string ()
 Returns this ratings aggregate value as a string.
 
 get_rate_url ($rating=null, $returnurl=null)
 Returns a URL that can be used to rate the associated item.
 
 get_rating ()
 Retreive the integer value of this rating.
 
 get_view_ratings_url ($popup=false)
 Returns a URL to view all of the ratings for the item this rating is for.
 
 update_rating ($rating)
 Update this rating in the database.
 
 user_can_rate ($userid=null)
 Returns true if the user is able to rate this rating object.
 
 user_can_view_aggregate ($userid=null)
 Returns true if the user is able to view the aggregate for this rating object.
 

Public Attributes

int $aggregate = null
 The aggregate of the combined ratings for the associated item.
 
string $component
 The component using ratings.
 
context $context
 The context in which this rating exists.
 
int $count = 0
 The total number of ratings for the associated item.
 
int $id = null
 The Id of this rating within the rating table.
 
int $itemid
 The id of the item (forum post, glossary item etc) being rated.
 
int $itemtimecreated = null
 The time the associated item was created.
 
int $itemuserid = null
 The id of the user who submitted the rating.
 
int $rating = null
 The rating the associated user gave the associated item.
 
string $ratingarea = null
 The rating area to associate this rating with This allows a plugin to rate more than one thing by specifying different rating areas.
 
int $scaleid
 The id scale (1-5, 0-100) that was in use when the rating was submitted.
 
stdclass $settings
 settings for this rating.
 
int $userid
 The id of the user who submitted the rating.
 

Detailed Description

The rating class represents a single rating by a single user.

License
http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
Since
Moodle 2.0

Constructor & Destructor Documentation

◆ __construct()

rating::__construct ( $options)

Constructor.

Parameters
stdClass$options{ context => context context to use for the rating [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] scaleid => int The scale in use when the rating was submitted [required] userid => int The id of the user who submitted the rating [required] settings => Settings for the rating object [optional] id => The id of this rating (if the rating is from the db) [optional] aggregate => The aggregate for the rating [optional] count => The number of ratings [optional] rating => The rating given by the user [optional] }

Member Function Documentation

◆ get_aggregate_string()

rating::get_aggregate_string ( )

Returns this ratings aggregate value as a string.

Return values
stringratings aggregate value

◆ get_rate_url()

rating::get_rate_url ( $rating = null,
$returnurl = null )

Returns a URL that can be used to rate the associated item.

Parameters
int | null$ratingThe rating to give the item, if null then no rating param is added.
moodle_url | string$returnurlThe URL to return to.
Return values
moodle_urlcan be used to rate the associated item.

◆ get_rating()

rating::get_rating ( )

Retreive the integer value of this rating.

Return values
intthe integer value of this rating object

◆ get_view_ratings_url()

rating::get_view_ratings_url ( $popup = false)

Returns a URL to view all of the ratings for the item this rating is for.

If this is a rating of a post then this URL will take the user to a page that shows all of the ratings for the post (this one included).

Parameters
bool$popupwhether of not the URL should be loaded in a popup
Return values
moodle_urlURL to view all of the ratings for the item this rating is for.

◆ update_rating()

rating::update_rating ( $rating)

Update this rating in the database.

Parameters
int$ratingthe integer value of this rating

◆ user_can_rate()

rating::user_can_rate ( $userid = null)

Returns true if the user is able to rate this rating object.

Parameters
int$useridCurrent user assumed if left empty
Return values
booltrue if the user is able to rate this rating object

◆ user_can_view_aggregate()

rating::user_can_view_aggregate ( $userid = null)

Returns true if the user is able to view the aggregate for this rating object.

Parameters
int | null$useridIf left empty the current user is assumed.
Return values
booltrue if the user is able to view the aggregate for this rating object

Member Data Documentation

◆ $aggregate

int rating::$aggregate = null

The aggregate of the combined ratings for the associated item.

This is only set if the rating already exists

◆ $component

string rating::$component

The component using ratings.

For example "mod_forum"

◆ $count

int rating::$count = 0

The total number of ratings for the associated item.

This is only set if the rating already exists

◆ $id

int rating::$id = null

The Id of this rating within the rating table.

This is only set if the rating already exists

◆ $rating

int rating::$rating = null

The rating the associated user gave the associated item.

This is only set if the rating already exists

◆ $settings

stdclass rating::$settings

settings for this rating.

Necessary to render the rating.


The documentation for this class was generated from the following file: