本文整理匯總了PHP中rating_manager::get_aggregation_method方法的典型用法代碼示例。如果您正苦於以下問題:PHP rating_manager::get_aggregation_method方法的具體用法?PHP rating_manager::get_aggregation_method怎麽用?PHP rating_manager::get_aggregation_method使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類rating_manager
的用法示例。
在下文中一共展示了rating_manager::get_aggregation_method方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: oublog_get_user_grades
/**
* Return grade for given user or all users.
*
* @global object
* @param object $dataplus
* @param int $userid optional user id, 0 means all users
* @return array array of grades, false if none
*/
function oublog_get_user_grades($oublog, $userid = 0)
{
global $CFG, $DB;
require_once $CFG->dirroot . '/rating/lib.php';
require_once $CFG->dirroot . '/mod/oublog/locallib.php';
$options = new stdClass();
$options->component = 'mod_oublog';
$options->ratingarea = 'post';
$options->modulename = 'oublog';
$options->moduleid = $oublog->id;
$options->userid = $userid;
$options->aggregationmethod = $oublog->assessed;
$options->scaleid = $oublog->scale;
$options->cmid = $oublog->cmidnumber;
// There now follows a lift of get_user_grades() from rating lib
// but with the requirement for items modified.
$rm = new rating_manager();
if (!isset($options->component)) {
throw new coding_exception('The component option is now a required option when getting user grades from ratings.');
}
if (!isset($options->ratingarea)) {
throw new coding_exception('The ratingarea option is now a required option when getting user grades from ratings.');
}
// Going direct to the db for the context id seemed wrong.
$context = context_module::instance($options->cmid);
$params = array();
$params['contextid'] = $context->id;
$params['component'] = $options->component;
$params['ratingarea'] = $options->ratingarea;
$scaleid = $options->scaleid;
$aggregationstring = $rm->get_aggregation_method($options->aggregationmethod);
// If userid is not 0 we only want the grade for a single user.
$singleuserwhere = '';
if ($options->userid != 0) {
// Get the grades for the {posts} the user is responsible for.
$cm = get_coursemodule_from_id('oublog', $oublog->cmidnumber);
list($posts, $recordcount) = oublog_get_posts($oublog, $context, 0, $cm, 0, $options->userid);
foreach ($posts as $post) {
$postids[] = (int) $post->id;
}
$params['userid'] = $userid;
$singleuserwhere = " AND i.userid = :userid";
}
$sql = "SELECT u.id as id, u.id AS userid, {$aggregationstring}(r.rating) AS rawgrade\n FROM {oublog} o\n JOIN {oublog_instances} i ON i.oublogid = o.id\n JOIN {oublog_posts} p ON p.oubloginstancesid = i.id\n JOIN {rating} r ON r.itemid = p.id\n JOIN {user} u ON i.userid = u.id\n WHERE r.contextid = :contextid\n AND r.component = :component\n AND r.ratingarea = :ratingarea\n {$singleuserwhere}\n GROUP BY u.id";
$results = $DB->get_records_sql($sql, $params);
if ($results) {
$scale = null;
$max = 0;
if ($options->scaleid >= 0) {
// Numeric.
$max = $options->scaleid;
} else {
// Custom scales.
$scale = $DB->get_record('scale', array('id' => -$options->scaleid));
if ($scale) {
$scale = explode(',', $scale->scale);
$max = count($scale);
} else {
debugging('rating_manager::get_user_grades() received a scale ID that doesnt exist');
}
}
// It could throw off the grading if count and sum returned a rawgrade higher than scale
// so to prevent it we review the results and ensure that rawgrade does not exceed
// the scale, if it does we set rawgrade = scale (i.e. full credit).
foreach ($results as $rid => $result) {
if ($options->scaleid >= 0) {
// Numeric.
if ($result->rawgrade > $options->scaleid) {
$results[$rid]->rawgrade = $options->scaleid;
}
} else {
// Scales.
if (!empty($scale) && $result->rawgrade > $max) {
$results[$rid]->rawgrade = $max;
}
}
}
}
return $results;
}