[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_plugins/models/ -> plugins.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  // No direct access.
   8  defined('_JEXEC') or die;
   9  
  10  jimport('joomla.application.component.modellist');
  11  
  12  /**
  13   * Methods supporting a list of plugin records.
  14   *
  15   * @package        Joomla.Administrator
  16   * @subpackage    com_plugins
  17   * @since        1.6
  18   */
  19  class PluginsModelPlugins extends JModelList
  20  {
  21      /**
  22       * Constructor.
  23       *
  24       * @param    array    An optional associative array of configuration settings.
  25       * @see        JController
  26       * @since    1.6
  27       */
  28  	public function __construct($config = array())
  29      {
  30          if (empty($config['filter_fields'])) {
  31              $config['filter_fields'] = array(
  32                  'extension_id', 'a.extension_id',
  33                  'name', 'a.name',
  34                  'folder', 'a.folder',
  35                  'element', 'a.element',
  36                  'checked_out', 'a.checked_out',
  37                  'checked_out_time', 'a.checked_out_time',
  38                  'state', 'a.state',
  39                  'enabled', 'a.enabled',
  40                  'access', 'a.access', 'access_level',
  41                  'ordering', 'a.ordering',
  42                  'client_id', 'a.client_id',
  43              );
  44          }
  45  
  46          parent::__construct($config);
  47      }
  48  
  49      /**
  50       * Method to auto-populate the model state.
  51       *
  52       * Note. Calling getState in this method will result in recursion.
  53       *
  54       * @since    1.6
  55       */
  56  	protected function populateState($ordering = null, $direction = null)
  57      {
  58          // Initialise variables.
  59          $app = JFactory::getApplication('administrator');
  60  
  61          // Load the filter state.
  62          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  63          $this->setState('filter.search', $search);
  64  
  65          $accessId = $this->getUserStateFromRequest($this->context.'.filter.access', 'filter_access', null, 'int');
  66          $this->setState('filter.access', $accessId);
  67  
  68          $state = $this->getUserStateFromRequest($this->context.'.filter.state', 'filter_state', '', 'string');
  69          $this->setState('filter.state', $state);
  70  
  71          $folder = $this->getUserStateFromRequest($this->context.'.filter.folder', 'filter_folder', null, 'cmd');
  72          $this->setState('filter.folder', $folder);
  73  
  74          $language = $this->getUserStateFromRequest($this->context.'.filter.language', 'filter_language', '');
  75          $this->setState('filter.language', $language);
  76  
  77          // Load the parameters.
  78          $params = JComponentHelper::getParams('com_plugins');
  79          $this->setState('params', $params);
  80  
  81          // List state information.
  82          parent::populateState('folder', 'asc');
  83      }
  84  
  85      /**
  86       * Method to get a store id based on model configuration state.
  87       *
  88       * This is necessary because the model is used by the component and
  89       * different modules that might need different sets of data or different
  90       * ordering requirements.
  91       *
  92       * @param    string    A prefix for the store id.
  93       *
  94       * @return    string    A store id.
  95       */
  96  	protected function getStoreId($id = '')
  97      {
  98          // Compile the store id.
  99          $id    .= ':'.$this->getState('filter.search');
 100          $id    .= ':'.$this->getState('filter.access');
 101          $id    .= ':'.$this->getState('filter.state');
 102          $id    .= ':'.$this->getState('filter.folder');
 103          $id    .= ':'.$this->getState('filter.language');
 104  
 105          return parent::getStoreId($id);
 106      }
 107  
 108      /**
 109       * Returns an object list
 110       *
 111       * @param    string The query
 112       * @param    int Offset
 113       * @param    int The number of records
 114       * @return    array
 115       */
 116  	protected function _getList($query, $limitstart=0, $limit=0)
 117      {
 118          $search = $this->getState('filter.search');
 119          $ordering = $this->getState('list.ordering', 'ordering');
 120          if ($ordering == 'name' || (!empty($search) && stripos($search, 'id:') !== 0)) {
 121              $this->_db->setQuery($query);
 122              $result = $this->_db->loadObjectList();
 123              $this->translate($result);
 124              if (!empty($search)) {
 125                  foreach($result as $i=>$item) {
 126                      if (!preg_match("/$search/i", $item->name)) {
 127                          unset($result[$i]);
 128                      }
 129                  }
 130              }
 131              $lang = JFactory::getLanguage();
 132              JArrayHelper::sortObjects($result, 'name', $this->getState('list.direction') == 'desc' ? -1 : 1, true, $lang->getLocale());
 133              $total = count($result);
 134              $this->cache[$this->getStoreId('getTotal')] = $total;
 135              if ($total < $limitstart) {
 136                  $limitstart = 0;
 137                  $this->setState('list.start', 0);
 138              }
 139              return array_slice($result, $limitstart, $limit ? $limit : null);
 140          }
 141          else {
 142              if ($ordering == 'ordering') {
 143                  $query->order('a.folder ASC');
 144                  $ordering = 'a.ordering';
 145              }
 146              $query->order($this->_db->quoteName($ordering) . ' ' . $this->getState('list.direction'));
 147              if($ordering == 'folder') {
 148                  $query->order('a.ordering ASC');
 149              }
 150              $result = parent::_getList($query, $limitstart, $limit);
 151              $this->translate($result);
 152              return $result;
 153          }
 154      }
 155  
 156      /**
 157       * Translate a list of objects
 158       *
 159       * @param    array The array of objects
 160       * @return    array The array of translated objects
 161       */
 162  	protected function translate(&$items)
 163      {
 164          $lang = JFactory::getLanguage();
 165          foreach($items as &$item) {
 166              $source = JPATH_PLUGINS . '/' . $item->folder . '/' . $item->element;
 167              $extension = 'plg_' . $item->folder . '_' . $item->element;
 168                  $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, null, false, false)
 169              ||    $lang->load($extension . '.sys', $source, null, false, false)
 170              ||    $lang->load($extension . '.sys', JPATH_ADMINISTRATOR, $lang->getDefault(), false, false)
 171              ||    $lang->load($extension . '.sys', $source, $lang->getDefault(), false, false);
 172              $item->name = JText::_($item->name);
 173          }
 174      }
 175      /**
 176       * Build an SQL query to load the list data.
 177       *
 178       * @return    JDatabaseQuery
 179       */
 180  	protected function getListQuery()
 181      {
 182          // Create a new query object.
 183          $db        = $this->getDbo();
 184          $query    = $db->getQuery(true);
 185  
 186          // Select the required fields from the table.
 187          $query->select(
 188              $this->getState(
 189                  'list.select',
 190                  'a.extension_id , a.name, a.element, a.folder, a.checked_out, a.checked_out_time,' .
 191                  ' a.enabled, a.access, a.ordering'
 192              )
 193          );
 194          $query->from($db->quoteName('#__extensions').' AS a');
 195  
 196          $query->where($db->quoteName('type').' = '.$db->quote('plugin'));
 197  
 198          // Join over the users for the checked out user.
 199          $query->select('uc.name AS editor');
 200          $query->join('LEFT', '#__users AS uc ON uc.id=a.checked_out');
 201  
 202          // Join over the asset groups.
 203          $query->select('ag.title AS access_level');
 204          $query->join('LEFT', '#__viewlevels AS ag ON ag.id = a.access');
 205  
 206          // Filter by access level.
 207          if ($access = $this->getState('filter.access')) {
 208              $query->where('a.access = '.(int) $access);
 209          }
 210  
 211          // Filter by published state
 212          $published = $this->getState('filter.state');
 213          if (is_numeric($published)) {
 214              $query->where('a.enabled = '.(int) $published);
 215          } elseif ($published === '') {
 216              $query->where('(a.enabled IN (0, 1))');
 217          }
 218  
 219          // Filter by state
 220          $query->where('a.state >= 0');
 221  
 222          // Filter by folder.
 223          if ($folder = $this->getState('filter.folder')) {
 224              $query->where('a.folder = '.$db->quote($folder));
 225          }
 226  
 227          // Filter by search in id
 228          $search = $this->getState('filter.search');
 229          if (!empty($search) && stripos($search, 'id:') === 0) {
 230                  $query->where('a.extension_id = '.(int) substr($search, 3));
 231          }
 232  
 233          return $query;
 234      }
 235  }


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