Source for file module.php

Documentation is available at module.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_modules
  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.  * Module controller class.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_modules
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Override parent add method.
  22.      *
  23.      * @return  mixed  True if the record can be added, a JError object if not.
  24.      *
  25.      * @since   1.6
  26.      */
  27.     public function add()
  28.     {
  29.         $app JFactory::getApplication();
  30.  
  31.         // Get the result of the parent method. If an error, just return it.
  32.         $result parent::add();
  33.         if ($result instanceof Exception)
  34.         {
  35.             return $result;
  36.         }
  37.  
  38.         // Look for the Extension ID.
  39.         $extensionId $app->input->get('eid'0'int');
  40.         if (empty($extensionId))
  41.         {
  42.             $this->setRedirect(JRoute::_('index.php?option='.$this->option.'&view='.$this->view_item.'&layout=edit'false));
  43.             return JError::raiseWarning(500JText::_('COM_MODULES_ERROR_INVALID_EXTENSION'));
  44.         }
  45.  
  46.         $app->setUserState('com_modules.add.module.extension_id'$extensionId);
  47.         $app->setUserState('com_modules.add.module.params'null);
  48.  
  49.         // Parameters could be coming in for a new item, so let's set them.
  50.         $params $app->input->get('params'array()'array');
  51.         $app->setUserState('com_modules.add.module.params'$params);
  52.     }
  53.  
  54.     /**
  55.      * Override parent cancel method to reset the add module state.
  56.      *
  57.      * @param   string  $key  The name of the primary key of the URL variable.
  58.      *
  59.      * @return  boolean  True if access level checks pass, false otherwise.
  60.      *
  61.      * @since   1.6
  62.      */
  63.     public function cancel($key null)
  64.     {
  65.         $app JFactory::getApplication();
  66.  
  67.         $result parent::cancel();
  68.  
  69.         $app->setUserState('com_modules.add.module.extension_id'null);
  70.         $app->setUserState('com_modules.add.module.params'null);
  71.  
  72.         return $result;
  73.     }
  74.  
  75.     /**
  76.      * Override parent allowSave method.
  77.      *
  78.      * @param   array   $data  An array of input data.
  79.      * @param   string  $key   The name of the key for the primary key.
  80.      *
  81.      * @return  boolean 
  82.      *
  83.      * @since   1.6
  84.      */
  85.     protected function allowSave($data$key 'id')
  86.     {
  87.         // use custom position if selected
  88.         if (isset($data['custom_position']))
  89.         {
  90.             if (empty($data['position']))
  91.             {
  92.                 $data['position'$data['custom_position'];
  93.             }
  94.  
  95.             unset($data['custom_position']);
  96.         }
  97.  
  98.         return parent::allowSave($data$key);
  99.     }
  100.  
  101.     /**
  102.      * Method override to check if you can edit an existing record.
  103.      *
  104.      * @param   array   $data  An array of input data.
  105.      * @param   string  $key   The name of the key for the primary key.
  106.      *
  107.      * @return  boolean 
  108.      *
  109.      * @since   3.2
  110.      */
  111.     protected function allowEdit($data array()$key 'id')
  112.     {
  113.         // Initialise variables.
  114.         $recordId = (int) isset($data[$key]$data[$key0;
  115.         $user JFactory::getUser();
  116.         $userId $user->get('id');
  117.  
  118.         // Check general edit permission first.
  119.         if ($user->authorise('core.edit''com_modules.module.' $recordId))
  120.         {
  121.             return true;
  122.         }
  123.  
  124.         // Since there is no asset tracking, revert to the component permissions.
  125.         return parent::allowEdit($data$key);
  126.     }
  127.  
  128.     /**
  129.      * Method to run batch operations.
  130.      *
  131.      * @param   string  $model  The model
  132.      *
  133.      * @return  boolean  True on success.
  134.      *
  135.      * @since   1.7
  136.      */
  137.     public function batch($model null)
  138.     {
  139.         JSession::checkToken(or jexit(JText::_('JINVALID_TOKEN'));
  140.  
  141.         // Set the model
  142.         $model    $this->getModel('Module'''array());
  143.  
  144.         // Preset the redirect
  145.         $this->setRedirect(JRoute::_('index.php?option=com_modules&view=modules'.$this->getRedirectToListAppend()false));
  146.  
  147.         return parent::batch($model);
  148.     }
  149.  
  150.     /**
  151.      * Function that allows child controller access to model data after the data has been saved.
  152.      *
  153.      * @param   JModelLegacy  $model      The data model object.
  154.      * @param   array         $validData  The validated data.
  155.      *
  156.      * @return  void 
  157.      *
  158.      * @since   1.6
  159.      */
  160.     protected function postSaveHook(JModelLegacy $model$validData array())
  161.     {
  162.         $app JFactory::getApplication();
  163.         $task $this->getTask();
  164.  
  165.         switch ($task)
  166.         {
  167.             case 'save2new':
  168.                 $app->setUserState('com_modules.add.module.extension_id'$model->getState('module.extension_id'));
  169.                 break;
  170.  
  171.             default:
  172.                 $app->setUserState('com_modules.add.module.extension_id'null);
  173.                 break;
  174.         }
  175.  
  176.         $app->setUserState('com_modules.add.module.params'null);
  177.     }
  178. }

Documentation generated on Tue, 19 Nov 2013 15:08:43 +0100 by phpDocumentor 1.4.3