コード例 #1
0
ファイル: rate_ajax.php プロジェクト: vuchannguyen/web
    echo $OUTPUT->footer();
    die;
}
$rm = new rating_manager();
//check the module rating permissions
//doing this check here rather than within rating_manager::get_ratings so we can return a json error response
$pluginrateallowed = true;
$pluginpermissionsarray = null;
if ($context->contextlevel == CONTEXT_MODULE) {
    $plugintype = 'mod';
    $pluginname = $cm->modname;
    $pluginpermissionsarray = $rm->get_plugin_permissions_array($context->id, $plugintype, $pluginname);
    $pluginrateallowed = $pluginpermissionsarray['rate'];
    if ($pluginrateallowed) {
        //check the item exists and isn't owned by the current user
        $pluginrateallowed = $rm->check_item_and_owner($plugintype, $pluginname, $itemid);
    }
}
if (!$pluginrateallowed || !has_capability('moodle/rating:rate', $context)) {
    $result->error = get_string('ratepermissiondenied', 'rating');
    echo json_encode($result);
    die;
}
$PAGE->set_url('/lib/rate.php', array('contextid' => $context->id));
//rating options used to update the rating then retrieve the aggregate
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->itemid = $itemid;
$ratingoptions->scaleid = $scaleid;
$ratingoptions->userid = $USER->id;
if ($userrating != RATING_UNSET_RATING) {