[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_users/models/ -> debuggroup.php (source)

   1  <?php
   2  /**
   3   * @copyright    Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
   4   * @license        GNU General Public License version 2 or later; see LICENSE.txt
   5   */
   6  
   7  defined('_JEXEC') or die;
   8  
   9  jimport('joomla.application.component.modellist');
  10  require_once JPATH_COMPONENT.'/helpers/debug.php';
  11  
  12  /**
  13   * Methods supporting a list of user records.
  14   *
  15   * @package        Joomla.Administrator
  16   * @subpackage    com_users
  17   * @since        1.6
  18   */
  19  class UsersModelDebugGroup extends JModelList
  20  {
  21      /**
  22       * Get a list of the actions.
  23       *
  24       * @return    array
  25       * @since    1.6
  26       */
  27  	public function getDebugActions()
  28      {
  29          $component = $this->getState('filter.component');
  30  
  31          return UsersHelperDebug::getDebugActions($component);
  32      }
  33  
  34      /**
  35       * Override getItems method.
  36       *
  37       * @return    array
  38       * @since    1.6
  39       */
  40  	public function getItems()
  41      {
  42          $groupId = $this->getState('filter.group_id');
  43  
  44          if (($assets = parent::getItems()) && $groupId) {
  45  
  46              $actions = $this->getDebugActions();
  47  
  48              foreach ($assets as &$asset)
  49              {
  50                  $asset->checks = array();
  51  
  52                  foreach ($actions as $action)
  53                  {
  54                      $name    = $action[0];
  55                      $level    = $action[1];
  56  
  57                      // Check that we check this action for the level of the asset.
  58                      if ($action[1] === null || $action[1] >= $asset->level) {
  59                          // We need to test this action.
  60                          $asset->checks[$name] = JAccess::checkGroup($groupId, $action[0], $asset->name);
  61                      }
  62                      else {
  63                          // We ignore this action.
  64                          $asset->checks[$name] = 'skip';
  65                      }
  66                  }
  67              }
  68          }
  69  
  70          return $assets;
  71      }
  72  
  73      /**
  74       * Method to auto-populate the model state.
  75       *
  76       * Note. Calling getState in this method will result in recursion.
  77       *
  78       * @return    void
  79       * @since    1.6
  80       */
  81  	protected function populateState($ordering = null, $direction = null)
  82      {
  83          // Initialise variables.
  84          $app = JFactory::getApplication('administrator');
  85  
  86          // Adjust the context to support modal layouts.
  87          if ($layout = JRequest::getVar('layout', 'default')) {
  88              $this->context .= '.'.$layout;
  89          }
  90  
  91          // Load the filter state.
  92          $search = $this->getUserStateFromRequest($this->context.'.filter.search', 'filter_search');
  93          $this->setState('filter.search', $search);
  94  
  95          $value = $this->getUserStateFromRequest($this->context.'.filter.group_id', 'group_id', 0, 'int', false);
  96          $this->setState('filter.group_id', $value);
  97  
  98          $levelStart = $this->getUserStateFromRequest($this->context.'.filter.level_start', 'filter_level_start', 0, 'int');
  99          $this->setState('filter.level_start', $levelStart);
 100  
 101          $value = $this->getUserStateFromRequest($this->context.'.filter.level_end', 'filter_level_end', 0, 'int');
 102          if ($value > 0 && $value < $levelStart) {
 103              $value = $levelStart;
 104          }
 105          $this->setState('filter.level_end', $value);
 106  
 107          $component = $this->getUserStateFromRequest($this->context.'.filter.component', 'filter_component');
 108          $this->setState('filter.component', $component);
 109  
 110          // Load the parameters.
 111          $params        = JComponentHelper::getParams('com_users');
 112          $this->setState('params', $params);
 113  
 114          // List state information.
 115          parent::populateState('a.lft', 'asc');
 116      }
 117  
 118      /**
 119       * Method to get a store id based on model configuration state.
 120       *
 121       * This is necessary because the model is used by the component and
 122       * different modules that might need different sets of data or different
 123       * ordering requirements.
 124       *
 125       * @param    string        $id    A prefix for the store id.
 126       *
 127       * @return    string        A store id.
 128       * @since    1.6
 129       */
 130  	protected function getStoreId($id = '')
 131      {
 132          // Compile the store id.
 133          $id    .= ':'.$this->getState('filter.search');
 134          $id    .= ':'.$this->getState('filter.level_start');
 135          $id    .= ':'.$this->getState('filter.level_end');
 136          $id    .= ':'.$this->getState('filter.component');
 137  
 138          return parent::getStoreId($id);
 139      }
 140  
 141      /**
 142       * Get the group being debugged.
 143       *
 144       * @return    JObject
 145       * @since    1.6
 146       */
 147  	public function getGroup()
 148      {
 149          $groupId = (int) $this->getState('filter.group_id');
 150  
 151          $db = $this->getDbo();
 152          $query    = $db->getQuery(true)
 153              ->select('id, title')
 154              ->from('#__usergroups')
 155              ->where('id = '.$groupId);
 156  
 157          $db->setQuery($query);
 158          $group = $db->loadObject();
 159  
 160          // Check for DB error.
 161          $error    = $db->getErrorMsg();
 162          if ($error) {
 163              $this->setError($error);
 164  
 165              return false;
 166          }
 167  
 168          return $group;
 169      }
 170  
 171      /**
 172       * Build an SQL query to load the list data.
 173       *
 174       * @return    JDatabaseQuery
 175       * @since    1.6
 176       */
 177  	protected function getListQuery()
 178      {
 179          // Create a new query object.
 180          $db        = $this->getDbo();
 181          $query    = $db->getQuery(true);
 182  
 183          // Select the required fields from the table.
 184          $query->select(
 185              $this->getState(
 186                  'list.select',
 187                  'a.id, a.name, a.title, a.level, a.lft, a.rgt'
 188              )
 189          );
 190          $query->from($db->quoteName('#__assets').' AS a');
 191  
 192          // Filter the items over the search string if set.
 193          if ($this->getState('filter.search')) {
 194              // Escape the search token.
 195              $token    = $db->Quote('%'.$db->escape($this->getState('filter.search')).'%');
 196  
 197              // Compile the different search clauses.
 198              $searches    = array();
 199              $searches[]    = 'a.name LIKE '.$token;
 200              $searches[]    = 'a.title LIKE '.$token;
 201  
 202              // Add the clauses to the query.
 203              $query->where('('.implode(' OR ', $searches).')');
 204          }
 205  
 206          // Filter on the start and end levels.
 207          $levelStart    = (int) $this->getState('filter.level_start');
 208          $levelEnd    = (int) $this->getState('filter.level_end');
 209          if ($levelEnd > 0 && $levelEnd < $levelStart) {
 210              $levelEnd = $levelStart;
 211          }
 212          if ($levelStart > 0) {
 213              $query->where('a.level >= '.$levelStart);
 214          }
 215          if ($levelEnd > 0) {
 216              $query->where('a.level <= '.$levelEnd);
 217          }
 218  
 219          // Filter the items over the component if set.
 220          if ($this->getState('filter.component')) {
 221              $component = $this->getState('filter.component');
 222              $query->where('(a.name = '.$db->quote($component).' OR a.name LIKE '.$db->quote($component.'.%').')');
 223          }
 224  
 225          // Add the list ordering clause.
 226          $query->order($db->escape($this->getState('list.ordering', 'a.lft')).' '.$db->escape($this->getState('list.direction', 'ASC')));
 227  
 228          return $query;
 229      }
 230  }


Generated: Tue Apr 3 11:40:28 2012 Cross-referenced by PHPXref 0.7.1