当前位置: 首页>>代码示例>>PHP>>正文


PHP rating_manager::add_rating方法代码示例

本文整理汇总了PHP中rating_manager::add_rating方法的典型用法代码示例。如果您正苦于以下问题:PHP rating_manager::add_rating方法的具体用法?PHP rating_manager::add_rating怎么用?PHP rating_manager::add_rating使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在rating_manager的用法示例。


在下文中一共展示了rating_manager::add_rating方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: json_encode

$userrating = required_param('rating', PARAM_INT);
$rateduserid = required_param('rateduserid', PARAM_INT);
// The user being rated. Required to update their grade.
$aggregationmethod = optional_param('aggregation', RATING_AGGREGATE_NONE, PARAM_INT);
// Used to calculate the aggregate to return.
$result = new stdClass();
// If session has expired and its an ajax request so we cant do a page redirect.
if (!isloggedin()) {
    $result->error = get_string('sessionerroruser', 'error');
    echo json_encode($result);
    die;
}
list($context, $course, $cm) = get_context_info_array($contextid);
require_login($course, false, $cm);
$contextid = null;
// Now we have a context object, throw away the id from the user.
$PAGE->set_context($context);
$PAGE->set_url('/rating/rate_ajax.php', array('contextid' => $context->id));
if (!confirm_sesskey() || !has_capability('moodle/rating:rate', $context)) {
    echo $OUTPUT->header();
    echo get_string('ratepermissiondenied', 'rating');
    echo $OUTPUT->footer();
    die;
}
$rm = new rating_manager();
$result = $rm->add_rating($cm, $context, $component, $ratingarea, $itemid, $scaleid, $userrating, $rateduserid, $aggregationmethod);
// Return translated error.
if (!empty($result->error)) {
    $result->error = get_string($result->error, 'rating');
}
echo json_encode($result);
开发者ID:janeklb,项目名称:moodle,代码行数:31,代码来源:rate_ajax.php

示例2: test_course_check_module_updates_since

 public function test_course_check_module_updates_since()
 {
     global $CFG, $DB, $USER;
     require_once $CFG->dirroot . '/mod/glossary/lib.php';
     require_once $CFG->dirroot . '/rating/lib.php';
     require_once $CFG->dirroot . '/comment/lib.php';
     $this->resetAfterTest(true);
     $CFG->enablecompletion = true;
     $course = $this->getDataGenerator()->create_course(array('enablecompletion' => 1));
     $glossary = $this->getDataGenerator()->create_module('glossary', array('course' => $course->id, 'completion' => COMPLETION_TRACKING_AUTOMATIC, 'completionview' => 1, 'allowcomments' => 1, 'assessed' => RATING_AGGREGATE_AVERAGE, 'scale' => 100));
     $glossarygenerator = $this->getDataGenerator()->get_plugin_generator('mod_glossary');
     $context = context_module::instance($glossary->cmid);
     $modinfo = get_fast_modinfo($course);
     $cm = $modinfo->get_cm($glossary->cmid);
     $user = $this->getDataGenerator()->create_user();
     $studentrole = $DB->get_record('role', array('shortname' => 'student'));
     $this->getDataGenerator()->enrol_user($user->id, $course->id, $studentrole->id);
     $from = time();
     $teacher = $this->getDataGenerator()->create_user();
     $teacherrole = $DB->get_record('role', array('shortname' => 'teacher'));
     $this->getDataGenerator()->enrol_user($teacher->id, $course->id, $teacherrole->id);
     assign_capability('mod/glossary:viewanyrating', CAP_ALLOW, $studentrole->id, $context->id, true);
     // Check nothing changed right now.
     $updates = course_check_module_updates_since($cm, $from);
     $this->assertFalse($updates->configuration->updated);
     $this->assertFalse($updates->completion->updated);
     $this->assertFalse($updates->gradeitems->updated);
     $this->assertFalse($updates->comments->updated);
     $this->assertFalse($updates->ratings->updated);
     $this->assertFalse($updates->introfiles->updated);
     $this->assertFalse($updates->outcomes->updated);
     $this->waitForSecond();
     // Do some changes.
     $this->setUser($user);
     $entry = $glossarygenerator->create_content($glossary);
     $this->setUser($teacher);
     // Name.
     set_coursemodule_name($glossary->cmid, 'New name');
     // Add some ratings.
     $rm = new rating_manager();
     $result = $rm->add_rating($cm, $context, 'mod_glossary', 'entry', $entry->id, 100, 50, $user->id, RATING_AGGREGATE_AVERAGE);
     // Change grades.
     $glossary->cmidnumber = $glossary->cmid;
     glossary_update_grades($glossary, $user->id);
     $this->setUser($user);
     // Completion status.
     glossary_view($glossary, $course, $cm, $context, 'letter');
     // Add one comment.
     $args = new stdClass();
     $args->context = $context;
     $args->course = $course;
     $args->cm = $cm;
     $args->area = 'glossary_entry';
     $args->itemid = $entry->id;
     $args->client_id = 1;
     $args->component = 'mod_glossary';
     $manager = new comment($args);
     $manager->add('blah blah blah');
     // Check upgrade status.
     $updates = course_check_module_updates_since($cm, $from);
     $this->assertTrue($updates->configuration->updated);
     $this->assertTrue($updates->completion->updated);
     $this->assertTrue($updates->gradeitems->updated);
     $this->assertTrue($updates->comments->updated);
     $this->assertTrue($updates->ratings->updated);
     $this->assertFalse($updates->introfiles->updated);
     $this->assertFalse($updates->outcomes->updated);
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:68,代码来源:courselib_test.php

示例3: add_rating

 /**
  * Adds a rating to an item
  *
  * @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 int $rating the user rating
  * @param int $rateduserid the rated user id
  * @param int $aggregation the aggregation method
  * @return array result and possible warnings
  * @throws moodle_exception
  * @since Moodle 3.2
  */
 public static function add_rating($contextlevel, $instanceid, $component, $ratingarea, $itemid, $scaleid, $rating, $rateduserid, $aggregation = RATING_AGGREGATE_NONE)
 {
     $warnings = array();
     $params = array('contextlevel' => $contextlevel, 'instanceid' => $instanceid, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'rating' => $rating, 'rateduserid' => $rateduserid, 'aggregation' => $aggregation);
     // Validate and normalize parameters.
     $params = self::validate_parameters(self::add_rating_parameters(), $params);
     $context = self::get_context_from_params($params);
     self::validate_context($context);
     $cm = get_coursemodule_from_id(false, $context->instanceid, 0, false, MUST_EXIST);
     require_capability('moodle/rating:rate', $context);
     $rm = new rating_manager();
     $result = $rm->add_rating($cm, $context, $params['component'], $params['ratingarea'], $params['itemid'], $params['scaleid'], $params['rating'], $params['rateduserid'], $params['aggregation']);
     if (!empty($result->error)) {
         throw new moodle_exception($result->error, 'rating');
     }
     $returndata = array('success' => $result->success, 'warnings' => $warnings);
     if (isset($result->aggregate)) {
         $returndata['aggregate'] = $result->aggregate;
         $returndata['count'] = $result->count;
         $returndata['itemid'] = $result->itemid;
     }
     return $returndata;
 }
开发者ID:janeklb,项目名称:moodle,代码行数:39,代码来源:external.php


注:本文中的rating_manager::add_rating方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。