/** * Saves new or update role. Echoes error/success message */ public function executeSave(sfWebRequest $request) { if (!$this->getUser()->hasCredential(array('Administrator'), false)) { $this->getUser()->setFlash("warning", 'You don\'t have permission to access this url ' . $request->getReferer()); $this->redirect('dashboard/index'); } $id = $request->getParameter('id'); if ($id) { $role = RolePeer::retrieveByPK($id); if (!$role instanceof Role) { return $this->renderText('<span style="color:red;">Role not found or is removed!</span>'); } $form = new RoleForm($role); } else { $form = new RoleForm(); } unset($form['_csrf_token']); $form->bind($request->getPostParameters()); if ($form->isValid()) { $form->save(); return $this->renderText('Role has been successfully saved!'); } else { # FIXME display other field errors echo 'e1'; # has error echo '<span style="color:red;">' . $form['title']->getError()->getMessage() . '</span>'; } return sfView::NONE; }
public function executeSave(sfWebRequest $request) { $role = RolePeer::retrieveByPK($request->getParameter('id')); $this->forward404Unless($role); $perms = $request->getParameter('permissions'); if (!is_array($perms)) { $perms = array(); } # remove rights $c = new Criteria(); $c->add(RolePermissionPeer::ROLE_ID, $role->getId()); RolePermissionPeer::doDelete($c); # save new rights foreach ($perms as $perm) { $role_permission = new RolePermission(); $role_permission->setPermissionId($perm); $role_permission->setRoleId($role->getId()); $role_permission->save(); } return $this->renderText('Rights for \'' . $role->getTitle() . '\' have successfully saved!'); }
<?php } ?> <?php } else { ?> <div class="person-table-data"> <h3>Security Role</h3> <table style="width: 100px"> <?php foreach ($assoc_roles as $assoc_role) { ?> <tr class="alt"> <td class="cell-1"> <?php $ro = RolePeer::retrieveByPK($assoc_role); echo $ro->getTitle(); echo "<br/>"; ?> </td> </tr> <?php } ?> </table> </div> <?php } ?> <?php if ($sf_user->hasCredential(array('Administrator', 'Staff', 'Coordinator'), false)) {
public function getRole($con = null) { include_once 'lib/model/om/BaseRolePeer.php'; if ($this->aRole === null && $this->role_id !== null) { $this->aRole = RolePeer::retrieveByPK($this->role_id, $con); } return $this->aRole; }