public function save_changes() { global $DB; 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); } // 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(); }
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(); }