/Users/Controller/RolesController.php
PHP | 113 lines | 53 code | 12 blank | 48 comment | 11 complexity | 034c1b0be69003910d08fd6627bad32d MD5 | raw file
- <?php
- App::uses('UsersAppController', 'Users.Controller');
- /**
- * Roles Controller
- *
- * @category Controller
- * @package Croogo.Users.Controller
- * @version 1.0
- * @author Fahad Ibnay Heylaal <contact@fahad19.com>
- * @license http://www.opensource.org/licenses/mit-license.php The MIT License
- * @link http://www.croogo.org
- */
- class RolesController extends UsersAppController {
- /**
- * Controller name
- *
- * @var string
- * @access public
- */
- public $name = 'Roles';
- /**
- * Models used by the Controller
- *
- * @var array
- * @access public
- */
- public $uses = array('Users.Role');
- /**
- * Admin index
- *
- * @return void
- * @access public
- */
- public function admin_index() {
- $this->set('title_for_layout', __d('croogo', 'Roles'));
- $this->Role->recursive = 0;
- $this->paginate['Role']['order'] = "Role.id ASC";
- $this->set('roles', $this->paginate());
- $this->set('displayFields', $this->Role->displayFields());
- }
- /**
- * Admin add
- *
- * @return void
- * @access public
- */
- public function admin_add() {
- $this->set('title_for_layout', __d('croogo', 'Add Role'));
- if (!empty($this->request->data)) {
- $this->Role->create();
- if ($this->Role->save($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'The Role has been saved'), 'default', array('class' => 'success'));
- return $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__d('croogo', 'The Role could not be saved. Please, try again.'), 'default', array('class' => 'error'));
- }
- }
- }
- /**
- * Admin edit
- *
- * @param integer $id
- * @return void
- * @access public
- */
- public function admin_edit($id = null) {
- $this->set('title_for_layout', __d('croogo', 'Edit Role'));
- if (!$id && empty($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'Invalid Role'), 'default', array('class' => 'error'));
- return $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->request->data)) {
- if ($this->Role->save($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'The Role has been saved'), 'default', array('class' => 'success'));
- return $this->Croogo->redirect(array('action' => 'edit', $this->Role->id));
- } else {
- $this->Session->setFlash(__d('croogo', 'The Role could not be saved. Please, try again.'), 'default', array('class' => 'error'));
- }
- }
- if (empty($this->request->data)) {
- $this->request->data = $this->Role->read(null, $id);
- }
- }
- /**
- * Admin delete
- *
- * @param integer $id
- * @return void
- * @access public
- */
- public function admin_delete($id = null) {
- if (!$id) {
- $this->Session->setFlash(__d('croogo', 'Invalid id for Role'), 'default', array('class' => 'error'));
- return $this->redirect(array('action' => 'index'));
- }
- if ($this->Role->delete($id)) {
- $this->Session->setFlash(__d('croogo', 'Role deleted'), 'default', array('class' => 'success'));
- return $this->redirect(array('action' => 'index'));
- }
- }
- }