/** * Create a new privilege * @param string $key The privilege key, e.g. my_app.object.verb * @param string $title A human-readable description for the UI * @param integer $order=1 Display order within its section * @return object New UserPrivilege object instance */ public function create_privilege($key, $title, $order = 1) { $Priv = $this->get_one_by('privKey', $key); if (is_object($Priv)) { return $Priv; } $data = array(); $data['privKey'] = $key; $data['privTitle'] = $title; $data['privOrder'] = $order; return parent::create($data); }
<?php $Roles = new PerchUserRoles(); $Privs = new PerchUserPrivileges(); if (isset($_GET['id']) && is_numeric($_GET['id'])) { $id = (int) $_GET['id']; $Role = $Roles->find($id); } else { $id = false; $Role = false; } $Form = new PerchForm('role', false); $req = array(); $req['roleTitle'] = "Required"; $Form->set_required($req); if ($Form->posted() && $Form->validate()) { PerchUtil::debug($_POST); $data = array(); $postvars = array('roleTitle'); $data = $Form->receive($postvars); $data['roleSlug'] = PerchUtil::urlify($data['roleTitle']); if (is_object($Role)) { $Role->update($data); } else { $Role = $Roles->create($data); } $privs = $Form->find_items('privs-'); $new_privs = array(); if (PerchUtil::count($privs)) { foreach ($privs as $category) { if (PerchUtil::count($category)) {