Source for file plugins.php

Documentation is available at plugins.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Administrator
  4.  * @subpackage  com_plugins
  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.  * Methods supporting a list of plugin records.
  14.  *
  15.  * @package     Joomla.Administrator
  16.  * @subpackage  com_plugins
  17.  * @since       1.6
  18.  */
  19. {
  20.     /**
  21.      * Constructor.
  22.      *
  23.      * @param   array  An optional associative array of configuration settings.
  24.      * @see     JController
  25.      * @since   1.6
  26.      */
  27.     public function __construct($config array())
  28.     {
  29.         if (empty($config['filter_fields']))
  30.         {
  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.      * @param   string  $ordering   An optional ordering field.
  55.      * @param   string  $direction  An optional direction (asc|desc).
  56.      *
  57.      * @return  void 
  58.      *
  59.      * @since   1.6
  60.      */
  61.     protected function populateState($ordering null$direction null)
  62.     {
  63.         // Load the filter state.
  64.         $search $this->getUserStateFromRequest($this->context . '.filter.search''filter_search');
  65.         $this->setState('filter.search'$search);
  66.  
  67.         $accessId $this->getUserStateFromRequest($this->context . '.filter.access''filter_access'null'int');
  68.         $this->setState('filter.access'$accessId);
  69.  
  70.         $state $this->getUserStateFromRequest($this->context . '.filter.enabled''filter_enabled''''string');
  71.         $this->setState('filter.enabled'$state);
  72.  
  73.         $folder $this->getUserStateFromRequest($this->context . '.filter.folder''filter_folder'null'cmd');
  74.         $this->setState('filter.folder'$folder);
  75.  
  76.         $language $this->getUserStateFromRequest($this->context . '.filter.language''filter_language''');
  77.         $this->setState('filter.language'$language);
  78.  
  79.         // Load the parameters.
  80.         $params JComponentHelper::getParams('com_plugins');
  81.         $this->setState('params'$params);
  82.  
  83.         // List state information.
  84.         parent::populateState('folder''asc');
  85.     }
  86.  
  87.     /**
  88.      * Method to get a store id based on model configuration state.
  89.      *
  90.      * This is necessary because the model is used by the component and
  91.      * different modules that might need different sets of data or different
  92.      * ordering requirements.
  93.      *
  94.      * @param   string    A prefix for the store id.
  95.      *
  96.      * @return  string    A store id.
  97.      */
  98.     protected function getStoreId($id '')
  99.     {
  100.         // Compile the store id.
  101.         $id .= ':' $this->getState('filter.search');
  102.         $id .= ':' $this->getState('filter.access');
  103.         $id .= ':' $this->getState('filter.state');
  104.         $id .= ':' $this->getState('filter.folder');
  105.         $id .= ':' $this->getState('filter.language');
  106.  
  107.         return parent::getStoreId($id);
  108.     }
  109.  
  110.     /**
  111.      * Returns an object list
  112.      *
  113.      * @param   string The query
  114.      * @param   int    Offset
  115.      * @param   int    The number of records
  116.      * @return  array 
  117.      */
  118.     protected function _getList($query$limitstart 0$limit 0)
  119.     {
  120.         $search $this->getState('filter.search');
  121.         $ordering $this->getState('list.ordering''ordering');
  122.         if ($ordering == 'name' || (!empty($search&& stripos($search'id:'!== 0))
  123.         {
  124.             $this->_db->setQuery($query);
  125.             $result $this->_db->loadObjectList();
  126.             $this->translate($result);
  127.             if (!empty($search))
  128.             {
  129.                 foreach ($result as $i => $item)
  130.                 {
  131.                     if (!preg_match("/$search/i"$item->name))
  132.                     {
  133.                         unset($result[$i]);
  134.                     }
  135.                 }
  136.             }
  137.  
  138.             $direction ($this->getState('list.direction'== 'desc'? -1;
  139.             JArrayHelper::sortObjects($result$ordering$directiontruetrue);
  140.  
  141.             $total count($result);
  142.             $this->cache[$this->getStoreId('getTotal')$total;
  143.             if ($total $limitstart)
  144.             {
  145.                 $limitstart 0;
  146.                 $this->setState('list.start'0);
  147.             }
  148.             return array_slice($result$limitstart$limit $limit null);
  149.         }
  150.         else
  151.         {
  152.             if ($ordering == 'ordering')
  153.             {
  154.                 $query->order('a.folder ASC');
  155.                 $ordering 'a.ordering';
  156.             }
  157.             $query->order($this->_db->quoteName($ordering' ' $this->getState('list.direction'));
  158.  
  159.             if ($ordering == 'folder')
  160.             {
  161.                 $query->order('a.ordering ASC');
  162.             }
  163.             $result parent::_getList($query$limitstart$limit);
  164.             $this->translate($result);
  165.             return $result;
  166.         }
  167.     }
  168.  
  169.     /**
  170.      * Translate a list of objects
  171.      *
  172.      * @param   array The array of objects
  173.      * @return  array The array of translated objects
  174.      */
  175.     protected function translate(&$items)
  176.     {
  177.         $lang JFactory::getLanguage();
  178.  
  179.         foreach ($items as &$item)
  180.         {
  181.             $source JPATH_PLUGINS '/' $item->folder '/' $item->element;
  182.             $extension 'plg_' $item->folder '_' $item->element;
  183.             $lang->load($extension '.sys'JPATH_ADMINISTRATORnullfalsetrue)
  184.                 || $lang->load($extension '.sys'$sourcenullfalsetrue);
  185.             $item->name JText::_($item->name);
  186.         }
  187.     }
  188.  
  189.     /**
  190.      * Build an SQL query to load the list data.
  191.      *
  192.      * @return  JDatabaseQuery 
  193.      */
  194.     protected function getListQuery()
  195.     {
  196.         // Create a new query object.
  197.         $db $this->getDbo();
  198.         $query $db->getQuery(true);
  199.  
  200.         // Select the required fields from the table.
  201.         $query->select(
  202.             $this->getState(
  203.                 'list.select',
  204.                 'a.extension_id , a.name, a.element, a.folder, a.checked_out, a.checked_out_time,' .
  205.                     ' a.enabled, a.access, a.ordering'
  206.             )
  207.         )
  208.             ->from($db->quoteName('#__extensions'' AS a')
  209.             ->where($db->quoteName('type'' = ' $db->quote('plugin'));
  210.  
  211.         // Join over the users for the checked out user.
  212.         $query->select('uc.name AS editor')
  213.             ->join('LEFT''#__users AS uc ON uc.id=a.checked_out');
  214.  
  215.         // Join over the asset groups.
  216.         $query->select('ag.title AS access_level')
  217.             ->join('LEFT''#__viewlevels AS ag ON ag.id = a.access');
  218.  
  219.         // Filter by access level.
  220.         if ($access $this->getState('filter.access'))
  221.         {
  222.             $query->where('a.access = ' . (int) $access);
  223.         }
  224.  
  225.         // Filter by published state
  226.         $published $this->getState('filter.enabled');
  227.         if (is_numeric($published))
  228.         {
  229.             $query->where('a.enabled = ' . (int) $published);
  230.         }
  231.         elseif ($published === '')
  232.         {
  233.             $query->where('(a.enabled IN (0, 1))');
  234.         }
  235.  
  236.         // Filter by state
  237.         $query->where('a.state >= 0');
  238.  
  239.         // Filter by folder.
  240.         if ($folder $this->getState('filter.folder'))
  241.         {
  242.             $query->where('a.folder = ' $db->quote($folder));
  243.         }
  244.  
  245.         // Filter by search in name or id
  246.         $search $this->getState('filter.search');
  247.         if (!empty($search))
  248.         {
  249.             if (stripos($search'id:'=== 0)
  250.             {
  251.                 $query->where('a.extension_id = ' . (int) substr($search3));
  252.             }
  253.         }
  254.  
  255.         return $query;
  256.     }
  257. }

Documentation generated on Tue, 19 Nov 2013 15:10:51 +0100 by phpDocumentor 1.4.3