本文整理汇总了PHP中rating_manager类的典型用法代码示例。如果您正苦于以下问题:PHP rating_manager类的具体用法?PHP rating_manager怎么用?PHP rating_manager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了rating_manager类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:ULCC-QMUL,项目名称:moodle-mod_forumng,代码行数:56,代码来源:rating_test.php
示例2: required_param
$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
示例3: forum_reset_userdata
/**
* This function is used by the reset_course_userdata function in moodlelib.
* This function will remove all posts from the specified forum
* and clean up any related data.
*
* @global object
* @global object
* @param $data the data submitted from the reset course.
* @return array status array
*/
function forum_reset_userdata($data) {
global $CFG, $DB;
require_once($CFG->dirroot.'/rating/lib.php');
$componentstr = get_string('modulenameplural', 'forum');
$status = array();
$params = array($data->courseid);
$removeposts = false;
$typesql = "";
if (!empty($data->reset_forum_all)) {
$removeposts = true;
$typesstr = get_string('resetforumsall', 'forum');
$types = array();
} else if (!empty($data->reset_forum_types)){
$removeposts = true;
$typesql = "";
$types = array();
$forum_types_all = forum_get_forum_types_all();
foreach ($data->reset_forum_types as $type) {
if (!array_key_exists($type, $forum_types_all)) {
continue;
}
$typesql .= " AND f.type=?";
$types[] = $forum_types_all[$type];
$params[] = $type;
}
$typesstr = get_string('resetforums', 'forum').': '.implode(', ', $types);
}
$alldiscussionssql = "SELECT fd.id
FROM {forum_discussions} fd, {forum} f
WHERE f.course=? AND f.id=fd.forum";
$allforumssql = "SELECT f.id
FROM {forum} f
WHERE f.course=?";
$allpostssql = "SELECT fp.id
FROM {forum_posts} fp, {forum_discussions} fd, {forum} f
WHERE f.course=? AND f.id=fd.forum AND fd.id=fp.discussion";
$forumssql = $forums = $rm = null;
if( $removeposts || !empty($data->reset_forum_ratings) ) {
$forumssql = "$allforumssql $typesql";
$forums = $forums = $DB->get_records_sql($forumssql, $params);
$rm = new rating_manager();
$ratingdeloptions = new stdClass;
$ratingdeloptions->component = 'mod_forum';
$ratingdeloptions->ratingarea = 'post';
}
if ($removeposts) {
$discussionssql = "$alldiscussionssql $typesql";
$postssql = "$allpostssql $typesql";
// now get rid of all attachments
$fs = get_file_storage();
if ($forums) {
foreach ($forums as $forumid=>$unused) {
if (!$cm = get_coursemodule_from_instance('forum', $forumid)) {
continue;
}
$context = context_module::instance($cm->id);
$fs->delete_area_files($context->id, 'mod_forum', 'attachment');
$fs->delete_area_files($context->id, 'mod_forum', 'post');
//remove ratings
$ratingdeloptions->contextid = $context->id;
$rm->delete_ratings($ratingdeloptions);
}
}
// first delete all read flags
$DB->delete_records_select('forum_read', "forumid IN ($forumssql)", $params);
// remove tracking prefs
$DB->delete_records_select('forum_track_prefs', "forumid IN ($forumssql)", $params);
// remove posts from queue
$DB->delete_records_select('forum_queue', "discussionid IN ($discussionssql)", $params);
// all posts - initial posts must be kept in single simple discussion forums
$DB->delete_records_select('forum_posts', "discussion IN ($discussionssql) AND parent <> 0", $params); // first all children
$DB->delete_records_select('forum_posts', "discussion IN ($discussionssql AND f.type <> 'single') AND parent = 0", $params); // now the initial posts for non single simple
// finally all discussions except single simple forums
$DB->delete_records_select('forum_discussions', "forum IN ($forumssql AND f.type <> 'single')", $params);
//.........这里部分代码省略.........
开发者ID:Jtgadbois,项目名称:Pedadida,代码行数:101,代码来源:lib.php
示例4: required_param
$returnurl = required_param('returnurl', PARAM_LOCALURL);
//required for non-ajax requests
$result = new stdClass();
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.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();
//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;
}
开发者ID:EmmanuelYupit,项目名称:educursos,代码行数:31,代码来源:rate.php
示例5: render_rating
/**
* Produces the html that represents this rating in the UI
*
* @param rating $rating the page object on which this rating will appear
* @return string
*/
function render_rating(rating $rating) {
global $CFG, $USER;
if ($rating->settings->aggregationmethod == RATING_AGGREGATE_NONE) {
return null;//ratings are turned off
}
$ratingmanager = new rating_manager();
// Initialise the JavaScript so ratings can be done by AJAX.
$ratingmanager->initialise_rating_javascript($this->page);
$strrate = get_string("rate", "rating");
$ratinghtml = ''; //the string we'll return
// permissions check - can they view the aggregate?
if ($rating->user_can_view_aggregate()) {
$aggregatelabel = $ratingmanager->get_aggregate_label($rating->settings->aggregationmethod);
$aggregatestr = $rating->get_aggregate_string();
$aggregatehtml = html_writer::tag('span', $aggregatestr, array('id' => 'ratingaggregate'.$rating->itemid, 'class' => 'ratingaggregate')).' ';
if ($rating->count > 0) {
$countstr = "({$rating->count})";
} else {
$countstr = '-';
}
$aggregatehtml .= html_writer::tag('span', $countstr, array('id'=>"ratingcount{$rating->itemid}", 'class' => 'ratingcount')).' ';
$ratinghtml .= html_writer::tag('span', $aggregatelabel, array('class'=>'rating-aggregate-label'));
if ($rating->settings->permissions->viewall && $rating->settings->pluginpermissions->viewall) {
$nonpopuplink = $rating->get_view_ratings_url();
$popuplink = $rating->get_view_ratings_url(true);
$action = new popup_action('click', $popuplink, 'ratings', array('height' => 400, 'width' => 600));
$ratinghtml .= $this->action_link($nonpopuplink, $aggregatehtml, $action);
} else {
$ratinghtml .= $aggregatehtml;
}
}
$formstart = null;
// if the item doesn't belong to the current user, the user has permission to rate
// and we're within the assessable period
if ($rating->user_can_rate()) {
$rateurl = $rating->get_rate_url();
$inputs = $rateurl->params();
//start the rating form
$formattrs = array(
'id' => "postrating{$rating->itemid}",
'class' => 'postratingform',
'method' => 'post',
'action' => $rateurl->out_omit_querystring()
);
$formstart = html_writer::start_tag('form', $formattrs);
$formstart .= html_writer::start_tag('div', array('class' => 'ratingform'));
// add the hidden inputs
foreach ($inputs as $name => $value) {
$attributes = array('type' => 'hidden', 'class' => 'ratinginput', 'name' => $name, 'value' => $value);
$formstart .= html_writer::empty_tag('input', $attributes);
}
if (empty($ratinghtml)) {
$ratinghtml .= $strrate.': ';
}
$ratinghtml = $formstart.$ratinghtml;
$scalearray = array(RATING_UNSET_RATING => $strrate.'...') + $rating->settings->scale->scaleitems;
$scaleattrs = array('class'=>'postratingmenu ratinginput','id'=>'menurating'.$rating->itemid);
$ratinghtml .= html_writer::label($rating->rating, 'menurating'.$rating->itemid, false, array('class' => 'accesshide'));
$ratinghtml .= html_writer::select($scalearray, 'rating', $rating->rating, false, $scaleattrs);
//output submit button
$ratinghtml .= html_writer::start_tag('span', array('class'=>"ratingsubmit"));
$attributes = array('type' => 'submit', 'class' => 'postratingmenusubmit', 'id' => 'postratingsubmit'.$rating->itemid, 'value' => s(get_string('rate', 'rating')));
$ratinghtml .= html_writer::empty_tag('input', $attributes);
if (!$rating->settings->scale->isnumeric) {
// If a global scale, try to find current course ID from the context
if (empty($rating->settings->scale->courseid) and $coursecontext = $rating->context->get_course_context(false)) {
$courseid = $coursecontext->instanceid;
} else {
$courseid = $rating->settings->scale->courseid;
}
$ratinghtml .= $this->help_icon_scale($courseid, $rating->settings->scale);
}
$ratinghtml .= html_writer::end_tag('span');
$ratinghtml .= html_writer::end_tag('div');
$ratinghtml .= html_writer::end_tag('form');
}
//.........这里部分代码省略.........
开发者ID:afgal,项目名称:moodle-1,代码行数:101,代码来源:outputrenderers.php
示例6: remove_course_contents
//.........这里部分代码省略.........
foreach ($cleanuplugintypes as $type) {
if (!empty($callbacks[$type])) {
foreach ($callbacks[$type] as $pluginfunction) {
debugging("Callback delete_course is deprecated. Function {$pluginfunction} should be converted " . 'to observer of event \\core\\event\\course_content_deleted', DEBUG_DEVELOPER);
$pluginfunction($course->id, $showfeedback);
}
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_' . $type . '_plural', 'plugin'), 'notifysuccess');
}
}
}
// Delete questions and question categories.
question_delete_course($course, $showfeedback);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('questions', 'question'), 'notifysuccess');
}
// Make sure there are no subcontexts left - all valid blocks and modules should be already gone.
$childcontexts = $coursecontext->get_child_contexts();
// Returns all subcontexts since 2.2.
foreach ($childcontexts as $childcontext) {
$childcontext->delete();
}
unset($childcontexts);
// Remove all roles and enrolments by default.
if (empty($options['keep_roles_and_enrolments'])) {
// This hack is used in restore when deleting contents of existing course.
role_unassign_all(array('contextid' => $coursecontext->id, 'component' => ''), true);
enrol_course_delete($course);
if ($showfeedback) {
echo $OUTPUT->notification($strdeleted . get_string('type_enrol_plural', 'plugin'), 'notifysuccess');
}
}
// Delete any groups, removing members and grouping/course links first.
if (empty($options['keep_groups_and_groupings'])) {
groups_delete_groupings($course->id, $showfeedback);
groups_delete_groups($course->id, $showfeedback);
}
// Filters be gone!
filter_delete_all_for_context($coursecontext->id);
// Notes, you shall not pass!
note_delete_all($course->id);
// Die comments!
comment::delete_comments($coursecontext->id);
// Ratings are history too.
$delopt = new stdclass();
$delopt->contextid = $coursecontext->id;
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// Delete course tags.
core_tag_tag::remove_all_item_tags('core', 'course', $course->id);
// Notify the competency subsystem.
\core_competency\api::hook_course_deleted($course);
// Delete calendar events.
$DB->delete_records('event', array('courseid' => $course->id));
$fs->delete_area_files($coursecontext->id, 'calendar');
// Delete all related records in other core tables that may have a courseid
// This array stores the tables that need to be cleared, as
// table_name => column_name that contains the course id.
$tablestoclear = array('backup_courses' => 'courseid', 'user_lastaccess' => 'courseid');
foreach ($tablestoclear as $table => $col) {
$DB->delete_records($table, array($col => $course->id));
}
// Delete all course backup files.
$fs->delete_area_files($coursecontext->id, 'backup');
// Cleanup course record - remove links to deleted stuff.
$oldcourse = new stdClass();
$oldcourse->id = $course->id;
$oldcourse->summary = '';
$oldcourse->cacherev = 0;
$oldcourse->legacyfiles = 0;
if (!empty($options['keep_groups_and_groupings'])) {
$oldcourse->defaultgroupingid = 0;
}
$DB->update_record('course', $oldcourse);
// Delete course sections.
$DB->delete_records('course_sections', array('course' => $course->id));
// Delete legacy, section and any other course files.
$fs->delete_area_files($coursecontext->id, 'course');
// Files from summary and section.
// Delete all remaining stuff linked to context such as files, comments, ratings, etc.
if (empty($options['keep_roles_and_enrolments']) and empty($options['keep_groups_and_groupings'])) {
// Easy, do not delete the context itself...
$coursecontext->delete_content();
} else {
// Hack alert!!!!
// We can not drop all context stuff because it would bork enrolments and roles,
// there might be also files used by enrol plugins...
}
// Delete legacy files - just in case some files are still left there after conversion to new file api,
// also some non-standard unsupported plugins may try to store something there.
fulldelete($CFG->dataroot . '/' . $course->id);
// Delete from cache to reduce the cache size especially makes sense in case of bulk course deletion.
$cachemodinfo = cache::make('core', 'coursemodinfo');
$cachemodinfo->delete($courseid);
// Trigger a course content deleted event.
$event = \core\event\course_content_deleted::create(array('objectid' => $course->id, 'context' => $coursecontext, 'other' => array('shortname' => $course->shortname, 'fullname' => $course->fullname, 'options' => $options)));
$event->add_record_snapshot('course', $course);
$event->trigger();
return true;
}
开发者ID:lucaboesch,项目名称:moodle,代码行数:101,代码来源:moodlelib.php
示例7: data_reset_userdata
/**
* Actual implementation of the reset course functionality, delete all the
* data responses for course $data->courseid.
*
* @global object
* @global object
* @param object $data the data submitted from the reset course.
* @return array status array
*/
function data_reset_userdata($data)
{
global $CFG, $DB;
require_once $CFG->libdir . '/filelib.php';
require_once $CFG->dirroot . '/rating/lib.php';
$componentstr = get_string('modulenameplural', 'data');
$status = array();
$allrecordssql = "SELECT r.id\n FROM {data_records} r\n INNER JOIN {data} d ON r.dataid = d.id\n WHERE d.course = ?";
$alldatassql = "SELECT d.id\n FROM {data} d\n WHERE d.course=?";
$rm = new rating_manager();
$ratingdeloptions = new stdClass();
$ratingdeloptions->component = 'mod_data';
$ratingdeloptions->ratingarea = 'entry';
// Set the file storage - may need it to remove files later.
$fs = get_file_storage();
// delete entries if requested
if (!empty($data->reset_data)) {
$DB->delete_records_select('comments', "itemid IN ({$allrecordssql}) AND commentarea='database_entry'", array($data->courseid));
$DB->delete_records_select('data_content', "recordid IN ({$allrecordssql})", array($data->courseid));
$DB->delete_records_select('data_records', "dataid IN ({$alldatassql})", array($data->courseid));
if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
foreach ($datas as $dataid => $unused) {
if (!($cm = get_coursemodule_from_instance('data', $dataid))) {
continue;
}
$datacontext = context_module::instance($cm->id);
// Delete any files that may exist.
$fs->delete_area_files($datacontext->id, 'mod_data', 'content');
$ratingdeloptions->contextid = $datacontext->id;
$rm->delete_ratings($ratingdeloptions);
}
}
if (empty($data->reset_gradebook_grades)) {
// remove all grades from gradebook
data_reset_gradebook($data->courseid);
}
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallentries', 'data'), 'error' => false);
}
// remove entries by users not enrolled into course
if (!empty($data->reset_data_notenrolled)) {
$recordssql = "SELECT r.id, r.userid, r.dataid, u.id AS userexists, u.deleted AS userdeleted\n FROM {data_records} r\n JOIN {data} d ON r.dataid = d.id\n LEFT JOIN {user} u ON r.userid = u.id\n WHERE d.course = ? AND r.userid > 0";
$course_context = context_course::instance($data->courseid);
$notenrolled = array();
$fields = array();
$rs = $DB->get_recordset_sql($recordssql, array($data->courseid));
foreach ($rs as $record) {
if (array_key_exists($record->userid, $notenrolled) or !$record->userexists or $record->userdeleted or !is_enrolled($course_context, $record->userid)) {
//delete ratings
if (!($cm = get_coursemodule_from_instance('data', $record->dataid))) {
continue;
}
$datacontext = context_module::instance($cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$ratingdeloptions->itemid = $record->id;
$rm->delete_ratings($ratingdeloptions);
// Delete any files that may exist.
if ($contents = $DB->get_records('data_content', array('recordid' => $record->id), '', 'id')) {
foreach ($contents as $content) {
$fs->delete_area_files($datacontext->id, 'mod_data', 'content', $content->id);
}
}
$notenrolled[$record->userid] = true;
$DB->delete_records('comments', array('itemid' => $record->id, 'commentarea' => 'database_entry'));
$DB->delete_records('data_content', array('recordid' => $record->id));
$DB->delete_records('data_records', array('id' => $record->id));
}
}
$rs->close();
$status[] = array('component' => $componentstr, 'item' => get_string('deletenotenrolled', 'data'), 'error' => false);
}
// remove all ratings
if (!empty($data->reset_data_ratings)) {
if ($datas = $DB->get_records_sql($alldatassql, array($data->courseid))) {
foreach ($datas as $dataid => $unused) {
if (!($cm = get_coursemodule_from_instance('data', $dataid))) {
continue;
}
$datacontext = context_module::instance($cm->id);
$ratingdeloptions->contextid = $datacontext->id;
$rm->delete_ratings($ratingdeloptions);
}
}
if (empty($data->reset_gradebook_grades)) {
// remove all grades from gradebook
data_reset_gradebook($data->courseid);
}
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallratings'), 'error' => false);
}
// remove all comments
if (!empty($data->reset_data_comments)) {
$DB->delete_records_select('comments', "itemid IN ({$allrecordssql}) AND commentarea='database_entry'", array($data->courseid));
//.........这里部分代码省略.........
开发者ID:gabrielrosset,项目名称:moodle,代码行数:101,代码来源:lib.php
示例8: standard_coursemodule_elements
/**
* Adds all the standard elements to a form to edit the settings for an activity module.
*/
function standard_coursemodule_elements()
{
global $COURSE, $CFG, $DB;
$mform =& $this->_form;
$this->_outcomesused = false;
if ($this->_features->outcomes) {
if ($outcomes = grade_outcome::fetch_all_available($COURSE->id)) {
$this->_outcomesused = true;
$mform->addElement('header', 'modoutcomes', get_string('outcomes', 'grades'));
foreach ($outcomes as $outcome) {
$mform->addElement('advcheckbox', 'outcome_' . $outcome->id, $outcome->get_name());
}
}
}
if ($this->_features->rating) {
require_once $CFG->dirroot . '/rating/lib.php';
$rm = new rating_manager();
$mform->addElement('header', 'modstandardratings', get_string('ratings', 'rating'));
$permission = CAP_ALLOW;
$rolenamestring = null;
if (!empty($this->_cm)) {
$context = context_module::instance($this->_cm->id);
$rolenames = get_role_names_with_caps_in_context($context, array('moodle/rating:rate', 'mod/' . $this->_cm->modname . ':rate'));
$rolenamestring = implode(', ', $rolenames);
} else {
$rolenamestring = get_string('capabilitychecknotavailable', 'rating');
}
$mform->addElement('static', 'rolewarning', get_string('rolewarning', 'rating'), $rolenamestring);
$mform->addHelpButton('rolewarning', 'rolewarning', 'rating');
$mform->addElement('select', 'assessed', get_string('aggregatetype', 'rating'), $rm->get_aggregate_types());
$mform->setDefault('assessed', 0);
$mform->addHelpButton('assessed', 'aggregatetype', 'rating');
$mform->addElement('modgrade', 'scale', get_string('scale'), false);
$mform->disabledIf('scale', 'assessed', 'eq', 0);
$mform->addElement('checkbox', 'ratingtime', get_string('ratingtime', 'rating'));
$mform->disabledIf('ratingtime', 'assessed', 'eq', 0);
$mform->addElement('date_time_selector', 'assesstimestart', get_string('from'));
$mform->disabledIf('assesstimestart', 'assessed', 'eq', 0);
$mform->disabledIf('assesstimestart', 'ratingtime');
$mform->addElement('date_time_selector', 'assesstimefinish', get_string('to'));
$mform->disabledIf('assesstimefinish', 'assessed', 'eq', 0);
$mform->disabledIf('assesstimefinish', 'ratingtime');
}
//doing this here means splitting up the grade related settings on the lesson settings page
//$this->standard_grading_coursemodule_elements();
$mform->addElement('header', 'modstandardelshdr', get_string('modstandardels', 'form'));
if ($this->_features->groups) {
$options = array(NOGROUPS => get_string('groupsnone'), SEPARATEGROUPS => get_string('groupsseparate'), VISIBLEGROUPS => get_string('groupsvisible'));
$mform->addElement('select', 'groupmode', get_string('groupmode', 'group'), $options, NOGROUPS);
$mform->addHelpButton('groupmode', 'groupmode', 'group');
}
if ($this->_features->groupings or $this->_features->groupmembersonly) {
//groupings selector - used for normal grouping mode or also when restricting access with groupmembersonly
$options = array();
$options[0] = get_string('none');
if ($groupings = $DB->get_records('groupings', array('courseid' => $COURSE->id))) {
foreach ($groupings as $grouping) {
$options[$grouping->id] = format_string($grouping->name);
}
}
$mform->addElement('select', 'groupingid', get_string('grouping', 'group'), $options);
$mform->addHelpButton('groupingid', 'grouping', 'group');
$mform->setAdvanced('groupingid');
}
if ($this->_features->groupmembersonly) {
$mform->addElement('checkbox', 'groupmembersonly', get_string('groupmembersonly', 'group'));
$mform->addHelpButton('groupmembersonly', 'groupmembersonly', 'group');
$mform->setAdvanced('groupmembersonly');
}
$mform->addElement('modvisible', 'visible', get_string('visible'));
if (!empty($this->_cm)) {
$context = context_module::instance($this->_cm->id);
if (!has_capability('moodle/course:activityvisibility', $context)) {
$mform->hardFreeze('visible');
}
}
if ($this->_features->idnumber) {
$mform->addElement('text', 'cmidnumber', get_string('idnumbermod'));
$mform->addHelpButton('cmidnumber', 'idnumbermod');
}
if (!empty($CFG->enableavailability)) {
// String used by conditions
$strnone = get_string('none', 'condition');
// Conditional availability
// Available from/to defaults to midnight because then the display
// will be nicer where it tells users when they can access it (it
// shows only the date and not time).
$date = usergetdate(time());
$midnight = make_timestamp($date['year'], $date['mon'], $date['mday']);
// From/until controls
$mform->addElement('header', 'availabilityconditionsheader', get_string('availabilityconditions', 'condition'));
$mform->addElement('date_time_selector', 'availablefrom', get_string('availablefrom', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
$mform->addHelpButton('availablefrom', 'availablefrom', 'condition');
$mform->addElement('date_time_selector', 'availableuntil', get_string('availableuntil', 'condition'), array('optional' => true, 'defaulttime' => $midnight));
// Conditions based on grades
$gradeoptions = array();
$items = grade_item::fetch_all(array('courseid' => $COURSE->id));
//.........这里部分代码省略.........
开发者ID:Burick,项目名称:moodle,代码行数:101,代码来源:moodleform_mod.php
示例9: delete_context
/**
* Remove a context record and any dependent entries,
* removes context from static context cache too
*
* @param int $level
* @param int $instanceid
* @param bool $deleterecord false means keep record for now
* @return bool returns true or throws an exception
*/
function delete_context($contextlevel, $instanceid, $deleterecord = true)
{
global $DB, $ACCESSLIB_PRIVATE, $CFG;
// do not use get_context_instance(), because the related object might not exist,
// or the context does not exist yet and it would be created now
if ($context = $DB->get_record('context', array('contextlevel' => $contextlevel, 'instanceid' => $instanceid))) {
// delete these first because they might fetch the context and try to recreate it!
blocks_delete_all_for_context($context->id);
filter_delete_all_for_context($context->id);
require_once $CFG->dirroot . '/comment/lib.php';
comment::delete_comments(array('contextid' => $context->id));
require_once $CFG->dirroot . '/rating/lib.php';
$delopt = new stdclass();
$delopt->contextid = $context->id;
$rm = new rating_manager();
$rm->delete_ratings($delopt);
// delete all files attached to this context
$fs = get_file_storage();
$fs->delete_area_files($context->id);
// now delete stuff from role related tables, role_unassign_all
// and unenrol should be called earlier to do proper cleanup
$DB->delete_records('role_assignments', array('contextid' => $context->id));
$DB->delete_records('role_capabilities', array('contextid' => $context->id));
$DB->delete_records('role_names', array('contextid' => $context->id));
// and finally it is time to delete the context record if requested
if ($deleterecord) {
$DB->delete_records('context', array('id' => $context->id));
// purge static context cache if entry present
$ACCESSLIB_PRIVATE->contexcache->remove($context);
}
// do not mark dirty contexts if parents unknown
if (!is_null($context->path) and $context->depth > 0) {
mark_context_dirty($context->path);
}
}
return true;
}
开发者ID:LMSeXT,项目名称:SAWEE-WS_server-lib,代码行数:46,代码来源:accesslib.php
示例10: 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
示例11: display_homepage
//.........这里部分代码省略.........
//load javascript
$courseids = array();
//all result courses
$courseimagenumbers = array();
//number of screenshots of all courses (must be exact same order than $courseids)
foreach ($courses as $course) {
$courseids[] = $course->id;
$courseimagenumbers[] = $course->screenshots;
}
$PAGE->requires->yui_module('moodle-block_community-imagegallery', 'M.blocks_community.init_imagegallery', array(array('imageids' => $courseids, 'imagenumbers' => $courseimagenumbers, 'huburl' => $CFG->wwwroot)));
//get courses content
foreach ($courses as $course) {
$contents = $this->get_course_contents($course->id);
if (!empty($contents)) {
foreach ($contents as $content) {
$course->contents[] = $content;
}
}
}
//load ratings and comments
require_once $CFG->dirroot . '/rating/lib.php';
$ratingoptions = new stdclass();
$ratingoptions->context = context_course::instance(SITEID);
//front page course
$ratingoptions->items = $courses;
$ratingoptions->aggregate = RATING_AGGREGATE_COUNT;
//the aggregation method
$ratingoptions->scaleid = 0 - get_config('local_hub', 'courseratingscaleid');
//rating API is expecting "minus scaleid"
$ratingoptions->userid = $USER->id;
$ratingoptions->returnurl = $CFG->wwwroot . "/local/hub/index.php";
$ratingoptions->component = 'local_hub';
$ratingoptions->ratingarea = 'featured';
$rm = new rating_manager();
$courses = $rm->get_ratings($ratingoptions);
//this function return $ratingoptions->items with information about the ratings
foreach ($courses as $course) {
$course->rating->settings->permissions->viewany = 1;
}
require_once $CFG->dirroot . '/comment/lib.php';
foreach ($courses as $course) {
$commentoptions = new stdClass();
$commentoptions->context = context_course::instance(SITEID);
$commentoptions->area = 'local_hub';
$commentoptions->itemid = $course->id;
$commentoptions->showcount = true;
$commentoptions->component = 'local_hub';
$course->comment = new comment($commentoptions);
$course->comment->set_view_permission(true);
}
}
//create rss feed link
$enablerssfeeds = get_config('local_hub', 'enablerssfeeds');
if (!empty($enablerssfeeds)) {
require $CFG->libdir . '/rsslib.php';
$audience = key_exists('audience', $options) ? $options['audience'] : 'all';
$educationallevel = key_exists('educationallevel', $options) ? $options['educationallevel'] : 'all';
if (key_exists('downloadable', $options)) {
$downloadable = empty($options['downloadable']) ? 0 : 1;
} else {
$downloadable = 'all';
}
$subject = key_exists('subject', $options) ? $options['subject'] : 'all';
$licence = key_exists('licence', $options) ? $options['licence'] : 'all';
$language = key_exists('language', $options) ? $options['language'] : 'all';
$audience = key_exists('audience', $options) ? $options['audience'] : 'all';
开发者ID:k-holland,项目名称:moodle-local_hub,代码行数:67,代码来源:lib.php
示例12: pcast_display_episode_ratings
/**
* Displays the ratingsfor a specific episode
* @global stdClass $CFG
* @global stdClass $USER
* @global stdClass $DB
* @global stdClass $OUTPUT
* @param object $episode
* @param object $cm
* @param object $course
*/
function pcast_display_episode_ratings($episode, $cm, $course)
{
global $CFG, $USER, $DB, $OUTPUT;
$sql = pcast_get_episode_sql();
$sql .= " WHERE p.id = ?";
$episodes = $DB->get_records_sql($sql, array('id' => $episode->id));
$context = get_context_instance(CONTEXT_MODULE, $cm->id);
// load ratings
require_once $CFG->dirroot . '/rating/lib.php';
if ($episode->assessed != RATING_AGGREGATE_NONE) {
$ratingoptions = new stdClass();
// $ratingoptions->plugintype = 'mod';
// $ratingoptions->pluginname = 'pcast';
$ratingoptions->component = 'mod_pcast';
$ratingoptions->context = $context;
$ratingoptions->items = $episodes;
$ratingoptions->aggregate = $episode->assessed;
//the aggregation method
$ratingoptions->scaleid = $episode->scale;
$ratingoptions->userid = $USER->id;
$ratingoptions->returnurl = new moodle_url('/mod/pcast/showepisode.php', array('eid' => $episode->id, 'mode' => PCAST_EPISODE_COMMENT_AND_RATE));
$ratingoptions->assesstimestart = $episode->assesstimestart;
$ratingoptions->assesstimefinish = $episode->assesstimefinish;
$ratingoptions->ratingarea = 'episode';
$rm = new rating_manager();
$allepisodes = $rm->get_ratings($ratingoptions);
}
foreach ($allepisodes as $thisepisode) {
if (!empty($thisepisode->rating)) {
echo html_writer::tag('div', $OUTPUT->render($thisepisode->rating), array('class' => 'pcast-episode-rating'));
}
}
}
开发者ID:rtsfc,项目名称:moodle-mod_pcast,代码行数:43,代码来源:locallib.php
示例13: test_get_ratings_sql
/**
* Test the current get_ratings method main sql
*/
function test_get_ratings_sql() {
// We load 3 items. Each is rated twice. For simplicity itemid == user id of the item owner
$ctxid = SYSCONTEXTID;
$this->load_test_data('rating',
array('contextid', 'component', 'ratingarea', 'itemid', 'scaleid', 'rating', 'userid', 'timecreated', 'timemodified'), array(
//user 1's items. Average == 2
array( $ctxid , 'mod_forum', 'post', 1 , 10 , 1 , 2 , 1 , 1),
array( $ctxid , 'mod_forum', 'post', 1 , 10 , 3 , 3 , 1 , 1),
//user 2's items. Average == 3
array( $ctxid , 'mod_forum', 'post', 2 , 10 , 1 , 1 , 1 , 1),
array( $ctxid , 'mod_forum', 'post', 2 , 10 , 5 , 3 , 1 , 1),
//user 3's items. Average == 4
array( $ctxid , 'mod_forum', 'post', 3 , 10 , 3 , 1 , 1 , 1),
array( $ctxid , 'mod_forum', 'post', 3 ,
|
请发表评论