[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_modules/models/ -> select.php (source)

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


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1