[ Index ]

PHP Cross Reference of Joomla 2.5.4 DE

title

Body

[close]

/administrator/components/com_users/models/ -> debuguser.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 UsersModelDebugUser 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          $userId = $this->getState('filter.user_id');
  43  
  44          if (($assets = parent::getItems()) && $userId) {
  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::check($userId, $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.user_id', 'user_id', 0, 'int');
  96          $this->setState('filter.user_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.user_id');
 135          $id    .= ':'.$this->getState('filter.level_start');
 136          $id    .= ':'.$this->getState('filter.level_end');
 137          $id    .= ':'.$this->getState('filter.component');
 138  
 139          return parent::getStoreId($id);
 140      }
 141  
 142      /**
 143       * Get the user being debugged.
 144       *
 145       * @return    JUser
 146       * @since    1.6
 147       */
 148  	public function getUser()
 149      {
 150          $userId = $this->getState('filter.user_id');
 151  
 152          return JFactory::getUser($userId);
 153      }
 154  
 155      /**
 156       * Build an SQL query to load the list data.
 157       *
 158       * @return    JDatabaseQuery
 159       * @since    1.6
 160       */
 161  	protected function getListQuery()
 162      {
 163          // Create a new query object.
 164          $db        = $this->getDbo();
 165          $query    = $db->getQuery(true);
 166  
 167          // Select the required fields from the table.
 168          $query->select(
 169              $this->getState(
 170                  'list.select',
 171                  'a.id, a.name, a.title, a.level, a.lft, a.rgt'
 172              )
 173          );
 174          $query->from($db->quoteName('#__assets').' AS a');
 175  
 176          // Filter the items over the group id if set.
 177          if ($groupId = $this->getState('filter.group_id')) {
 178              $query->join('LEFT', '#__user_usergroup_map AS map2 ON map2.user_id = a.id');
 179              $query->where('map2.group_id = '.(int) $groupId);
 180          }
 181  
 182          // Filter the items over the search string if set.
 183          if ($this->getState('filter.search')) {
 184              // Escape the search token.
 185              $token    = $db->Quote('%'.$db->escape($this->getState('filter.search')).'%');
 186  
 187              // Compile the different search clauses.
 188              $searches    = array();
 189              $searches[]    = 'a.name LIKE '.$token;
 190              $searches[]    = 'a.title LIKE '.$token;
 191  
 192              // Add the clauses to the query.
 193              $query->where('('.implode(' OR ', $searches).')');
 194          }
 195  
 196          // Filter on the start and end levels.
 197          $levelStart    = (int) $this->getState('filter.level_start');
 198          $levelEnd    = (int) $this->getState('filter.level_end');
 199          if ($levelEnd > 0 && $levelEnd < $levelStart) {
 200              $levelEnd = $levelStart;
 201          }
 202          if ($levelStart > 0) {
 203              $query->where('a.level >= '.$levelStart);
 204          }
 205          if ($levelEnd > 0) {
 206              $query->where('a.level <= '.$levelEnd);
 207          }
 208  
 209          // Filter the items over the component if set.
 210          if ($this->getState('filter.component')) {
 211              $component = $this->getState('filter.component');
 212              $query->where('(a.name = '.$db->quote($component).' OR a.name LIKE '.$db->quote($component.'.%').')');
 213          }
 214  
 215          // Add the list ordering clause.
 216          $query->order($db->escape($this->getState('list.ordering', 'a.lft')).' '.$db->escape($this->getState('list.direction', 'ASC')));
 217  
 218          return $query;
 219      }
 220  }


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