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); // Permissions. parent::save_changes(); }
public function save_changes() { global $DB; if (!$this->roleid) { // Creating role if (isset($this->legacyroles[$this->role->legacytype])) { $legacycap = $this->legacyroles[$this->role->legacytype]; } else { $legacycap = ''; } $this->role->id = create_role($this->role->name, $this->role->shortname, $this->role->description, $legacycap); $this->roleid = $this->role->id; // Needed to make the parent::save_changes(); call work. } else { // Updating role $DB->update_record('role', $this->role); // Legacy type foreach ($this->legacyroles as $type => $cap) { if ($type == $this->role->legacytype) { assign_capability($cap, CAP_ALLOW, $this->role->id, $this->context->id); } else { unassign_capability($cap, $this->role->id); } } } // Assignable contexts. set_role_contextlevels($this->role->id, $this->contextlevels); // Permissions. parent::save_changes(); }