Source for file debuggroup.php

Documentation is available at debuggroup.php

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

Documentation generated on Tue, 19 Nov 2013 14:58:04 +0100 by phpDocumentor 1.4.3