[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

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


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