本文整理汇总了PHP中rating_manager::get_all_ratings_for_item方法的典型用法代码示例。如果您正苦于以下问题:PHP rating_manager::get_all_ratings_for_item方法的具体用法?PHP rating_manager::get_all_ratings_for_item怎么用?PHP rating_manager::get_all_ratings_for_item使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rating_manager
的用法示例。
在下文中一共展示了rating_manager::get_all_ratings_for_item方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: forum_get_ratings
/**
* Returns a list of ratings for a particular post - sorted.
*
* TODO: Check if this function is actually used anywhere.
* Up until the fix for MDL-27471 this function wasn't even returning.
*
* @param stdClass $context
* @param int $postid
* @param string $sort
* @return array Array of ratings or false
*/
function forum_get_ratings($context, $postid, $sort = "u.firstname ASC") {
$options = new stdClass;
$options->context = $context;
$options->component = 'mod_forum';
$options->ratingarea = 'post';
$options->itemid = $postid;
$options->sort = "ORDER BY $sort";
$rm = new rating_manager();
return $rm->get_all_ratings_for_item($options);
}
示例2: forum_get_ratings
/**
* Returns a list of ratings for a particular post - sorted.
*
* @global object
* @global object
* @param int $postid
* @param string $sort
* @return array Array of ratings or false
*/
function forum_get_ratings($context, $postid, $sort="u.firstname ASC") {
global $PAGE;
$options = new stdclass();
$options->context = $PAGE->context;
$options->itemid = $postid;
$options->sort = "ORDER BY $sort";
$rm = new rating_manager();
$rm->get_all_ratings_for_item($options);
}
示例3: quora_get_ratings
/**
* Returns a list of ratings for a particular post - sorted.
*
* @param stdClass $context
* @param int $postid
* @param string $sort
* @return array Array of ratings or false
* @deprecated since Moodle 2.0 MDL-21657 - please do not use this function any more.
*/
function quora_get_ratings($context, $postid, $sort = "u.firstname ASC")
{
debugging('quora_get_ratings() is deprecated.', DEBUG_DEVELOPER);
$options = new stdClass();
$options->context = $context;
$options->component = 'mod_quora';
$options->ratingarea = 'post';
$options->itemid = $postid;
$options->sort = "ORDER BY {$sort}";
$rm = new rating_manager();
return $rm->get_all_ratings_for_item($options);
}
示例4: get_item_ratings
/**
* Retrieve a list of ratings for a given item (forum post etc)
*
* @param string $contextlevel course, module, user...
* @param int $instanceid the instance if for the context element
* @param string $component the name of the component
* @param string $ratingarea rating area
* @param int $itemid the item id
* @param int $scaleid the scale id
* @param string $sort sql order (firstname, rating or timemodified)
* @return array Result and possible warnings
* @throws moodle_exception
* @since Moodle 2.9
*/
public static function get_item_ratings($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $sort)
{
global $USER, $PAGE;
$warnings = array();
$arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'sort' => $sort);
// Validate and normalize parameters.
$params = self::validate_parameters(self::get_item_ratings_parameters(), $arrayparams);
$context = self::get_context_from_params($params);
self::validate_context($context);
// Minimal capability required.
$callbackparams = array('contextid' => $context->id, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid);
if (!has_capability('moodle/rating:view', $context) || !component_callback($component, 'rating_can_see_item_ratings', array($callbackparams), true)) {
throw new moodle_exception('noviewrate', 'rating');
}
list($context, $course, $cm) = get_context_info_array($context->id);
// Can we see all ratings?
$canviewallratings = has_capability('moodle/rating:viewall', $context);
// Create the Sql sort order string.
switch ($params['sort']) {
case 'firstname':
$sqlsort = "u.firstname ASC";
break;
case 'rating':
$sqlsort = "r.rating ASC";
break;
default:
$sqlsort = "r.timemodified ASC";
}
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->component = $params['component'];
$ratingoptions->ratingarea = $params['ratingarea'];
$ratingoptions->itemid = $params['itemid'];
$ratingoptions->sort = $sqlsort;
$rm = new rating_manager();
$ratings = $rm->get_all_ratings_for_item($ratingoptions);
$scalemenu = make_grades_menu($params['scaleid']);
// If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
// We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
$maxrating = max(array_keys($scalemenu));
$results = array();
foreach ($ratings as $rating) {
if ($canviewallratings || $USER->id == $rating->userid) {
if ($rating->rating > $maxrating) {
$rating->rating = $maxrating;
}
// The rating object has all the required fields for generating the picture url.
$userpicture = new user_picture($rating);
$userpicture->size = 1;
// Size f1.
$profileimageurl = $userpicture->get_url($PAGE)->out(false);
$result = array();
$result['id'] = $rating->id;
$result['userid'] = $rating->userid;
$result['userpictureurl'] = $profileimageurl;
$result['userfullname'] = fullname($rating);
$result['rating'] = $scalemenu[$rating->rating];
$result['timemodified'] = $rating->timemodified;
$results[] = $result;
}
}
return array('ratings' => $results, 'warnings' => $warnings);
}
示例5: get_item_ratings
/**
* Retrieve a list of ratings for a given item (forum post etc)
*
* @param string $contextlevel course, module, user...
* @param int $instanceid the instance if for the context element
* @param string $component the name of the component
* @param string $ratingarea rating area
* @param int $itemid the item id
* @param int $scaleid the scale id
* @param string $sort sql order (firstname, rating or timemodified)
* @return array Result and possible warnings
* @throws moodle_exception
* @since Moodle 2.9
*/
public static function get_item_ratings($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $sort)
{
global $USER;
$warnings = array();
$arrayparams = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'sort' => $sort);
// Validate and normalize parameters.
$params = self::validate_parameters(self::get_item_ratings_parameters(), $arrayparams);
$context = self::get_context_from_params($params);
self::validate_context($context);
// Minimal capability required.
if (!has_capability('moodle/rating:view', $context)) {
throw new moodle_exception('noviewrate', 'rating');
}
list($context, $course, $cm) = get_context_info_array($context->id);
// Can we see all ratings?
$canviewallratings = has_capability('moodle/rating:viewall', $context);
// Create the Sql sort order string.
switch ($params['sort']) {
case 'firstname':
$sqlsort = "u.firstname ASC";
break;
case 'rating':
$sqlsort = "r.rating ASC";
break;
default:
$sqlsort = "r.timemodified ASC";
}
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->component = $params['component'];
$ratingoptions->ratingarea = $params['ratingarea'];
$ratingoptions->itemid = $params['itemid'];
$ratingoptions->sort = $sqlsort;
$rm = new rating_manager();
$ratings = $rm->get_all_ratings_for_item($ratingoptions);
$scalemenu = make_grades_menu($params['scaleid']);
// If the scale was changed after ratings were submitted some ratings may have a value above the current maximum.
// We can't just do count($scalemenu) - 1 as custom scales start at index 1, not 0.
$maxrating = max(array_keys($scalemenu));
$results = array();
foreach ($ratings as $rating) {
if ($canviewallratings || $USER->id == $rating->userid) {
if ($rating->rating > $maxrating) {
$rating->rating = $maxrating;
}
$profileimageurl = '';
// We can have ratings from deleted users. In this case, those users don't have a valid context.
$usercontext = context_user::instance($rating->userid, IGNORE_MISSING);
if ($usercontext) {
$profileimageurl = moodle_url::make_webservice_pluginfile_url($usercontext->id, 'user', 'icon', null, '/', 'f1')->out(false);
}
$result = array();
$result['id'] = $rating->id;
$result['userid'] = $rating->userid;
$result['userpictureurl'] = $profileimageurl;
$result['userfullname'] = fullname($rating);
$result['rating'] = $scalemenu[$rating->rating];
$result['timemodified'] = $rating->timemodified;
$results[] = $result;
}
}
return array('ratings' => $results, 'warnings' => $warnings);
}