本文整理汇总了PHP中rating_manager::check_rating_is_valid方法的典型用法代码示例。如果您正苦于以下问题:PHP rating_manager::check_rating_is_valid方法的具体用法?PHP rating_manager::check_rating_is_valid怎么用?PHP rating_manager::check_rating_is_valid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rating_manager
的用法示例。
在下文中一共展示了rating_manager::check_rating_is_valid方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_lib_hooks
/**
* Tests getting forum object from id and cmid, inc clones.
*/
public function test_lib_hooks()
{
global $USER, $DB;
$this->resetAfterTest();
$generator = $this->getDataGenerator()->get_plugin_generator('mod_forumng');
$course = $this->get_new_course();
$suser = $this->get_new_user('student', $course->id);
$forum = $this->get_new_forumng($course->id, array('name' => 'TEST', 'intro' => 'abc123', 'enableratings' => mod_forumng::FORUMNG_STANDARD_RATING, 'ratingscale' => 10));
$cm = get_coursemodule_from_instance('forumng', $forum->get_id());
$result = forumng_rating_permissions($forum->get_context()->id, 'mod_forumng', 'post');
$this->assertTrue(is_array($result));
foreach ($result as $cap) {
$this->assertFalse($cap);
}
$this->setAdminUser();
$result = forumng_rating_permissions($forum->get_context()->id, 'mod_forumng', 'post');
$this->assertTrue(is_array($result));
foreach ($result as $cap) {
$this->assertTrue($cap);
}
$did1 = $generator->create_discussion(array('course' => $course, 'forum' => $forum->get_id(), 'userid' => $USER->id));
$post = $generator->create_post(array('discussionid' => $did1[0], 'parentpostid' => $did1[1], 'userid' => $suser->id));
$rm = new rating_manager();
$params = array();
$params['context'] = $forum->get_context();
$params['component'] = 'mod_forumng';
$params['ratingarea'] = 'post';
$params['itemid'] = $did1[1];
$params['scaleid'] = $forum->get_rating_scale();
$params['rateduserid'] = $USER->id;
$params['rating'] = 21;
// Check rating valid, should fail with same user + rating too high.
$this->setExpectedException('rating_exception', get_string('nopermissiontorate', 'error'));
$rm->check_rating_is_valid($params);
$params['itemid'] = $post->id;
$params['rateduserid'] = $suser->id;
$this->setExpectedException('rating_exception', get_string('invalidnum', 'error'));
$rm->check_rating_is_valid($params);
$params['rating'] = 10;
$result = $rm->check_rating_is_valid($params);
$this->assertTrue($result);
// Call to update grades (should do nothing as grading not set, no assertions).
forumng_update_grades($DB->get_record('forumng', array('id' => $forum->get_id())));
// Check clones.
$forum1 = $this->get_new_forumng($course->id, array('name' => 'TEST', 'intro' => 'abc123', 'shared' => true, 'cmidnumber' => 'SF1', 'enableratings' => mod_forumng::FORUMNG_STANDARD_RATING, 'ratingscale' => 10));
$forum2 = $this->get_new_forumng($course->id, array('name' => 'TEST', 'usesharedgroup' => array('useshared' => true, 'originalcmidnumber' => 'SF1')));
$did1 = $generator->create_discussion(array('course' => $course, 'forum' => $forum1->get_id(), 'userid' => $USER->id));
$post = $generator->create_post(array('discussionid' => $did1[0], 'parentpostid' => $did1[1], 'userid' => $suser->id));
$params['itemid'] = $post->id;
$params['context'] = $forum2->get_context(true);
$result = $rm->check_rating_is_valid($params);
$this->assertTrue($result);
}
示例2: array
echo $OUTPUT->header();
echo get_string('ratepermissiondenied', 'rating');
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
$pluginpermissionsarray = $rm->get_plugin_permissions_array($context->id, $component, $ratingarea);
if (!$pluginpermissionsarray['rate']) {
$result->error = get_string('ratepermissiondenied', 'rating');
echo json_encode($result);
die;
} else {
$params = array('context' => $context, 'component' => $component, 'ratingarea' => $ratingarea, 'itemid' => $itemid, 'scaleid' => $scaleid, 'rating' => $userrating, 'rateduserid' => $rateduserid);
if (!$rm->check_rating_is_valid($params)) {
echo $OUTPUT->header();
echo get_string('ratinginvalid', 'rating');
echo $OUTPUT->footer();
die;
}
}
if ($userrating != RATING_UNSET_RATING) {
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->component = $component;
$ratingoptions->ratingarea = $ratingarea;
$ratingoptions->itemid = $itemid;
$ratingoptions->scaleid = $scaleid;
$ratingoptions->userid = $USER->id;
$rating = new rating($ratingoptions);
示例3: array
echo $OUTPUT->header();
echo get_string('ratepermissiondenied', 'rating');
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
$pluginpermissionsarray = $rm->get_plugin_permissions_array($context->id, $component);
if (!$pluginpermissionsarray['rate']) {
$result->error = get_string('ratepermissiondenied', 'rating');
echo json_encode($result);
die;
} else {
$params = array('context' => $context, 'itemid' => $itemid, 'scaleid' => $scaleid, 'rating' => $userrating, 'rateduserid' => $rateduserid);
if (!$rm->check_rating_is_valid($component, $params)) {
echo $OUTPUT->header();
echo get_string('ratinginvalid', 'rating');
echo $OUTPUT->footer();
die;
}
}
if ($userrating != RATING_UNSET_RATING) {
$ratingoptions = new stdClass();
$ratingoptions->context = $context;
$ratingoptions->component = $component;
$ratingoptions->itemid = $itemid;
$ratingoptions->scaleid = $scaleid;
$ratingoptions->userid = $USER->id;
$rating = new rating($ratingoptions);
$rating->update_rating($userrating);