mirror of
https://github.com/moodle/moodle.git
synced 2025-04-21 08:22:07 +02:00
rating MDL-21657 more changes based on Petr's feedback
This commit is contained in:
parent
5db9b119bd
commit
7ac928a749
@ -9,4 +9,3 @@ $string['noviewrate'] = 'You do not have the capability to view post ratings';
|
||||
$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.';
|
||||
|
@ -1234,11 +1234,11 @@ class core_renderer extends renderer_base {
|
||||
* @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;
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ $sort = optional_param('sort', '', PARAM_ALPHA);
|
||||
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);
|
||||
}
|
||||
@ -80,7 +80,7 @@ if (!$ratings) {
|
||||
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));
|
||||
|
@ -44,9 +44,34 @@ define ('RATING_AGGREGATE_SUM', 5);
|
||||
* @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
|
||||
@ -120,7 +145,7 @@ class rating implements renderable {
|
||||
* 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:
|
||||
@ -168,7 +193,7 @@ class rating implements renderable {
|
||||
/**
|
||||
* 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
|
||||
@ -186,7 +211,7 @@ class rating implements renderable {
|
||||
$userid = $USER->id;
|
||||
}
|
||||
|
||||
$aggregatestr = rating::rating_get_aggregation_method($aggregate);
|
||||
$aggregatestr = rating::get_aggregation_method($aggregate);
|
||||
|
||||
//create an array of item ids
|
||||
$itemids = array();
|
||||
|
@ -40,7 +40,7 @@ $returnurl = optional_param('returnurl', null, PARAM_LOCALURL);//will only be su
|
||||
$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();
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user