[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/components/com_tags/src/Model/ -> TagsModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_tags
   6   *
   7   * @copyright   (C) 2013 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\Tags\Site\Model;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Helper\ContentHelper;
  16  use Joomla\CMS\MVC\Model\ListModel;
  17  use Joomla\Database\ParameterType;
  18  
  19  // phpcs:disable PSR1.Files.SideEffects
  20  \defined('_JEXEC') or die;
  21  // phpcs:enable PSR1.Files.SideEffects
  22  
  23  /**
  24   * This models supports retrieving a list of tags.
  25   *
  26   * @since  3.1
  27   */
  28  class TagsModel extends ListModel
  29  {
  30      /**
  31       * Model context string.
  32       *
  33       * @var    string
  34       * @since  3.1
  35       */
  36      public $_context = 'com_tags.tags';
  37  
  38      /**
  39       * Method to auto-populate the model state.
  40       *
  41       * @param   string  $ordering   An optional ordering field.
  42       * @param   string  $direction  An optional direction (asc|desc).
  43       *
  44       * @return  void
  45       *
  46       * @note Calling getState in this method will result in recursion.
  47       *
  48       * @since   3.1
  49       */
  50      protected function populateState($ordering = null, $direction = null)
  51      {
  52          $app = Factory::getApplication();
  53  
  54          // Load state from the request.
  55          $pid = $app->input->getInt('parent_id');
  56          $this->setState('tag.parent_id', $pid);
  57  
  58          $language = $app->input->getString('tag_list_language_filter');
  59          $this->setState('tag.language', $language);
  60  
  61          $offset = $app->input->get('limitstart', 0, 'uint');
  62          $this->setState('list.offset', $offset);
  63          $app = Factory::getApplication();
  64  
  65          $params = $app->getParams();
  66          $this->setState('params', $params);
  67  
  68          $this->setState('list.limit', $params->get('maximum', 200));
  69  
  70          $this->setState('filter.published', 1);
  71          $this->setState('filter.access', true);
  72  
  73          $user = Factory::getUser();
  74  
  75          if ((!$user->authorise('core.edit.state', 'com_tags')) &&  (!$user->authorise('core.edit', 'com_tags'))) {
  76              $this->setState('filter.published', 1);
  77          }
  78  
  79          // Optional filter text
  80          $itemid = $pid . ':' . $app->input->getInt('Itemid', 0);
  81          $filterSearch = $app->getUserStateFromRequest('com_tags.tags.list.' . $itemid . '.filter_search', 'filter-search', '', 'string');
  82          $this->setState('list.filter', $filterSearch);
  83      }
  84  
  85      /**
  86       * Method to build an SQL query to load the list data.
  87       *
  88       * @return  string  An SQL query
  89       *
  90       * @since   1.6
  91       */
  92      protected function getListQuery()
  93      {
  94          $app            = Factory::getApplication();
  95          $user           = Factory::getUser();
  96          $groups         = $user->getAuthorisedViewLevels();
  97          $pid            = (int) $this->getState('tag.parent_id');
  98          $orderby        = $this->state->params->get('all_tags_orderby', 'title');
  99          $published      = (int) $this->state->params->get('published', 1);
 100          $orderDirection = $this->state->params->get('all_tags_orderby_direction', 'ASC');
 101          $language       = $this->getState('tag.language');
 102  
 103          // Create a new query object.
 104          $db    = $this->getDatabase();
 105          $query = $db->getQuery(true);
 106  
 107          // Select required fields from the tags.
 108          $query->select('a.*, u.name as created_by_user_name, u.email')
 109              ->from($db->quoteName('#__tags', 'a'))
 110              ->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('a.created_user_id') . ' = ' . $db->quoteName('u.id'))
 111              ->whereIn($db->quoteName('a.access'), $groups);
 112  
 113          if (!empty($pid)) {
 114              $query->where($db->quoteName('a.parent_id') . ' = :pid')
 115                  ->bind(':pid', $pid, ParameterType::INTEGER);
 116          }
 117  
 118          // Exclude the root.
 119          $query->where($db->quoteName('a.parent_id') . ' <> 0');
 120  
 121          // Optionally filter on language
 122          if (empty($language)) {
 123              $language = ComponentHelper::getParams('com_tags')->get('tag_list_language_filter', 'all');
 124          }
 125  
 126          if ($language !== 'all') {
 127              if ($language === 'current_language') {
 128                  $language = ContentHelper::getCurrentLanguage();
 129              }
 130  
 131              $query->whereIn($db->quoteName('language'), [$language, '*'], ParameterType::STRING);
 132          }
 133  
 134          // List state information
 135          $format = $app->input->getWord('format');
 136  
 137          if ($format === 'feed') {
 138              $limit = $app->get('feed_limit');
 139          } else {
 140              if ($this->state->params->get('show_pagination_limit')) {
 141                  $limit = $app->getUserStateFromRequest('global.list.limit', 'limit', $app->get('list_limit'), 'uint');
 142              } else {
 143                  $limit = $this->state->params->get('maximum', 20);
 144              }
 145          }
 146  
 147          $this->setState('list.limit', $limit);
 148  
 149          $offset = $app->input->get('limitstart', 0, 'uint');
 150          $this->setState('list.start', $offset);
 151  
 152          // Optionally filter on entered value
 153          if ($this->state->get('list.filter')) {
 154              $title = '%' . $this->state->get('list.filter') . '%';
 155              $query->where($db->quoteName('a.title') . ' LIKE :title')
 156                  ->bind(':title', $title);
 157          }
 158  
 159          $query->where($db->quoteName('a.published') . ' = :published')
 160              ->bind(':published', $published, ParameterType::INTEGER);
 161  
 162          $query->order($db->quoteName($orderby) . ' ' . $orderDirection . ', a.title ASC');
 163  
 164          return $query;
 165      }
 166  }


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