[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_modules/src/Model/ -> SelectModel.php (source)

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


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer