/** * Edit action method * * @param int $id * @return void */ public function edit($id) { $role = new Model\Role(); $role->getById($id); if (!isset($role->id)) { $this->redirect(BASE_PATH . APP_URI . '/roles'); } $this->prepareView('phire/roles/edit.phtml'); $this->view->title = 'Roles'; $this->view->role_name = $role->name; $fields = $this->application->config()['forms']['Phire\\Form\\Role']; $config = $this->application->config(); $resources = ['----' => '----']; $parents = ['----' => '----']; $roles = (new Model\Role())->getAll(); if (count($roles) > 0) { foreach ($roles as $r) { if ($r['id'] != $id) { $parents[$r['id']] = $r['name']; } } } foreach ($config['resources'] as $resource => $perms) { if (strpos($resource, '|') !== false) { $resource = explode('|', $resource); $resources[$resource[0]] = $resource[1]; } else { $resources[$resource] = $resource; } } $fields[0]['role_parent_id']['value'] = $parents; $fields[2]['resource_1']['value'] = $resources; $this->view->form = new Form\Role($fields); $this->view->form->addFilter('htmlentities', [ENT_QUOTES, 'UTF-8'])->setFieldValues($role->toArray()); if ($this->request->isPost()) { $this->view->form->addFilter('strip_tags')->setFieldValues($this->request->getPost()); if ($this->view->form->isValid()) { $role = new Model\Role(); $role->update($this->request->getPost(), $this->sess); $this->view->id = $role->id; $this->sess->setRequestValue('saved', true); $this->redirect(BASE_PATH . APP_URI . '/roles/edit/' . $role->id); } } $this->send(); }
/** * Password action method * * @return void */ public function edit() { $roleId = $this->getRoleId(); $name = ''; while ($name == '') { $name = $this->console->prompt($this->console->getIndent() . 'Enter Name: ', null, true); } $verification = ''; while (strtolower($verification) != 'y' && strtolower($verification) != 'n') { $verification = $this->console->prompt($this->console->getIndent() . 'Verification? (Y/N) '); } $approval = ''; while (strtolower($approval) != 'y' && strtolower($approval) != 'n') { $approval = $this->console->prompt($this->console->getIndent() . 'Approval? (Y/N) '); } $emailAsUsername = ''; while (strtolower($emailAsUsername) != 'y' && strtolower($emailAsUsername) != 'n') { $emailAsUsername = $this->console->prompt($this->console->getIndent() . 'Email as Username? (Y/N): '); } $emailRequired = ''; while (strtolower($emailRequired) != 'y' && strtolower($emailRequired) != 'n') { $emailRequired = $this->console->prompt($this->console->getIndent() . 'Email Required? (Y/N): '); } $fields = ['id' => $roleId, 'role_parent_id' => '----', 'name' => $name, 'verification' => strtolower($verification) == 'y' ? 1 : 0, 'approval' => strtolower($approval) == 'y' ? 1 : 0, 'email_as_username' => strtolower($emailAsUsername) == 'y' ? 1 : 0, 'email_required' => strtolower($emailRequired) == 'y' ? 1 : 0]; $role = new Model\Role(); $role->update($fields); $this->console->write(); $this->console->write($this->console->colorize('Role Updated!', Console::BOLD_GREEN)); }