[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Helper/ -> UsersHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2017 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\Helper;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\ContentHelper;
  15  use Joomla\CMS\Helper\UserGroupsHelper;
  16  use Joomla\CMS\HTML\HTMLHelper;
  17  use Joomla\CMS\Language\Text;
  18  use Joomla\CMS\Object\CMSObject;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Users component helper.
  26   *
  27   * @since  1.6
  28   */
  29  class UsersHelper extends ContentHelper
  30  {
  31      /**
  32       * @var    CMSObject  A cache for the available actions.
  33       * @since  1.6
  34       */
  35      protected static $actions;
  36  
  37      /**
  38       * Get a list of filter options for the blocked state of a user.
  39       *
  40       * @return  array  An array of \JHtmlOption elements.
  41       *
  42       * @since   1.6
  43       */
  44      public static function getStateOptions()
  45      {
  46          // Build the filter options.
  47          $options = array();
  48          $options[] = HTMLHelper::_('select.option', '0', Text::_('JENABLED'));
  49          $options[] = HTMLHelper::_('select.option', '1', Text::_('JDISABLED'));
  50  
  51          return $options;
  52      }
  53  
  54      /**
  55       * Get a list of filter options for the activated state of a user.
  56       *
  57       * @return  array  An array of \JHtmlOption elements.
  58       *
  59       * @since   1.6
  60       */
  61      public static function getActiveOptions()
  62      {
  63          // Build the filter options.
  64          $options = array();
  65          $options[] = HTMLHelper::_('select.option', '0', Text::_('COM_USERS_ACTIVATED'));
  66          $options[] = HTMLHelper::_('select.option', '1', Text::_('COM_USERS_UNACTIVATED'));
  67  
  68          return $options;
  69      }
  70  
  71      /**
  72       * Get a list of the user groups for filtering.
  73       *
  74       * @return  array  An array of \JHtmlOption elements.
  75       *
  76       * @since   1.6
  77       */
  78      public static function getGroups()
  79      {
  80          $options = UserGroupsHelper::getInstance()->getAll();
  81  
  82          foreach ($options as &$option) {
  83              $option->value = $option->id;
  84              $option->text = str_repeat('- ', $option->level) . $option->title;
  85          }
  86  
  87          return $options;
  88      }
  89  
  90      /**
  91       * Creates a list of range options used in filter select list
  92       * used in com_users on users view
  93       *
  94       * @return  array
  95       *
  96       * @since   2.5
  97       */
  98      public static function getRangeOptions()
  99      {
 100          $options = array(
 101              HTMLHelper::_('select.option', 'today', Text::_('COM_USERS_OPTION_RANGE_TODAY')),
 102              HTMLHelper::_('select.option', 'past_week', Text::_('COM_USERS_OPTION_RANGE_PAST_WEEK')),
 103              HTMLHelper::_('select.option', 'past_1month', Text::_('COM_USERS_OPTION_RANGE_PAST_1MONTH')),
 104              HTMLHelper::_('select.option', 'past_3month', Text::_('COM_USERS_OPTION_RANGE_PAST_3MONTH')),
 105              HTMLHelper::_('select.option', 'past_6month', Text::_('COM_USERS_OPTION_RANGE_PAST_6MONTH')),
 106              HTMLHelper::_('select.option', 'past_year', Text::_('COM_USERS_OPTION_RANGE_PAST_YEAR')),
 107              HTMLHelper::_('select.option', 'post_year', Text::_('COM_USERS_OPTION_RANGE_POST_YEAR')),
 108          );
 109  
 110          return $options;
 111      }
 112  
 113      /**
 114       * No longer used.
 115       *
 116       * @return  array
 117       *
 118       * @since   3.2.0
 119       * @throws  \Exception
 120       *
 121       * @deprecated 4.2.0 Will be removed in 5.0
 122       */
 123      public static function getTwoFactorMethods()
 124      {
 125          return [];
 126      }
 127  
 128      /**
 129       * Get a list of the User Groups for Viewing Access Levels
 130       *
 131       * @param   string  $rules  User Groups in JSON format
 132       *
 133       * @return  string  $groups  Comma separated list of User Groups
 134       *
 135       * @since   3.6
 136       */
 137      public static function getVisibleByGroups($rules)
 138      {
 139          $rules = json_decode($rules);
 140  
 141          if (!$rules) {
 142              return false;
 143          }
 144  
 145          $db = Factory::getDbo();
 146          $query = $db->getQuery(true)
 147              ->select($db->quoteName('title', 'text'))
 148              ->from($db->quoteName('#__usergroups'))
 149              ->whereIn($db->quoteName('id'), $rules);
 150          $db->setQuery($query);
 151  
 152          $groups = $db->loadColumn();
 153          $groups = implode(', ', $groups);
 154  
 155          return $groups;
 156      }
 157  
 158      /**
 159       * Returns a valid section for users. If it is not valid then null
 160       * is returned.
 161       *
 162       * @param   string  $section  The section to get the mapping for
 163       *
 164       * @return  string|null  The new section
 165       *
 166       * @since       3.7.0
 167       * @throws      \Exception
 168       * @deprecated  5.0  Use \Joomla\Component\Users\Administrator\Extension\UsersComponent::validateSection() instead.
 169       */
 170      public static function validateSection($section)
 171      {
 172          return Factory::getApplication()->bootComponent('com_users')->validateSection($section, null);
 173      }
 174  
 175      /**
 176       * Returns valid contexts
 177       *
 178       * @return  array
 179       *
 180       * @since       3.7.0
 181       * @deprecated  5.0  Use \Joomla\Component\Users\Administrator\Extension\UsersComponent::getContexts() instead.
 182       */
 183      public static function getContexts()
 184      {
 185          return Factory::getApplication()->bootComponent('com_users')->getContexts();
 186      }
 187  }


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