本文整理汇总了PHP中delete_role函数的典型用法代码示例。如果您正苦于以下问题:PHP delete_role函数的具体用法?PHP delete_role怎么用?PHP delete_role使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了delete_role函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
public function execute()
{
global $CFG, $DB;
require_once $CFG->libdir . DIRECTORY_SEPARATOR . "accesslib.php";
$options = $this->expandedOptions;
$arguments = $this->arguments;
//execute method
//delete by id?
if ($options['id']) {
$role = $DB->get_record('role', array('id' => $arguments[0]));
if (!$role) {
echo "Role with id '" . $arguments[0] . "' does not exist\n";
exit(0);
}
delete_role($arguments[0]);
} else {
$role = $DB->get_record('role', array('shortname' => $arguments[0]));
if (!$role) {
echo "Role '" . $arguments[0] . "' does not exist.\n";
exit(0);
}
delete_role($role->id);
}
echo "\n";
}
示例2: xmldb_adobeconnect_uninstall
/**
* @package mod
* @subpackage adobeconnect
* @author Akinsaya Delamarre (adelamarre@remote-learner.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
function xmldb_adobeconnect_uninstall()
{
global $DB;
$result = true;
$param = array('shortname' => 'adobeconnectparticipant');
if ($mrole = $DB->get_record('role', $param)) {
$result = $result && delete_role($mrole->id);
}
$param = array('shortname' => 'adobeconnectpresenter');
if ($mrole = $DB->get_record('role', $param)) {
$result = $result && delete_role($mrole->id);
}
$param = array('shortname' => 'adobeconnecthost');
if ($mrole = $DB->get_record('role', $param)) {
$result = $result && delete_role($mrole->id);
}
return $result;
}
示例3: xmldb_block_demostudent_uninstall
/**
* @package block
* @subpackage demostudent
* @author Dominik Royko royko@ualberta.ca
*/
function xmldb_block_demostudent_uninstall()
{
global $DB;
$result = true;
// Delete all traces of the DemoStudent role.
if ($cruftyrole = $DB->get_record('role', array('shortname' => 'demostudent'))) {
$result = $result && delete_role($cruftyrole->id);
}
// And delete the capabilities specific to the block.
// Would have expected this to happen automatically, but it didn't seem to.
$capparam = array('capability' => 'block/demostudent:myaddinstance');
if ($cruftycapability = $DB->get_records('role_capabilities', $capparam)) {
$result = $result && $DB->delete_records('role_capabilities', $capparam);
}
$capparam = array('capability' => 'block/demostudent:seedemostudentblock');
if ($cruftycapability = $DB->get_records('role_capabilities', $capparam)) {
$result = $result && $DB->delete_records('role_capabilities', $capparam);
}
return $result;
}
示例4: test_delete_role
/**
* Test deleting of roles.
*/
public function test_delete_role()
{
global $DB;
$this->resetAfterTest();
$role = $DB->get_record('role', array('shortname' => 'manager'), '*', MUST_EXIST);
$user = $this->getDataGenerator()->create_user();
role_assign($role->id, $user->id, context_system::instance());
$course = $this->getDataGenerator()->create_course();
$rolename = (object) array('roleid' => $role->id, 'name' => 'Man', 'contextid' => context_course::instance($course->id)->id);
$DB->insert_record('role_names', $rolename);
$this->assertTrue($DB->record_exists('role_assignments', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_capabilities', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_names', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_context_levels', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_assign', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_assign', array('allowassign' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_override', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_override', array('allowoverride' => $role->id)));
// Delete role and get event.
$sink = $this->redirectEvents();
$result = delete_role($role->id);
$events = $sink->get_events();
$sink->close();
$event = array_pop($events);
$this->assertTrue($result);
$this->assertFalse($DB->record_exists('role', array('id' => $role->id)));
$this->assertFalse($DB->record_exists('role_assignments', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_capabilities', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_names', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_context_levels', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_assign', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_assign', array('allowassign' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_override', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_override', array('allowoverride' => $role->id)));
// Test triggered event.
$this->assertInstanceOf('\\core\\event\\role_deleted', $event);
$this->assertSame('role', $event->target);
$this->assertSame('role', $event->objecttable);
$this->assertSame($role->id, $event->objectid);
$this->assertEquals(context_system::instance(), $event->get_context());
$this->assertSame($role->shortname, $event->other['shortname']);
$this->assertSame($role->description, $event->other['description']);
$this->assertSame($role->archetype, $event->other['archetype']);
$expectedlegacylog = array(SITEID, 'role', 'delete', 'admin/roles/manage.php?action=delete&roleid=' . $role->id, $role->shortname, '');
$this->assertEventLegacyLogData($expectedlegacylog, $event);
}
示例5: test_delete_role
/**
* Test deleting of roles.
* @return void
*/
public function test_delete_role()
{
global $DB;
$this->resetAfterTest();
$role = $DB->get_record('role', array('shortname' => 'manager'), '*', MUST_EXIST);
$user = $this->getDataGenerator()->create_user();
role_assign($role->id, $user->id, context_system::instance());
$course = $this->getDataGenerator()->create_course();
$rolename = (object) array('roleid' => $role->id, 'name' => 'Man', 'contextid' => context_course::instance($course->id)->id);
$DB->insert_record('role_names', $rolename);
$this->assertTrue($DB->record_exists('role_assignments', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_capabilities', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_names', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_context_levels', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_assign', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_assign', array('allowassign' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_override', array('roleid' => $role->id)));
$this->assertTrue($DB->record_exists('role_allow_override', array('allowoverride' => $role->id)));
$result = delete_role($role->id);
$this->assertTrue($result);
$this->assertFalse($DB->record_exists('role', array('id' => $role->id)));
$this->assertFalse($DB->record_exists('role_assignments', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_capabilities', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_names', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_context_levels', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_assign', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_assign', array('allowassign' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_override', array('roleid' => $role->id)));
$this->assertFalse($DB->record_exists('role_allow_override', array('allowoverride' => $role->id)));
}
示例6: array
if (!$confirmed) {
// Show confirmation.
echo $OUTPUT->header();
$optionsyes = array('action' => 'delete', 'roleid' => $roleid, 'sesskey' => sesskey(), 'confirm' => 1);
$a = new stdClass();
$a->id = $roleid;
$a->name = $roles[$roleid]->name;
$a->shortname = $roles[$roleid]->shortname;
$a->count = $DB->count_records_select('role_assignments', 'roleid = ?', array($roleid), 'COUNT(DISTINCT userid)');
$formcontinue = new single_button(new moodle_url($baseurl, $optionsyes), get_string('yes'));
$formcancel = new single_button(new moodle_url($baseurl), get_string('no'), 'get');
echo $OUTPUT->confirm(get_string('deleterolesure', 'core_role', $a), $formcontinue, $formcancel);
echo $OUTPUT->footer();
die;
}
if (!delete_role($roleid)) {
// The delete failed, but mark the context dirty in case.
$systemcontext->mark_dirty();
print_error('cannotdeleterolewithid', 'error', $baseurl, $roleid);
}
// Deleted a role sitewide...
$systemcontext->mark_dirty();
redirect($baseurl);
break;
case 'moveup':
if (confirm_sesskey()) {
$prevrole = null;
$thisrole = null;
foreach ($roles as $role) {
if ($role->id == $roleid) {
$thisrole = $role;
示例7: moodle_group_delete_groups
function moodle_group_delete_groups($client) {
global $DB, $CFG;
//create category
$category = new stdClass();
$category->name = 'tmpcategoryfortest123';
$category->id = $DB->insert_record('course_categories', $category);
//create a course
$course = new stdClass();
$course->fullname = 'tmpcoursefortest123';
$course->shortname = 'tmpcoursefortest123';
$course->idnumber = 'tmpcoursefortest123';
$course->category = $category->id;
$course->id = $DB->insert_record('course', $course);
//create a role
$role1->id = create_role('role1thatshouldnotexist', 'role1thatshouldnotexist', '');
//create a user
$user = new stdClass();
$user->username = 'veryimprobabletestusername2';
$user->password = 'testpassword2';
$user->firstname = 'testfirstname2';
$user->lastname = 'testlastname2';
$user->email = 'testemail1@moodle.com';
$user->mnethostid = $CFG->mnet_localhost_id;
require_once($CFG->dirroot."/user/lib.php");
$user->id = user_create_user($user);
//create course context
$context = get_context_instance(CONTEXT_COURSE, $course->id, MUST_EXIST);
//enrol the user in the course with the created role
role_assign($role1->id, $user->id, $context->id);
$enrol = new stdClass();
$enrol->courseid = $course->id;
$enrol->roleid = $role1->id;
$enrol->id = $DB->insert_record('enrol', $enrol);
$enrolment = new stdClass();
$enrolment->userid = $user->id;
$enrolment->enrolid = $enrol->id;
$enrolment->id = $DB->insert_record('user_enrolments', $enrolment);
//create a group in the course
$group = new stdClass();
$group->courseid = $course->id;
$group->name = 'tmpgroufortest123';
$group->enrolmentkey = '';
$group->description = '';
$group->id = $DB->insert_record('groups', $group);
$group2 = new stdClass();
$group2->courseid = $course->id;
$group2->name = 'tmpgroufortest1233';
$group2->enrolmentkey = '';
$group2->description = '';
$group2->id = $DB->insert_record('groups', $group2);
$paramgroups = array($group, $group2);
require_once($CFG->dirroot . "/group/lib.php");
$groups = groups_get_all_groups($course->id);
$this->assertEqual(2, count($groups));
//WEBSERVICE CALL - delete the group
$function = 'moodle_group_delete_groups';
$params = array('groupids' => array($group->id, $group2->id));
$client->call($function, $params);
$groups = groups_get_all_groups($course->id);
$this->assertEqual(0, count($groups));
//unenrol the user
$DB->delete_records('user_enrolments', array('id' => $enrolment->id));
$DB->delete_records('enrol', array('id' => $enrol->id));
role_unassign($role1->id, $user->id, $context->id);
//delete course context
delete_context(CONTEXT_COURSE, $course->id);
//delete the user
$DB->delete_records('user', array('id' => $user->id));
//delete the role
delete_role($role1->id);
//delete the course
$DB->delete_records('course', array('id' => $course->id));
//delete the category
$DB->delete_records('course_categories', array('id' => $category->id));
}
示例8: isset
<?php
$semid = isset($_POST['semid']) ? $_POST['semid'] : '';
$semester = semester_load($semid);
if (isset($_POST['submit'])) {
delete_role($_POST['id']);
sleep(1);
header('location: ' . currentURL() . '?p=semester');
}
?>
<h3>Do you want to delete the semester "<?php
print $semester['Semester_Code'];
?>
"?</h3>
<form method="post" action="">
<input type="hidden" name="id" value="<?php
print $semid;
?>
"/>
<input type="submit" name="submit" value="Delete" />
<button onclick="history.go(-1);return false;">Cancel</button>
</form>
示例9: tao_reset_custom_roles
/**
* When called resets all custom roles as per definition set down in /local/roles.php
*
* Note that this uses the non-core role.custom field to isolate roles to remove.
*
* Utilise the $path parameter to allow for localisation (i.e. different roles defintion than core).
*
* Sort order is reset based on the order listed in the defintion.
*
* WARNING: as long as you retain the same shortname existing user role assigments will
* be retained. if you change the shortname they will be lost.
*
* KNOWN ISSUE: we rely on shortname being unique, but this is not enforced by the db.
* this is more a problem with moodle.
*
* @param text $path
*
*/
function tao_reset_custom_roles($path = 'local')
{
global $CFG;
if (!get_site()) {
// not finished installing, skip
return true;
}
// get latest role definition from roles file
$rolespath = $CFG->dirroot . '/' . $path . '/roles.php';
if (!file_exists($rolespath)) {
debugging("Local caps reassignment called with invalid path {$path}");
return false;
}
require_once $rolespath;
if (!isset($customroles)) {
return true;
// nothing to do.
}
$undeletableroles = array();
$undeletableroles[$CFG->notloggedinroleid] = 1;
$undeletableroles[$CFG->guestroleid] = 1;
$undeletableroles[$CFG->defaultuserroleid] = 1;
$undeletableroles[$CFG->defaultcourseroleid] = 1;
// If there is only one admin role, add that to $undeletableroles too.
$adminroles = get_admin_roles();
if (count($adminroles) == 1) {
$undeletableroles[reset($adminroles)->id] = 1;
}
// get recordset of existing custom roles
$sql = "SELECT id, name, shortname, description, sortorder, custom\n FROM {$CFG->prefix}role\n WHERE custom IS NOT NULL";
$roles = get_records_sql($sql);
// remove custom roles that are not in the latest definition
foreach ($roles as $role) {
// check whether this role is in the latest definition
if (array_key_exists($role->shortname, $customroles)) {
continue;
}
// extra safety: check undeletable roles
if (isset($undeletableroles[$role->id])) {
continue;
}
delete_role($role->id);
}
// hack to avoid sortorder unique constraint
execute_sql("UPDATE {$CFG->prefix}role SET sortorder = (sortorder+1000) WHERE custom IS NOT NULL");
// set sortorder to current highest value
$sortorder = get_field_sql("SELECT " . sql_max('sortorder') . " FROM {$CFG->prefix}role WHERE custom IS NULL");
// now loop through the new settings
foreach ($customroles as $shortname => $role) {
$sortorder++;
// get the roleid
$roleid = get_field('role', 'id', 'shortname', $shortname);
// if exists then make updates
if (!empty($roleid)) {
// only update fields that have been set
if (isset($role['name'])) {
set_field('role', 'name', $role['name'], 'shortname', $shortname);
}
if (isset($role['description'])) {
set_field('role', 'description', $role['description'], 'shortname', $shortname);
}
// reset sortorder
set_field('role', 'sortorder', $sortorder, 'shortname', $shortname);
// else create record
} else {
$newrole = new stdclass();
$newrole->name = $role['name'];
$newrole->shortname = $shortname;
$newrole->description = $role['description'];
$newrole->sortorder = $sortorder;
$newrole->custom = 1;
$roleid = insert_record('role', $newrole);
}
// remove any previously set legacy roles
$legacyroles = get_legacy_roles();
foreach ($legacyroles as $ltype => $lcap) {
unassign_capability($lcap, $roleid);
}
// reset legacy role
if (isset($role['legacy'])) {
$legacycap = $legacyroles[$role['legacy']];
$context = get_context_instance(CONTEXT_SYSTEM);
//.........这里部分代码省略.........
示例10: adobeconnect_uninstall
/**
* Execute post-uninstall custom actions for the module
* This function was added in 1.9
*
* @return boolean true if success, false on error
*/
function adobeconnect_uninstall()
{
$result = true;
if ($mrole = get_record('role', 'shortname', 'adobeconnectparticipant')) {
$result = $result && delete_role($mrole->id);
$result = $result && delete_records('role_allow_assign', 'allowassign', $mrole->id);
}
if ($prole = get_record('role', 'shortname', 'adobeconnectpresenter')) {
$result = $result && delete_role($prole->id);
$result = $result && delete_records('role_allow_assign', 'allowassign', $prole->id);
}
if ($prole = get_record('role', 'shortname', 'adobeconnecthost')) {
$result = $result && delete_role($prole->id);
$result = $result && delete_records('role_allow_assign', 'allowassign', $prole->id);
}
return $result;
}
示例11: elluminate_uninstall
/**
* Clean up the roles we created during install.
*
* @param none
* @return bool True on success, False otherwise.
*/
function elluminate_uninstall()
{
$result = true;
if ($mrole = get_record('role', 'shortname', 'elluminatemoderator')) {
$result = $result && delete_role($mrole->id);
$result = $result && delete_records('role_allow_assign', 'allowassign', $mrole->id);
}
if ($prole = get_record('role', 'shortname', 'elluminateparticipant')) {
$result = $result && delete_role($prole->id);
$result = $result && delete_records('role_allow_assign', 'allowassign', $prole->id);
}
return $result;
}