$string['noviewanyrate'] = 'You can only look at results for posts that you made';
$string['ratepermissiondenied'] = 'You do not have permission to rate this item';
$string['ratingsuse'] = 'Use ratings';
-$string['sessionexpired'] = 'Your session has expired. Please log in again.';
* @param $page the page object on which this rating will appear
*/
function render_rating(rating $rating) {
- global $CFG, $USER, $PAGE;
+ global $CFG, $USER;
static $havesetupjavascript = false;
if( !$havesetupjavascript && !empty($CFG->enableajax) ) {
- $PAGE->requires->js_init_call('M.core_ratings.init');
+ $this->page->requires->js_init_call('M.core_ratings.init');
$havesetupjavascript = true;
}
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);
-$url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'itemid'=>$itemid));
+$url = new moodle_url('/rating/index.php', array('contextid'=>$contextid,'itemid'=>$itemid,'scaleid'=>$scaleid));
if ($sort !== 0) {
$url->param('sort', $sort);
}
echo "<th class=\"header\" scope=\"col\"><a href=\"report.php?id=$itemid&sort=time\">$strtime</a></th>";
echo "</tr>";
foreach ($ratings as $rating) {
- echo '<tr class="forumpostheader">';
+ echo '<tr class="ratingitemheader">';
echo "<td>";
if($courseid) {
echo $OUTPUT->user_picture($rating, array('courseid'=>$courseid));
* @since Moodle 2.0
*/
class rating implements renderable {
+
+ /**
+ * The context in which this rating exists
+ * @var context
+ */
+ public $context;
+
+ /**
+ * The id of the item (forum post, glossary item etc) being rated
+ * @var int
+ */
+ public $itemid;
+
+ /**
+ * The id scale (1-5, 0-100) that was in use when the rating was submitted
+ * @var int
+ */
+ public $scaleid;
+
+ /**
+ * The id of the user who submitted the rating
+ * @var int
+ */
+ public $userid;
+
/**
* Constructor.
- * @param int $contextid the current context
+ * @param context $context the current context object
* @param int $itemid the id of the associated item (forum post, glossary item etc)
* @param int $scaleid the scale to use
* @param int $userid the user submitting the rating
* Static method that converts an aggregation method constant into something that can be included in SQL
* @param $aggregate An aggregation constant. For example, RATING_AGGREGATE_AVERAGE.
*/
- public static function rating_get_aggregation_method($aggregate) {
+ public static function get_aggregation_method($aggregate) {
$aggregatestr = null;
switch($aggregate){
case RATING_AGGREGATE_AVERAGE:
/**
* Static method that adds rating objects to an array of items (forum posts, glossary entries etc)
* Rating objects are available at $item->rating
- * @param int $contextid the current context
+ * @param context $context the current context object
* @param array $items an array of items such as forum posts or glossary items. They must have an 'id' member ie $items[0]->id
* @param $aggregate what aggregation method should be applied. AVG, MAX etc
* @param int $scaleid the scale from which the user can select a rating
$userid = $USER->id;
}
- $aggregatestr = rating::rating_get_aggregation_method($aggregate);
+ $aggregatestr = rating::get_aggregation_method($aggregate);
//create an array of item ids
$itemids = array();
$result = new stdClass;
if( !isloggedin() && !$returnurl ){ //session has expired and its an ajax request
- $result->error = get_string('sessionexpired', 'ratings');
+ $result->error = get_string('sessionerroruser', 'error');
echo json_encode($result);
die();
}