/Blocks/Controller/RegionsController.php
PHP | 143 lines | 69 code | 14 blank | 60 comment | 11 complexity | 3f043583ba4f8cdfcd82cbff865efcf5 MD5 | raw file
- <?php
- App::uses('BlocksAppController', 'Blocks.Controller');
- /**
- * Regions Controller
- *
- * @category Blocks.Controller
- * @package Croogo.Blocks.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 RegionsController extends BlocksAppController {
- /**
- * Controller name
- *
- * @var string
- * @access public
- */
- public $name = 'Regions';
- /**
- * Components
- *
- * @var array
- * @access public
- */
- public $components = array(
- 'Search.Prg' => array(
- 'presetForm' => array(
- 'paramType' => 'querystring',
- ),
- 'commonProcess' => array(
- 'paramType' => 'querystring',
- 'filterEmpty' => true,
- ),
- ),
- );
- /**
- * Preset Variables Search
- *
- * @var array
- * @access public
- */
- public $presetVars = true;
- /**
- * Models used by the Controller
- *
- * @var array
- * @access public
- */
- public $uses = array('Blocks.Region');
- /**
- * Admin index
- *
- * @return void
- * @access public
- */
- public function admin_index() {
- $this->set('title_for_layout', __d('croogo', 'Region'));
- $this->Prg->commonProcess();
- $searchFields = array('title');
- $this->Region->recursive = 0;
- $this->paginate['Region']['order'] = 'Region.title ASC';
- $criteria = $this->Region->parseCriteria($this->Prg->parsedParams());
- $this->set('regions', $this->paginate($criteria));
- $this->set('displayFields', $this->Region->displayFields());
- $this->set('searchFields', $searchFields);
- }
- /**
- * Admin add
- *
- * @return void
- * @access public
- */
- public function admin_add() {
- $this->set('title_for_layout', __d('croogo', 'Add Region'));
- if (!empty($this->request->data)) {
- $this->Region->create();
- if ($this->Region->save($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'The Region has been saved'), 'default', array('class' => 'success'));
- return $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__d('croogo', 'The Region 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 Region'));
- if (!$id && empty($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'Invalid Region'), 'default', array('class' => 'error'));
- return $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->request->data)) {
- if ($this->Region->save($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'The Region has been saved'), 'default', array('class' => 'success'));
- return $this->redirect(array('action' => 'index'));
- } else {
- $this->Session->setFlash(__d('croogo', 'The Region could not be saved. Please, try again.'), 'default', array('class' => 'error'));
- }
- }
- if (empty($this->request->data)) {
- $this->request->data = $this->Region->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 Region'), 'default', array('class' => 'error'));
- return $this->redirect(array('action' => 'index'));
- }
- if ($this->Region->delete($id)) {
- $this->Session->setFlash(__d('croogo', 'Region deleted'), 'default', array('class' => 'success'));
- return $this->redirect(array('action' => 'index'));
- }
- }
- }