Source for file select.php

Documentation is available at select.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 model.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_modules
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Method to auto-populate the model state.
  22.      *
  23.      * Note. Calling getState in this method will result in recursion.
  24.      *
  25.      * @since   1.6
  26.      */
  27.     protected function populateState($ordering null$direction null)
  28.     {
  29.         $app JFactory::getApplication('administrator');
  30.  
  31.         // Load the filter state.
  32.         $clientId $app->getUserState('com_modules.modules.filter.client_id'0);
  33.         $this->setState('filter.client_id'(int) $clientId);
  34.  
  35.         // Load the parameters.
  36.         $params JComponentHelper::getParams('com_modules');
  37.         $this->setState('params'$params);
  38.  
  39.         // Manually set limits to get all modules.
  40.         $this->setState('list.limit'0);
  41.         $this->setState('list.start'0);
  42.         $this->setState('list.ordering''a.name');
  43.         $this->setState('list.direction''ASC');
  44.     }
  45.  
  46.     /**
  47.      * Method to get a store id based on model configuration state.
  48.      *
  49.      * This is necessary because the model is used by the component and
  50.      * different modules that might need different sets of data or different
  51.      * ordering requirements.
  52.      *
  53.      * @param   string    A prefix for the store id.
  54.      *
  55.      * @return  string    A store id.
  56.      */
  57.     protected function getStoreId($id '')
  58.     {
  59.         // Compile the store id.
  60.         $id .= ':' $this->getState('filter.client_id');
  61.  
  62.         return parent::getStoreId($id);
  63.     }
  64.  
  65.     /**
  66.      * Build an SQL query to load the list data.
  67.      *
  68.      * @return  JDatabaseQuery 
  69.      */
  70.     protected function getListQuery()
  71.     {
  72.         // Create a new query object.
  73.         $db $this->getDbo();
  74.         $query $db->getQuery(true);
  75.  
  76.         // Select the required fields from the table.
  77.         $query->select(
  78.             $this->getState(
  79.                 'list.select',
  80.                 'a.extension_id, a.name, a.element AS module'
  81.             )
  82.         );
  83.         $query->from($db->quoteName('#__extensions'' AS a');
  84.  
  85.         // Filter by module
  86.         $query->where('a.type = ' $db->quote('module'));
  87.  
  88.         // Filter by client.
  89.         $clientId $this->getState('filter.client_id');
  90.         $query->where('a.client_id = ' . (int) $clientId);
  91.  
  92.         // Filter by enabled
  93.         $query->where('a.enabled = 1');
  94.  
  95.         // Add the list ordering clause.
  96.         $query->order($db->escape($this->getState('list.ordering''a.ordering')) ' ' $db->escape($this->getState('list.direction''ASC')));
  97.  
  98.         //echo nl2br(str_replace('#__','jos_',$query));
  99.         return $query;
  100.     }
  101.  
  102.     /**
  103.      * Method to get a list of items.
  104.      *
  105.      * @return  mixed  An array of objects on success, false on failure.
  106.      */
  107.     public function getItems()
  108.     {
  109.         // Get the list of items from the database.
  110.         $items parent::getItems();
  111.  
  112.         $client JApplicationHelper::getClientInfo($this->getState('filter.client_id'0));
  113.         $lang JFactory::getLanguage();
  114.  
  115.         // Loop through the results to add the XML metadata,
  116.         // and load language support.
  117.         foreach ($items as &$item)
  118.         {
  119.             $path JPath::clean($client->path '/modules/' $item->module '/' $item->module '.xml');
  120.             if (file_exists($path))
  121.             {
  122.                 $item->xml simplexml_load_file($path);
  123.             }
  124.             else
  125.             {
  126.                 $item->xml null;
  127.             }
  128.  
  129.             // 1.5 Format; Core files or language packs then
  130.             // 1.6 3PD Extension Support
  131.             $lang->load($item->module '.sys'$client->pathnullfalsetrue)
  132.                 || $lang->load($item->module '.sys'$client->path '/modules/' $item->modulenullfalsetrue);
  133.             $item->name JText::_($item->name);
  134.  
  135.             if (isset($item->xml&& $text trim($item->xml->description))
  136.             {
  137.                 $item->desc JText::_($text);
  138.             }
  139.             else
  140.             {
  141.                 $item->desc JText::_('COM_MODULES_NODESCRIPTION');
  142.             }
  143.         }
  144.         $items JArrayHelper::sortObjects($items'name'1truetrue);
  145.  
  146.         // TODO: Use the cached XML from the extensions table?
  147.  
  148.         return $items;
  149.     }
  150. }

Documentation generated on Tue, 19 Nov 2013 15:12:48 +0100 by phpDocumentor 1.4.3