/** * Role edit method * * @return void */ public function edit() { if (null === $this->request->getPath(1)) { Response::redirect($this->request->getBasePath()); } else { $this->prepareView('roles.phtml', array('assets' => $this->project->getAssets(), 'acl' => $this->project->getService('acl'), 'phireNav' => $this->project->getService('phireNav'))); $role = new Model\UserRole(); $role->getById($this->request->getPath(1)); // If role is found and valid if (isset($role->name)) { $this->view->set('title', $this->view->i18n->__('User Roles') . ' ' . $this->view->separator . ' ' . $role->name)->set('data_title', $this->view->i18n->__('User Roles') . ' ' . $this->view->separator . ' '); $form = new Form\UserRole($this->request->getBasePath() . $this->request->getRequestUri(), 'post', $role->id, $this->project->module('Phire')); // If form is submitted if ($this->request->isPost()) { $form->setFieldValues($this->request->getPost(), array('htmlentities' => array(ENT_QUOTES, 'UTF-8'))); // If form is valid, save role if ($form->isValid()) { $role->update($form); $this->view->set('id', $role->id); if (null !== $this->request->getPost('update_value') && $this->request->getPost('update_value') == '1') { Response::redirect($this->request->getBasePath() . '/edit/' . $role->id . '?saved=' . time()); } else { if (null !== $this->request->getQuery('update')) { $this->sendJson(array('updated' => '', 'form' => 'user-role-form')); } else { Response::redirect($this->request->getBasePath() . '?saved=' . time()); } } // Else, re-render the form with errors } else { if (null !== $this->request->getQuery('update')) { $this->sendJson($form->getErrors()); } else { $this->view->set('form', $form); $this->send(); } } // Else, render form } else { $form->setFieldValues($role->getData(null, false)); $this->view->set('form', $form); $this->send(); } // Else, redirect } else { Response::redirect($this->request->getBasePath()); } } }