当前位置: 首页>>代码示例>>PHP>>正文


PHP coursecat::role_assignment_changed方法代码示例

本文整理汇总了PHP中coursecat::role_assignment_changed方法的典型用法代码示例。如果您正苦于以下问题:PHP coursecat::role_assignment_changed方法的具体用法?PHP coursecat::role_assignment_changed怎么用?PHP coursecat::role_assignment_changed使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在coursecat的用法示例。


在下文中一共展示了coursecat::role_assignment_changed方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: role_unassign_all

/**
 * Removes multiple role assignments, parameters may contain:
 *   'roleid', 'userid', 'contextid', 'component', 'enrolid'.
 *
 * @param array $params role assignment parameters
 * @param bool $subcontexts unassign in subcontexts too
 * @param bool $includemanual include manual role assignments too
 * @return void
 */
function role_unassign_all(array $params, $subcontexts = false, $includemanual = false)
{
    global $USER, $CFG, $DB;
    require_once $CFG->libdir . '/coursecatlib.php';
    if (!$params) {
        throw new coding_exception('Missing parameters in role_unsassign_all() call');
    }
    $allowed = array('roleid', 'userid', 'contextid', 'component', 'itemid');
    foreach ($params as $key => $value) {
        if (!in_array($key, $allowed)) {
            throw new coding_exception('Unknown role_unsassign_all() parameter key', 'key:' . $key);
        }
    }
    if (isset($params['component']) and $params['component'] !== '' and strpos($params['component'], '_') === false) {
        throw new coding_exception('Invalid component paramter in role_unsassign_all() call', 'component:' . $params['component']);
    }
    if ($includemanual) {
        if (!isset($params['component']) or $params['component'] === '') {
            throw new coding_exception('include manual parameter requires component parameter in role_unsassign_all() call');
        }
    }
    if ($subcontexts) {
        if (empty($params['contextid'])) {
            throw new coding_exception('subcontexts paramtere requires component parameter in role_unsassign_all() call');
        }
    }
    $ras = $DB->get_records('role_assignments', $params);
    foreach ($ras as $ra) {
        $DB->delete_records('role_assignments', array('id' => $ra->id));
        if ($context = context::instance_by_id($ra->contextid, IGNORE_MISSING)) {
            // this is a bit expensive but necessary
            $context->mark_dirty();
            // If the user is the current user, then do full reload of capabilities too.
            if (!empty($USER->id) && $USER->id == $ra->userid) {
                reload_all_capabilities();
            }
            $event = \core\event\role_unassigned::create(array('context' => $context, 'objectid' => $ra->roleid, 'relateduserid' => $ra->userid, 'other' => array('id' => $ra->id, 'component' => $ra->component, 'itemid' => $ra->itemid)));
            $event->add_record_snapshot('role_assignments', $ra);
            $event->trigger();
            coursecat::role_assignment_changed($ra->roleid, $context);
        }
    }
    unset($ras);
    // process subcontexts
    if ($subcontexts and $context = context::instance_by_id($params['contextid'], IGNORE_MISSING)) {
        if ($params['contextid'] instanceof context) {
            $context = $params['contextid'];
        } else {
            $context = context::instance_by_id($params['contextid'], IGNORE_MISSING);
        }
        if ($context) {
            $contexts = $context->get_child_contexts();
            $mparams = $params;
            foreach ($contexts as $context) {
                $mparams['contextid'] = $context->id;
                $ras = $DB->get_records('role_assignments', $mparams);
                foreach ($ras as $ra) {
                    $DB->delete_records('role_assignments', array('id' => $ra->id));
                    // this is a bit expensive but necessary
                    $context->mark_dirty();
                    // If the user is the current user, then do full reload of capabilities too.
                    if (!empty($USER->id) && $USER->id == $ra->userid) {
                        reload_all_capabilities();
                    }
                    $event = \core\event\role_unassigned::create(array('context' => $context, 'objectid' => $ra->roleid, 'relateduserid' => $ra->userid, 'other' => array('id' => $ra->id, 'component' => $ra->component, 'itemid' => $ra->itemid)));
                    $event->add_record_snapshot('role_assignments', $ra);
                    $event->trigger();
                    coursecat::role_assignment_changed($ra->roleid, $context);
                }
            }
        }
    }
    // do this once more for all manual role assignments
    if ($includemanual) {
        $params['component'] = '';
        role_unassign_all($params, $subcontexts, false);
    }
}
开发者ID:alanaipe2015,项目名称:moodle,代码行数:87,代码来源:accesslib.php

示例2: save_local_role_names

/**
 * Save the Your name for 'Some role' strings.
 *
 * @param integer $courseid the id of this course.
 * @param array $data the data that came from the course settings form.
 */
function save_local_role_names($courseid, $data)
{
    global $DB;
    $context = context_course::instance($courseid);
    foreach ($data as $fieldname => $value) {
        if (strpos($fieldname, 'role_') !== 0) {
            continue;
        }
        list($ignored, $roleid) = explode('_', $fieldname);
        // make up our mind whether we want to delete, update or insert
        if (!$value) {
            $DB->delete_records('role_names', array('contextid' => $context->id, 'roleid' => $roleid));
        } else {
            if ($rolename = $DB->get_record('role_names', array('contextid' => $context->id, 'roleid' => $roleid))) {
                $rolename->name = $value;
                $DB->update_record('role_names', $rolename);
            } else {
                $rolename = new stdClass();
                $rolename->contextid = $context->id;
                $rolename->roleid = $roleid;
                $rolename->name = $value;
                $DB->insert_record('role_names', $rolename);
            }
        }
        // This will ensure the course contacts cache is purged..
        coursecat::role_assignment_changed($roleid, $context);
    }
}
开发者ID:rushi963,项目名称:moodle,代码行数:34,代码来源:lib.php

示例3: save_changes

 public function save_changes()
 {
     global $DB, $CFG;
     if (!$this->roleid) {
         // Creating role.
         $this->role->id = create_role($this->role->name, $this->role->shortname, $this->role->description, $this->role->archetype);
         $this->roleid = $this->role->id;
         // Needed to make the parent::save_changes(); call work.
     } else {
         // Updating role.
         $DB->update_record('role', $this->role);
         // This will ensure the course contacts cache is purged so name changes get updated in
         // the UI. It would be better to do this only when we know that fields affected are
         // updated. But thats getting into the weeds of the coursecat cache and role edits
         // should not be that frequent, so here is the ugly brutal approach.
         require_once $CFG->libdir . '/coursecatlib.php';
         coursecat::role_assignment_changed($this->role->id, context_system::instance());
     }
     // Assignable contexts.
     set_role_contextlevels($this->role->id, $this->contextlevels);
     // Set allowed roles.
     $this->save_allow('assign');
     $this->save_allow('override');
     $this->save_allow('switch');
     // Permissions.
     parent::save_changes();
 }
开发者ID:EsdrasCaleb,项目名称:moodle,代码行数:27,代码来源:define_role_table_advanced.php


注:本文中的coursecat::role_assignment_changed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。