PageRenderTime 42ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/Blocks/Controller/RegionsController.php

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