Source for file menu.php

Documentation is available at menu.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_menus
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE.txt
  8.  */
  9.  
  10. defined('_JEXEC') or die;
  11.  
  12. /**
  13.  * The Menu Type Controller
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_menus
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Dummy method to redirect back to standard controller
  22.      *
  23.      * @param   boolean            If true, the view output will be cached
  24.      * @param   array  An array of safe url parameters and their variable types, for valid values see {@link JFilterInput::clean()}.
  25.      *
  26.      * @return  JController        This object to support chaining.
  27.      * @since   1.5
  28.      */
  29.     public function display($cachable = false, $urlparams = false)
  30.     {
  31.         $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
  32.     }
  33.  
  34.     /**
  35.      * Method to save a menu item.
  36.      *
  37.      * @return  void 
  38.      */
  39.     public function save($key = null, $urlVar = null)
  40.     {
  41.         // Check for request forgeries.
  42.         JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
  43.  
  44.         $app      = JFactory::getApplication();
  45.         $data     = $this->input->post->get('jform', array(), 'array');
  46.         $context  = 'com_menus.edit.menu';
  47.         $task     = $this->getTask();
  48.         $recordId = $this->input->getInt('id');
  49.  
  50.         // Make sure we are not trying to modify an administrator menu.
  51.         if (isset($data['client_id']) && $data['client_id'] == 1){
  52.             JError::raiseNotice(0, JText::_('COM_MENUS_MENU_TYPE_NOT_ALLOWED'));
  53.  
  54.             // Redirect back to the edit screen.
  55.             $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
  56.  
  57.             return false;
  58.         }
  59.  
  60.         // Populate the row id from the session.
  61.         $data['id'] = $recordId;
  62.  
  63.         // Get the model and attempt to validate the posted data.
  64.         $model    = $this->getModel('Menu');
  65.         $form    = $model->getForm();
  66.         if (!$form)
  67.         {
  68.             JError::raiseError(500, $model->getError());
  69.  
  70.             return false;
  71.         }
  72.  
  73.         $data    = $model->validate($form, $data);
  74.  
  75.         // Check for validation errors.
  76.         if ($data === false)
  77.         {
  78.             // Get the validation messages.
  79.             $errors    = $model->getErrors();
  80.  
  81.             // Push up to three validation messages out to the user.
  82.             for ($i = 0, $n = count($errors); $i < $n && $i < 3; $i++)
  83.             {
  84.                 if ($errors[$i] instanceof Exception)
  85.                 {
  86.                     $app->enqueueMessage($errors[$i]->getMessage(), 'warning');
  87.                 }
  88.                 else {
  89.                     $app->enqueueMessage($errors[$i], 'warning');
  90.                 }
  91.             }
  92.             // Save the data in the session.
  93.             $app->setUserState('com_menus.edit.menu.data', $data);
  94.  
  95.             // Redirect back to the edit screen.
  96.             $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
  97.  
  98.             return false;
  99.         }
  100.  
  101.         // Attempt to save the data.
  102.         if (!$model->save($data))
  103.         {
  104.             // Save the data in the session.
  105.             $app->setUserState('com_menus.edit.menu.data', $data);
  106.  
  107.             // Redirect back to the edit screen.
  108.             $this->setMessage(JText::sprintf('JLIB_APPLICATION_ERROR_SAVE_FAILED', $model->getError()), 'warning');
  109.             $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
  110.  
  111.             return false;
  112.         }
  113.  
  114.         $this->setMessage(JText::_('COM_MENUS_MENU_SAVE_SUCCESS'));
  115.  
  116.         // Redirect the user and adjust session state based on the chosen task.
  117.         switch ($task)
  118.         {
  119.             case 'apply':
  120.                 // Set the record data in the session.
  121.                 $recordId = $model->getState($this->context.'.id');
  122.                 $this->holdEditId($context, $recordId);
  123.  
  124.                 // Redirect back to the edit screen.
  125.                 $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit'.$this->getRedirectToItemAppend($recordId), false));
  126.                 break;
  127.  
  128.             case 'save2new':
  129.                 // Clear the record id and data from the session.
  130.                 $this->releaseEditId($context, $recordId);
  131.                 $app->setUserState($context.'.data', null);
  132.  
  133.                 // Redirect back to the edit screen.
  134.                 $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menu&layout=edit', false));
  135.                 break;
  136.  
  137.             default:
  138.                 // Clear the record id and data from the session.
  139.                 $this->releaseEditId($context, $recordId);
  140.                 $app->setUserState($context.'.data', null);
  141.  
  142.                 // Redirect to the list screen.
  143.                 $this->setRedirect(JRoute::_('index.php?option=com_menus&view=menus', false));
  144.                 break;
  145.         }
  146.     }
  147. }

Documentation generated on Tue, 19 Nov 2013 15:07:49 +0100 by phpDocumentor 1.4.3