本文整理汇总了PHP中completion_info::delete_course_completion_data方法的典型用法代码示例。如果您正苦于以下问题:PHP completion_info::delete_course_completion_data方法的具体用法?PHP completion_info::delete_course_completion_data怎么用?PHP completion_info::delete_course_completion_data使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类completion_info
的用法示例。
在下文中一共展示了completion_info::delete_course_completion_data方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reset_course_userdata
/**
* This function will empty a course of user data.
* It will retain the activities and the structure of the course.
*
* @param object $data an object containing all the settings including courseid (without magic quotes)
* @return array status array of array component, item, error
*/
function reset_course_userdata($data)
{
global $CFG, $USER, $DB;
require_once $CFG->libdir . '/gradelib.php';
require_once $CFG->libdir . '/completionlib.php';
require_once $CFG->dirroot . '/group/lib.php';
$data->courseid = $data->id;
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
// calculate the time shift of dates
if (!empty($data->reset_start_date)) {
// time part of course startdate should be zero
$data->timeshift = $data->reset_start_date - usergetmidnight($data->reset_start_date_old);
} else {
$data->timeshift = 0;
}
// result array: component, item, error
$status = array();
// start the resetting
$componentstr = get_string('general');
// move the course start time
if (!empty($data->reset_start_date) and $data->timeshift) {
// change course start data
$DB->set_field('course', 'startdate', $data->reset_start_date, array('id' => $data->courseid));
// update all course and group events - do not move activity events
$updatesql = "UPDATE {event}\n SET timestart = timestart + ?\n WHERE courseid=? AND instance=0";
$DB->execute($updatesql, array($data->timeshift, $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
}
if (!empty($data->reset_logs)) {
$DB->delete_records('log', array('course' => $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('deletelogs'), 'error' => false);
}
if (!empty($data->reset_events)) {
$DB->delete_records('event', array('courseid' => $data->courseid));
$status[] = array('component' => $componentstr, 'item' => get_string('deleteevents', 'calendar'), 'error' => false);
}
if (!empty($data->reset_notes)) {
require_once $CFG->dirroot . '/notes/lib.php';
note_delete_all($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('deletenotes', 'notes'), 'error' => false);
}
if (!empty($data->delete_blog_associations)) {
require_once $CFG->dirroot . '/blog/lib.php';
blog_remove_associations_for_course($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteblogassociations', 'blog'), 'error' => false);
}
if (!empty($data->reset_course_completion)) {
// Delete course completion information
$course = $DB->get_record('course', array('id' => $data->courseid));
$cc = new completion_info($course);
$cc->delete_course_completion_data();
$status[] = array('component' => $componentstr, 'item' => get_string('deletecoursecompletiondata', 'completion'), 'error' => false);
}
$componentstr = get_string('roles');
if (!empty($data->reset_roles_overrides)) {
$children = get_child_contexts($context);
foreach ($children as $child) {
$DB->delete_records('role_capabilities', array('contextid' => $child->id));
}
$DB->delete_records('role_capabilities', array('contextid' => $context->id));
//force refresh for logged in users
mark_context_dirty($context->path);
$status[] = array('component' => $componentstr, 'item' => get_string('deletecourseoverrides', 'role'), 'error' => false);
}
if (!empty($data->reset_roles_local)) {
$children = get_child_contexts($context);
foreach ($children as $child) {
role_unassign_all(array('contextid' => $child->id));
}
//force refresh for logged in users
mark_context_dirty($context->path);
$status[] = array('component' => $componentstr, 'item' => get_string('deletelocalroles', 'role'), 'error' => false);
}
// First unenrol users - this cleans some of related user data too, such as forum subscriptions, tracking, etc.
$data->unenrolled = array();
if (!empty($data->unenrol_users)) {
$plugins = enrol_get_plugins(true);
$instances = enrol_get_instances($data->courseid, true);
foreach ($instances as $key => $instance) {
if (!isset($plugins[$instance->enrol])) {
unset($instances[$key]);
continue;
}
if (!$plugins[$instance->enrol]->allow_unenrol($instance)) {
unset($instances[$key]);
}
}
$sqlempty = $DB->sql_empty();
foreach ($data->unenrol_users as $withroleid) {
$sql = "SELECT DISTINCT ue.userid, ue.enrolid\n FROM {user_enrolments} ue\n JOIN {enrol} e ON (e.id = ue.enrolid AND e.courseid = :courseid)\n JOIN {context} c ON (c.contextlevel = :courselevel AND c.instanceid = e.courseid)\n JOIN {role_assignments} ra ON (ra.contextid = c.id AND ra.roleid = :roleid AND ra.userid = ue.userid)";
$params = array('courseid' => $data->courseid, 'roleid' => $withroleid, 'courselevel' => CONTEXT_COURSE);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $ue) {
//.........这里部分代码省略.........
示例2: array
// Set up the page.
$PAGE->set_course($course);
$PAGE->set_url('/course/completion.php', array('id' => $course->id));
$PAGE->set_title($course->shortname);
$PAGE->set_heading($course->fullname);
$PAGE->set_pagelayout('admin');
// Create the settings form instance.
$form = new course_completion_form('completion.php?id=' . $id, array('course' => $course));
if ($form->is_cancelled()) {
redirect($CFG->wwwroot . '/course/view.php?id=' . $course->id);
} else {
if ($data = $form->get_data()) {
$completion = new completion_info($course);
// Process criteria unlocking if requested.
if (!empty($data->settingsunlock)) {
$completion->delete_course_completion_data();
// Return to form (now unlocked).
redirect($PAGE->url);
}
// Delete old criteria.
$completion->clear_criteria();
// Loop through each criteria type and run its update_config() method.
global $COMPLETION_CRITERIA_TYPES;
foreach ($COMPLETION_CRITERIA_TYPES as $type) {
$class = 'completion_criteria_' . $type;
$criterion = new $class();
$criterion->update_config($data);
}
// Handle overall aggregation.
$aggdata = array('course' => $data->id, 'criteriatype' => null);
$aggregation = new completion_aggregation($aggdata);