本文整理汇总了PHP中groups_delete_groups函数的典型用法代码示例。如果您正苦于以下问题:PHP groups_delete_groups函数的具体用法?PHP groups_delete_groups怎么用?PHP groups_delete_groups使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了groups_delete_groups函数的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_groups_delete_groups
public function test_groups_delete_groups()
{
global $DB;
$this->resetAfterTest();
$course = $this->getDataGenerator()->create_course();
$course2 = $this->getDataGenerator()->create_course();
$group1 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group2 = $this->getDataGenerator()->create_group(array('courseid' => $course->id));
$group1c2 = $this->getDataGenerator()->create_group(array('courseid' => $course2->id));
$grouping1 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$grouping2 = $this->getDataGenerator()->create_grouping(array('courseid' => $course->id));
$user1 = $this->getDataGenerator()->create_user();
$this->getDataGenerator()->enrol_user($user1->id, $course->id);
$this->getDataGenerator()->create_group_member(array('groupid' => $group1->id, 'userid' => $user1->id));
$this->getDataGenerator()->create_grouping_group(array('groupid' => $group1->id, 'groupingid' => $grouping1->id));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groups', array('id' => $group2->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1c2->id, 'courseid' => $course2->id)));
$this->assertTrue($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
groups_delete_groups($course->id);
$this->assertFalse($DB->record_exists('groups', array('id' => $group1->id, 'courseid' => $course->id)));
$this->assertFalse($DB->record_exists('groups', array('id' => $group2->id, 'courseid' => $course->id)));
$this->assertTrue($DB->record_exists('groups', array('id' => $group1c2->id, 'courseid' => $course2->id)));
$this->assertFalse($DB->record_exists('groups_members', array('groupid' => $group1->id, 'userid' => $user1->id)));
$this->assertTrue($DB->record_exists('groupings', array('id' => $grouping1->id, 'courseid' => $course->id)));
$this->assertFalse($DB->record_exists('groupings_groups', array('groupid' => $group1->id, 'groupingid' => $grouping1->id)));
}
示例2: reset_course_userdata
//.........这里部分代码省略.........
$params = array('courseid' => $data->courseid, 'roleid' => $withroleid, 'courselevel' => CONTEXT_COURSE);
} else {
// Without any role assigned at course context.
$sql = "SELECT ue.*\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 LEFT JOIN {role_assignments} ra ON (ra.contextid = c.id AND ra.userid = ue.userid)\n WHERE ra.id IS null";
$params = array('courseid' => $data->courseid, 'courselevel' => CONTEXT_COURSE);
}
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $ue) {
if (!isset($instances[$ue->enrolid])) {
continue;
}
$instance = $instances[$ue->enrolid];
$plugin = $plugins[$instance->enrol];
if (!$plugin->allow_unenrol($instance) and !$plugin->allow_unenrol_user($instance, $ue)) {
continue;
}
$plugin->unenrol_user($instance, $ue->userid);
$data->unenrolled[$ue->userid] = $ue->userid;
}
$rs->close();
}
}
if (!empty($data->unenrolled)) {
$status[] = array('component' => $componentstr, 'item' => get_string('unenrol', 'enrol') . ' (' . count($data->unenrolled) . ')', 'error' => false);
}
$componentstr = get_string('groups');
// Remove all group members.
if (!empty($data->reset_groups_members)) {
groups_delete_group_members($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('removegroupsmembers', 'group'), 'error' => false);
}
// Remove all groups.
if (!empty($data->reset_groups_remove)) {
groups_delete_groups($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallgroups', 'group'), 'error' => false);
}
// Remove all grouping members.
if (!empty($data->reset_groupings_members)) {
groups_delete_groupings_groups($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('removegroupingsmembers', 'group'), 'error' => false);
}
// Remove all groupings.
if (!empty($data->reset_groupings_remove)) {
groups_delete_groupings($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallgroupings', 'group'), 'error' => false);
}
// Look in every instance of every module for data to delete.
$unsupportedmods = array();
if ($allmods = $DB->get_records('modules')) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot . '/mod/' . $modname . '/lib.php';
$moddeleteuserdata = $modname . '_reset_userdata';
// Function to delete user data.
if (file_exists($modfile)) {
if (!$DB->count_records($modname, array('course' => $data->courseid))) {
continue;
// Skip mods with no instances.
}
include_once $modfile;
if (function_exists($moddeleteuserdata)) {
$modstatus = $moddeleteuserdata($data);
if (is_array($modstatus)) {
$status = array_merge($status, $modstatus);
} else {
debugging('Module ' . $modname . ' returned incorrect staus - must be an array!');
示例3: 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;
require_once $CFG->libdir . '/gradelib.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
set_field('course', 'startdate', $data->reset_start_date, 'id', $data->courseid);
// update all course and group events - do not move activity events
$updatesql = "UPDATE {$CFG->prefix}event\n SET timestart = timestart + ({$data->timeshift})\n WHERE courseid={$data->courseid} AND instance=0";
execute_sql($updatesql, false);
$status[] = array('component' => $componentstr, 'item' => get_string('datechanged'), 'error' => false);
}
if (!empty($data->reset_logs)) {
delete_records('log', 'course', $data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('deletelogs'), 'error' => false);
}
if (!empty($data->reset_events)) {
delete_records('event', '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);
}
$componentstr = get_string('roles');
if (!empty($data->reset_roles_overrides)) {
$children = get_child_contexts($context);
foreach ($children as $child) {
delete_records('role_capabilities', 'contextid', $child->id);
}
delete_records('role_capabilities', '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(0, 0, 0, $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->reset_roles)) {
foreach ($data->reset_roles as $roleid) {
if ($users = get_role_users($roleid, $context, false, 'u.id', 'u.id ASC')) {
foreach ($users as $user) {
role_unassign($roleid, $user->id, 0, $context->id);
if (!has_capability('moodle/course:view', $context, $user->id)) {
$data->unenrolled[$user->id] = $user->id;
}
}
}
}
}
if (!empty($data->unenrolled)) {
$status[] = array('component' => $componentstr, 'item' => get_string('unenrol') . ' (' . count($data->unenrolled) . ')', 'error' => false);
}
$componentstr = get_string('groups');
// remove all group members
if (!empty($data->reset_groups_members)) {
groups_delete_group_members($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('removegroupsmembers', 'group'), 'error' => false);
}
// remove all groups
if (!empty($data->reset_groups_remove)) {
groups_delete_groups($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallgroups', 'group'), 'error' => false);
}
// remove all grouping members
if (!empty($data->reset_groupings_members)) {
groups_delete_groupings_groups($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('removegroupingsmembers', 'group'), 'error' => false);
}
// remove all groupings
//.........这里部分代码省略.........
示例4: reset_course_userdata
//.........这里部分代码省略.........
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) {
if (!isset($instances[$ue->enrolid])) {
continue;
}
$plugins[$instances[$ue->enrolid]->enrol]->unenrol_user($instances[$ue->enrolid], $ue->userid);
$data->unenrolled[$ue->userid] = $ue->userid;
}
}
}
if (!empty($data->unenrolled)) {
$status[] = array('component' => $componentstr, 'item' => get_string('unenrol', 'enrol') . ' (' . count($data->unenrolled) . ')', 'error' => false);
}
$componentstr = get_string('groups');
// remove all group members
if (!empty($data->reset_groups_members)) {
groups_delete_group_members($data->courseid);
$status[] = array('component' => $componentstr, 'item' => get_string('removegroupsmembers', 'group'), 'error' => false);
}
// remove all groups
if (!empty($data->reset_groups_remove)) {
groups_delete_groups($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallgroups', 'group'), 'error' => false);
}
// remove all grouping members
if (!empty($data->reset_groupings_members)) {
groups_delete_groupings_groups($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('removegroupingsmembers', 'group'), 'error' => false);
}
// remove all groupings
if (!empty($data->reset_groupings_remove)) {
groups_delete_groupings($data->courseid, false);
$status[] = array('component' => $componentstr, 'item' => get_string('deleteallgroupings', 'group'), 'error' => false);
}
// Look in every instance of every module for data to delete
$unsupported_mods = array();
if ($allmods = $DB->get_records('modules')) {
foreach ($allmods as $mod) {
$modname = $mod->name;
if (!$DB->count_records($modname, array('course' => $data->courseid))) {
continue;
// skip mods with no instances
}
$modfile = $CFG->dirroot . '/mod/' . $modname . '/lib.php';
$moddeleteuserdata = $modname . '_reset_userdata';
// Function to delete user data
if (file_exists($modfile)) {
include_once $modfile;
if (function_exists($moddeleteuserdata)) {
$modstatus = $moddeleteuserdata($data);
if (is_array($modstatus)) {
$status = array_merge($status, $modstatus);
} else {
debugging('Module ' . $modname . ' returned incorrect staus - must be an array!');
示例5: local_ltiprovider_duplicate_course
//.........这里部分代码省略.........
foreach ($backupsettings as $name => $value) {
$setting = $rc->get_plan()->get_setting($name);
if ($setting->get_status() == backup_setting::NOT_LOCKED) {
$setting->set_value($value);
}
}
if (!$rc->execute_precheck()) {
$precheckresults = $rc->get_precheck_results();
if (is_array($precheckresults) && !empty($precheckresults['errors'])) {
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($backupbasepath);
}
$errorinfo = '';
foreach ($precheckresults['errors'] as $error) {
$errorinfo .= $error;
}
if (array_key_exists('warnings', $precheckresults)) {
foreach ($precheckresults['warnings'] as $warning) {
$errorinfo .= $warning;
}
}
throw new moodle_exception('backupprecheckerrors', 'webservice', '', $errorinfo);
}
}
$rc->execute_plan();
$rc->destroy();
$course = $DB->get_record('course', array('id' => $newcourse->id), '*', MUST_EXIST);
$course->visible = $visible;
$course->fullname = $newcourse->fullname;
$course->shortname = $newcourse->shortname;
$course->idnumber = $newcourse->idnumber;
// Set shortname and fullname back.
$DB->update_record('course', $course);
if (empty($CFG->keeptempdirectoriesonbackup)) {
fulldelete($backupbasepath);
}
// Delete the course backup file created by this WebService. Originally located in the course backups area.
$file->delete();
// We have to unenroll all the user except the one that create the course.
if (get_config('local_ltiprovider', 'duplicatecourseswithoutusers') and $useridcreating) {
require_once $CFG->dirroot . '/group/lib.php';
// Previous to unenrol users, we assign some type of activities to the user that created the course.
if ($user = $DB->get_record('user', array('id' => $useridcreating))) {
if ($databases = $DB->get_records('data', array('course' => $course->id))) {
foreach ($databases as $data) {
$DB->execute("UPDATE {data_records} SET userid = ? WHERE dataid = ?", array($user->id, $data->id));
}
}
if ($glossaries = $DB->get_records('glossary', array('course' => $course->id))) {
foreach ($glossaries as $glossary) {
$DB->execute("UPDATE {glossary_entries} SET userid = ? WHERE glossaryid = ?", array($user->id, $glossary->id));
}
}
// Same for questions.
$newcoursecontextid = context_course::instance($course->id);
if ($qcategories = $DB->get_records('question_categories', array('contextid' => $newcoursecontextid->id))) {
foreach ($qcategories as $qcategory) {
$DB->execute("UPDATE {question} SET createdby = ?, modifiedby = ? WHERE category = ?", array($user->id, $user->id, $qcategory->id));
}
}
// Enrol the user.
if ($tool = $DB->get_record('local_ltiprovider', array('contextid' => $newcoursecontextid->id))) {
$roles = explode(',', strtolower($context->info['roles']));
local_ltiprovider_enrol_user($tool, $user, $roles, true);
}
// Now, we unenrol all the users except the one who created the course.
$plugins = enrol_get_plugins(true);
$instances = enrol_get_instances($course->id, true);
foreach ($instances as $key => $instance) {
if (!isset($plugins[$instance->enrol])) {
unset($instances[$key]);
continue;
}
}
$sql = "SELECT ue.*\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)";
$params = array('courseid' => $course->id, 'courselevel' => CONTEXT_COURSE);
$rs = $DB->get_recordset_sql($sql, $params);
foreach ($rs as $ue) {
if ($ue->userid == $user->id) {
continue;
}
if (!isset($instances[$ue->enrolid])) {
continue;
}
$instance = $instances[$ue->enrolid];
$plugin = $plugins[$instance->enrol];
if (!$plugin->allow_unenrol($instance) and !$plugin->allow_unenrol_user($instance, $ue)) {
continue;
}
$plugin->unenrol_user($instance, $ue->userid);
}
$rs->close();
groups_delete_group_members($course->id);
groups_delete_groups($course->id, false);
groups_delete_groupings_groups($course->id, false);
groups_delete_groupings($course->id, false);
}
}
return $course;
}
示例6: reset_course_userdata
/**
* This function will empty a course of USER data as much as
/// possible. It will retain the activities and the structure
/// of the course.
*
* @uses $USER
* @uses $SESSION
* @uses $CFG
* @param object $data an object containing all the boolean settings and courseid
* @param bool $showfeedback if false then do it all silently
* @return bool
* @todo Finish documenting this function
*/
function reset_course_userdata($data, $showfeedback = true)
{
global $CFG, $USER, $SESSION;
require_once $CFG->dirroot . '/group/lib.php';
$result = true;
$strdeleted = get_string('deleted');
// Look in every instance of every module for data to delete
if ($allmods = get_records('modules')) {
foreach ($allmods as $mod) {
$modname = $mod->name;
$modfile = $CFG->dirroot . '/mod/' . $modname . '/lib.php';
$moddeleteuserdata = $modname . '_delete_userdata';
// Function to delete user data
if (file_exists($modfile)) {
@(include_once $modfile);
if (function_exists($moddeleteuserdata)) {
$moddeleteuserdata($data, $showfeedback);
}
}
}
} else {
error('No modules are installed!');
}
// Delete other stuff
$context = get_context_instance(CONTEXT_COURSE, $data->courseid);
if (!empty($data->reset_students) or !empty($data->reset_teachers)) {
$teachers = array_keys(get_users_by_capability($context, 'moodle/course:update'));
$participants = array_keys(get_users_by_capability($context, 'moodle/course:view'));
$students = array_diff($participants, $teachers);
if (!empty($data->reset_students)) {
foreach ($students as $studentid) {
role_unassign(0, $studentid, 0, $context->id);
}
if ($showfeedback) {
notify($strdeleted . ' ' . get_string('students'), 'notifysuccess');
}
/// Delete group members (but keep the groups)
$result = groups_delete_group_members($data->courseid, $showfeedback) && $result;
}
if (!empty($data->reset_teachers)) {
foreach ($teachers as $teacherid) {
role_unassign(0, $teacherid, 0, $context->id);
}
if ($showfeedback) {
notify($strdeleted . ' ' . get_string('teachers'), 'notifysuccess');
}
}
}
if (!empty($data->reset_groups)) {
$result = groups_delete_groupings($data->courseid, $showfeedback) && $result;
$result = groups_delete_groups($data->courseid, $showfeedback) && $result;
}
if (!empty($data->reset_events)) {
if (delete_records('event', 'courseid', $data->courseid)) {
if ($showfeedback) {
notify($strdeleted . ' event', 'notifysuccess');
}
} else {
$result = false;
}
}
if (!empty($data->reset_logs)) {
if (delete_records('log', 'course', $data->courseid)) {
if ($showfeedback) {
notify($strdeleted . ' log', 'notifysuccess');
}
} else {
$result = false;
}
}
// deletes all role assignments, and local override,
// these have no courseid in table and needs separate process
delete_records('role_capabilities', 'contextid', $context->id);
// force accessinfo refresh for users visiting this context...
mark_context_dirty($context->path);
return $result;
}