[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_finder/src/Model/ -> FiltersModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_finder
   6   *
   7   * @copyright   (C) 2011 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\Finder\Administrator\Model;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  15  use Joomla\CMS\MVC\Model\ListModel;
  16  
  17  // phpcs:disable PSR1.Files.SideEffects
  18  \defined('_JEXEC') or die;
  19  // phpcs:enable PSR1.Files.SideEffects
  20  
  21  /**
  22   * Filters model class for Finder.
  23   *
  24   * @since  2.5
  25   */
  26  class FiltersModel extends ListModel
  27  {
  28      /**
  29       * Constructor.
  30       *
  31       * @param   array                $config   An optional associative array of configuration settings.
  32       * @param   MVCFactoryInterface  $factory  The factory.
  33       *
  34       * @see     \Joomla\CMS\MVC\Model\BaseDatabaseModel
  35       * @since   3.7
  36       */
  37      public function __construct($config = array(), MVCFactoryInterface $factory = null)
  38      {
  39          if (empty($config['filter_fields'])) {
  40              $config['filter_fields'] = array(
  41                  'filter_id', 'a.filter_id',
  42                  'title', 'a.title',
  43                  'state', 'a.state',
  44                  'created_by_alias', 'a.created_by_alias',
  45                  'created', 'a.created',
  46                  'map_count', 'a.map_count'
  47              );
  48          }
  49  
  50          parent::__construct($config, $factory);
  51      }
  52  
  53      /**
  54       * Build an SQL query to load the list data.
  55       *
  56       * @return  \Joomla\Database\DatabaseQuery
  57       *
  58       * @since   2.5
  59       */
  60      protected function getListQuery()
  61      {
  62          $db = $this->getDatabase();
  63          $query = $db->getQuery(true);
  64  
  65          // Select all fields from the table.
  66          $query->select('a.*')
  67              ->from($db->quoteName('#__finder_filters', 'a'));
  68  
  69          // Join over the users for the checked out user.
  70          $query->select($db->quoteName('uc.name', 'editor'))
  71              ->join('LEFT', $db->quoteName('#__users', 'uc') . ' ON ' . $db->quoteName('uc.id') . ' = ' . $db->quoteName('a.checked_out'));
  72  
  73          // Join over the users for the author.
  74          $query->select($db->quoteName('ua.name', 'user_name'))
  75              ->join('LEFT', $db->quoteName('#__users', 'ua') . ' ON ' . $db->quoteName('ua.id') . ' = ' . $db->quoteName('a.created_by'));
  76  
  77          // Check for a search filter.
  78          if ($search = $this->getState('filter.search')) {
  79              $search = $db->quote('%' . str_replace(' ', '%', $db->escape(trim($search), true) . '%'));
  80              $query->where($db->quoteName('a.title') . ' LIKE ' . $search);
  81          }
  82  
  83          // If the model is set to check item state, add to the query.
  84          $state = $this->getState('filter.state');
  85  
  86          if (is_numeric($state)) {
  87              $query->where($db->quoteName('a.state') . ' = ' . (int) $state);
  88          }
  89  
  90          // Add the list ordering clause.
  91          $query->order($db->escape($this->getState('list.ordering', 'a.title') . ' ' . $db->escape($this->getState('list.direction', 'ASC'))));
  92  
  93          return $query;
  94      }
  95  
  96      /**
  97       * Method to get a store id based on model configuration state.
  98       *
  99       * This is necessary because the model is used by the component and
 100       * different modules that might need different sets of data or different
 101       * ordering requirements.
 102       *
 103       * @param   string  $id  A prefix for the store id. [optional]
 104       *
 105       * @return  string  A store id.
 106       *
 107       * @since   2.5
 108       */
 109      protected function getStoreId($id = '')
 110      {
 111          // Compile the store id.
 112          $id .= ':' . $this->getState('filter.search');
 113          $id .= ':' . $this->getState('filter.state');
 114  
 115          return parent::getStoreId($id);
 116      }
 117  
 118      /**
 119       * Method to auto-populate the model state.  Calling getState in this method will result in recursion.
 120       *
 121       * @param   string  $ordering   An optional ordering field. [optional]
 122       * @param   string  $direction  An optional direction. [optional]
 123       *
 124       * @return  void
 125       *
 126       * @since   2.5
 127       */
 128      protected function populateState($ordering = 'a.title', $direction = 'asc')
 129      {
 130          // Load the filter state.
 131          $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
 132          $this->setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd'));
 133  
 134          // Load the parameters.
 135          $params = ComponentHelper::getParams('com_finder');
 136          $this->setState('params', $params);
 137  
 138          // List state information.
 139          parent::populateState($ordering, $direction);
 140      }
 141  }


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