/Menus/Controller/MenusController.php
PHP | 140 lines | 63 code | 15 blank | 62 comment | 11 complexity | b370a15a99ecd242b3e3091ed60d505d MD5 | raw file
- <?php
- App::uses('MenusAppController', 'Menus.Controller');
- /**
- * Menus Controller
- *
- * @category Controller
- * @package Croogo.Menus.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 MenusController extends MenusAppController {
- /**
- * Controller name
- *
- * @var string
- * @access public
- */
- public $name = 'Menus';
- /**
- * Models used by the Controller
- *
- * @var array
- * @access public
- */
- public $uses = array('Menus.Menu');
- /**
- * afterConstruct
- */
- public function afterConstruct() {
- parent::afterConstruct();
- $this->_setupAclComponent();
- }
- /**
- * beforeFilter
- *
- */
- public function beforeFilter() {
- parent::beforeFilter();
- $this->Security->unlockedActions[] = 'admin_toggle';
- }
- /**
- * Toggle Link status
- *
- * @param $id string Link id
- * @param $status integer Current Link status
- * @return void
- */
- public function admin_toggle($id = null, $status = null) {
- $this->Croogo->fieldToggle($this->Menu, $id, $status);
- }
- /**
- * Admin index
- *
- * @return void
- * @access public
- */
- public function admin_index() {
- $this->set('title_for_layout', __d('croogo', 'Menus'));
- $this->Menu->recursive = 0;
- $this->paginate['Menu']['order'] = 'Menu.id ASC';
- $this->set('menus', $this->paginate());
- }
- /**
- * Admin add
- *
- * @return void
- * @access public
- */
- public function admin_add() {
- $this->set('title_for_layout', __d('croogo', 'Add Menu'));
- if (!empty($this->request->data)) {
- $this->Menu->create();
- if ($this->Menu->save($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'The Menu has been saved'), 'default', array('class' => 'success'));
- $this->Croogo->redirect(array('action' => 'edit', $this->Menu->id));
- } else {
- $this->Session->setFlash(__d('croogo', 'The Menu 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 Menu'));
- if (!$id && empty($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'Invalid Menu'), 'default', array('class' => 'error'));
- return $this->redirect(array('action' => 'index'));
- }
- if (!empty($this->request->data)) {
- if ($this->Menu->save($this->request->data)) {
- $this->Session->setFlash(__d('croogo', 'The Menu has been saved'), 'default', array('class' => 'success'));
- $this->Croogo->redirect(array('action' => 'edit', $this->Menu->id));
- } else {
- $this->Session->setFlash(__d('croogo', 'The Menu could not be saved. Please, try again.'), 'default', array('class' => 'error'));
- }
- }
- if (empty($this->request->data)) {
- $this->request->data = $this->Menu->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 Menu'), 'default', array('class' => 'error'));
- return $this->redirect(array('action' => 'index'));
- }
- if ($this->Menu->delete($id)) {
- $this->Session->setFlash(__d('croogo', 'Menu deleted'), 'default', array('class' => 'success'));
- return $this->redirect(array('action' => 'index'));
- }
- }
- }