PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Users/Controller/RolesController.php

https://github.com/kareypowell/croogo
PHP | 113 lines | 53 code | 12 blank | 48 comment | 11 complexity | 034c1b0be69003910d08fd6627bad32d MD5 | raw file
  1. <?php
  2. App::uses('UsersAppController', 'Users.Controller');
  3. /**
  4. * Roles Controller
  5. *
  6. * @category Controller
  7. * @package Croogo.Users.Controller
  8. * @version 1.0
  9. * @author Fahad Ibnay Heylaal <contact@fahad19.com>
  10. * @license http://www.opensource.org/licenses/mit-license.php The MIT License
  11. * @link http://www.croogo.org
  12. */
  13. class RolesController extends UsersAppController {
  14. /**
  15. * Controller name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Roles';
  21. /**
  22. * Models used by the Controller
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $uses = array('Users.Role');
  28. /**
  29. * Admin index
  30. *
  31. * @return void
  32. * @access public
  33. */
  34. public function admin_index() {
  35. $this->set('title_for_layout', __d('croogo', 'Roles'));
  36. $this->Role->recursive = 0;
  37. $this->paginate['Role']['order'] = "Role.id ASC";
  38. $this->set('roles', $this->paginate());
  39. $this->set('displayFields', $this->Role->displayFields());
  40. }
  41. /**
  42. * Admin add
  43. *
  44. * @return void
  45. * @access public
  46. */
  47. public function admin_add() {
  48. $this->set('title_for_layout', __d('croogo', 'Add Role'));
  49. if (!empty($this->request->data)) {
  50. $this->Role->create();
  51. if ($this->Role->save($this->request->data)) {
  52. $this->Session->setFlash(__d('croogo', 'The Role has been saved'), 'default', array('class' => 'success'));
  53. return $this->redirect(array('action' => 'index'));
  54. } else {
  55. $this->Session->setFlash(__d('croogo', 'The Role could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  56. }
  57. }
  58. }
  59. /**
  60. * Admin edit
  61. *
  62. * @param integer $id
  63. * @return void
  64. * @access public
  65. */
  66. public function admin_edit($id = null) {
  67. $this->set('title_for_layout', __d('croogo', 'Edit Role'));
  68. if (!$id && empty($this->request->data)) {
  69. $this->Session->setFlash(__d('croogo', 'Invalid Role'), 'default', array('class' => 'error'));
  70. return $this->redirect(array('action' => 'index'));
  71. }
  72. if (!empty($this->request->data)) {
  73. if ($this->Role->save($this->request->data)) {
  74. $this->Session->setFlash(__d('croogo', 'The Role has been saved'), 'default', array('class' => 'success'));
  75. return $this->Croogo->redirect(array('action' => 'edit', $this->Role->id));
  76. } else {
  77. $this->Session->setFlash(__d('croogo', 'The Role could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  78. }
  79. }
  80. if (empty($this->request->data)) {
  81. $this->request->data = $this->Role->read(null, $id);
  82. }
  83. }
  84. /**
  85. * Admin delete
  86. *
  87. * @param integer $id
  88. * @return void
  89. * @access public
  90. */
  91. public function admin_delete($id = null) {
  92. if (!$id) {
  93. $this->Session->setFlash(__d('croogo', 'Invalid id for Role'), 'default', array('class' => 'error'));
  94. return $this->redirect(array('action' => 'index'));
  95. }
  96. if ($this->Role->delete($id)) {
  97. $this->Session->setFlash(__d('croogo', 'Role deleted'), 'default', array('class' => 'success'));
  98. return $this->redirect(array('action' => 'index'));
  99. }
  100. }
  101. }