[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Model/ -> DebuguserModel.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2010 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\Users\Administrator\Model;
  12  
  13  use Joomla\CMS\Component\ComponentHelper;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  16  use Joomla\CMS\MVC\Model\ListModel;
  17  use Joomla\CMS\User\User;
  18  use Joomla\Component\Users\Administrator\Helper\DebugHelper;
  19  use Joomla\Database\DatabaseQuery;
  20  use Joomla\Database\ParameterType;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Methods supporting a list of User ACL permissions
  28   *
  29   * @since  1.6
  30   */
  31  class DebuguserModel extends ListModel
  32  {
  33      /**
  34       * Constructor.
  35       *
  36       * @param   array                $config   An optional associative array of configuration settings.
  37       * @param   MVCFactoryInterface  $factory  The factory.
  38       *
  39       * @see     \Joomla\CMS\MVC\Model\BaseDatabaseModel
  40       * @since   3.2
  41       */
  42      public function __construct($config = array(), MVCFactoryInterface $factory = null)
  43      {
  44          if (empty($config['filter_fields'])) {
  45              $config['filter_fields'] = array(
  46                  'a.title',
  47                  'component', 'a.name',
  48                  'a.lft',
  49                  'a.id',
  50                  'level_start', 'level_end', 'a.level',
  51              );
  52          }
  53  
  54          parent::__construct($config, $factory);
  55      }
  56  
  57      /**
  58       * Get a list of the actions.
  59       *
  60       * @return  array
  61       *
  62       * @since   1.6
  63       */
  64      public function getDebugActions()
  65      {
  66          $component = $this->getState('filter.component');
  67  
  68          return DebugHelper::getDebugActions($component);
  69      }
  70  
  71      /**
  72       * Override getItems method.
  73       *
  74       * @return  array
  75       *
  76       * @since   1.6
  77       */
  78      public function getItems()
  79      {
  80          $userId = $this->getState('user_id');
  81          $user   = Factory::getUser($userId);
  82  
  83          if (($assets = parent::getItems()) && $userId) {
  84              $actions = $this->getDebugActions();
  85  
  86              foreach ($assets as &$asset) {
  87                  $asset->checks = array();
  88  
  89                  foreach ($actions as $action) {
  90                      $name = $action[0];
  91                      $asset->checks[$name] = $user->authorise($name, $asset->name);
  92                  }
  93              }
  94          }
  95  
  96          return $assets;
  97      }
  98  
  99      /**
 100       * Method to auto-populate the model state.
 101       *
 102       * Note. Calling getState in this method will result in recursion.
 103       *
 104       * @param   string  $ordering   An optional ordering field.
 105       * @param   string  $direction  An optional direction (asc|desc).
 106       *
 107       * @return  void
 108       *
 109       * @since   1.6
 110       * @throws  \Exception
 111       */
 112      protected function populateState($ordering = 'a.lft', $direction = 'asc')
 113      {
 114          $app = Factory::getApplication();
 115  
 116          // Adjust the context to support modal layouts.
 117          $layout = $app->input->get('layout', 'default');
 118  
 119          if ($layout) {
 120              $this->context .= '.' . $layout;
 121          }
 122  
 123          // Load the filter state.
 124          $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
 125          $this->setState('user_id', $this->getUserStateFromRequest($this->context . '.user_id', 'user_id', 0, 'int', false));
 126  
 127          $levelStart = $this->getUserStateFromRequest($this->context . '.filter.level_start', 'filter_level_start', '', 'cmd');
 128          $this->setState('filter.level_start', $levelStart);
 129  
 130          $value = $this->getUserStateFromRequest($this->context . '.filter.level_end', 'filter_level_end', '', 'cmd');
 131  
 132          if ($value > 0 && $value < $levelStart) {
 133              $value = $levelStart;
 134          }
 135  
 136          $this->setState('filter.level_end', $value);
 137  
 138          $this->setState('filter.component', $this->getUserStateFromRequest($this->context . '.filter.component', 'filter_component', '', 'string'));
 139  
 140          // Load the parameters.
 141          $params = ComponentHelper::getParams('com_users');
 142          $this->setState('params', $params);
 143  
 144          // List state information.
 145          parent::populateState($ordering, $direction);
 146      }
 147  
 148      /**
 149       * Method to get a store id based on model configuration state.
 150       *
 151       * This is necessary because the model is used by the component and
 152       * different modules that might need different sets of data or different
 153       * ordering requirements.
 154       *
 155       * @param   string  $id  A prefix for the store id.
 156       *
 157       * @return  string  A store id.
 158       */
 159      protected function getStoreId($id = '')
 160      {
 161          // Compile the store id.
 162          $id .= ':' . $this->getState('user_id');
 163          $id .= ':' . $this->getState('filter.search');
 164          $id .= ':' . $this->getState('filter.level_start');
 165          $id .= ':' . $this->getState('filter.level_end');
 166          $id .= ':' . $this->getState('filter.component');
 167  
 168          return parent::getStoreId($id);
 169      }
 170  
 171      /**
 172       * Get the user being debugged.
 173       *
 174       * @return  User
 175       *
 176       * @since   1.6
 177       */
 178      public function getUser()
 179      {
 180          $userId = $this->getState('user_id');
 181  
 182          return Factory::getUser($userId);
 183      }
 184  
 185      /**
 186       * Build an SQL query to load the list data.
 187       *
 188       * @return  DatabaseQuery
 189       *
 190       * @since   1.6
 191       */
 192      protected function getListQuery()
 193      {
 194          // Create a new query object.
 195          $db = $this->getDatabase();
 196          $query = $db->getQuery(true);
 197  
 198          // Select the required fields from the table.
 199          $query->select(
 200              $this->getState(
 201                  'list.select',
 202                  'a.id, a.name, a.title, a.level, a.lft, a.rgt'
 203              )
 204          );
 205          $query->from($db->quoteName('#__assets', 'a'));
 206  
 207          // Filter the items over the search string if set.
 208          if ($this->getState('filter.search')) {
 209              $search = '%' . trim($this->getState('filter.search')) . '%';
 210  
 211              // Add the clauses to the query.
 212              $query->where(
 213                  '(' . $db->quoteName('a.name') . ' LIKE :name'
 214                  . ' OR ' . $db->quoteName('a.title') . ' LIKE :title)'
 215              )
 216                  ->bind(':name', $search)
 217                  ->bind(':title', $search);
 218          }
 219  
 220          // Filter on the start and end levels.
 221          $levelStart = (int) $this->getState('filter.level_start');
 222          $levelEnd = (int) $this->getState('filter.level_end');
 223  
 224          if ($levelEnd > 0 && $levelEnd < $levelStart) {
 225              $levelEnd = $levelStart;
 226          }
 227  
 228          if ($levelStart > 0) {
 229              $query->where($db->quoteName('a.level') . ' >= :levelStart')
 230                  ->bind(':levelStart', $levelStart, ParameterType::INTEGER);
 231          }
 232  
 233          if ($levelEnd > 0) {
 234              $query->where($db->quoteName('a.level') . ' <= :levelEnd')
 235                  ->bind(':levelEnd', $levelEnd, ParameterType::INTEGER);
 236          }
 237  
 238          // Filter the items over the component if set.
 239          if ($this->getState('filter.component')) {
 240              $component  = $this->getState('filter.component');
 241              $lcomponent = $component . '.%';
 242              $query->where(
 243                  '(' . $db->quoteName('a.name') . ' = :component'
 244                  . ' OR ' . $db->quoteName('a.name') . ' LIKE :lcomponent)'
 245              )
 246                  ->bind(':component', $component)
 247                  ->bind(':lcomponent', $lcomponent);
 248          }
 249  
 250          // Add the list ordering clause.
 251          $query->order($db->escape($this->getState('list.ordering', 'a.lft')) . ' ' . $db->escape($this->getState('list.direction', 'ASC')));
 252  
 253          return $query;
 254      }
 255  }


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