PageRenderTime 59ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/Menus/Controller/MenusController.php

https://github.com/kareypowell/croogo
PHP | 140 lines | 63 code | 15 blank | 62 comment | 11 complexity | b370a15a99ecd242b3e3091ed60d505d MD5 | raw file
  1. <?php
  2. App::uses('MenusAppController', 'Menus.Controller');
  3. /**
  4. * Menus Controller
  5. *
  6. * @category Controller
  7. * @package Croogo.Menus.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 MenusController extends MenusAppController {
  14. /**
  15. * Controller name
  16. *
  17. * @var string
  18. * @access public
  19. */
  20. public $name = 'Menus';
  21. /**
  22. * Models used by the Controller
  23. *
  24. * @var array
  25. * @access public
  26. */
  27. public $uses = array('Menus.Menu');
  28. /**
  29. * afterConstruct
  30. */
  31. public function afterConstruct() {
  32. parent::afterConstruct();
  33. $this->_setupAclComponent();
  34. }
  35. /**
  36. * beforeFilter
  37. *
  38. */
  39. public function beforeFilter() {
  40. parent::beforeFilter();
  41. $this->Security->unlockedActions[] = 'admin_toggle';
  42. }
  43. /**
  44. * Toggle Link status
  45. *
  46. * @param $id string Link id
  47. * @param $status integer Current Link status
  48. * @return void
  49. */
  50. public function admin_toggle($id = null, $status = null) {
  51. $this->Croogo->fieldToggle($this->Menu, $id, $status);
  52. }
  53. /**
  54. * Admin index
  55. *
  56. * @return void
  57. * @access public
  58. */
  59. public function admin_index() {
  60. $this->set('title_for_layout', __d('croogo', 'Menus'));
  61. $this->Menu->recursive = 0;
  62. $this->paginate['Menu']['order'] = 'Menu.id ASC';
  63. $this->set('menus', $this->paginate());
  64. }
  65. /**
  66. * Admin add
  67. *
  68. * @return void
  69. * @access public
  70. */
  71. public function admin_add() {
  72. $this->set('title_for_layout', __d('croogo', 'Add Menu'));
  73. if (!empty($this->request->data)) {
  74. $this->Menu->create();
  75. if ($this->Menu->save($this->request->data)) {
  76. $this->Session->setFlash(__d('croogo', 'The Menu has been saved'), 'default', array('class' => 'success'));
  77. $this->Croogo->redirect(array('action' => 'edit', $this->Menu->id));
  78. } else {
  79. $this->Session->setFlash(__d('croogo', 'The Menu could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  80. }
  81. }
  82. }
  83. /**
  84. * Admin edit
  85. *
  86. * @param integer $id
  87. * @return void
  88. * @access public
  89. */
  90. public function admin_edit($id = null) {
  91. $this->set('title_for_layout', __d('croogo', 'Edit Menu'));
  92. if (!$id && empty($this->request->data)) {
  93. $this->Session->setFlash(__d('croogo', 'Invalid Menu'), 'default', array('class' => 'error'));
  94. return $this->redirect(array('action' => 'index'));
  95. }
  96. if (!empty($this->request->data)) {
  97. if ($this->Menu->save($this->request->data)) {
  98. $this->Session->setFlash(__d('croogo', 'The Menu has been saved'), 'default', array('class' => 'success'));
  99. $this->Croogo->redirect(array('action' => 'edit', $this->Menu->id));
  100. } else {
  101. $this->Session->setFlash(__d('croogo', 'The Menu could not be saved. Please, try again.'), 'default', array('class' => 'error'));
  102. }
  103. }
  104. if (empty($this->request->data)) {
  105. $this->request->data = $this->Menu->read(null, $id);
  106. }
  107. }
  108. /**
  109. * Admin delete
  110. *
  111. * @param integer $id
  112. * @return void
  113. * @access public
  114. */
  115. public function admin_delete($id = null) {
  116. if (!$id) {
  117. $this->Session->setFlash(__d('croogo', 'Invalid id for Menu'), 'default', array('class' => 'error'));
  118. return $this->redirect(array('action' => 'index'));
  119. }
  120. if ($this->Menu->delete($id)) {
  121. $this->Session->setFlash(__d('croogo', 'Menu deleted'), 'default', array('class' => 'success'));
  122. return $this->redirect(array('action' => 'index'));
  123. }
  124. }
  125. }