[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/modules/mod_logged/src/Helper/ -> LoggedHelper.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  mod_logged
   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\Module\Logged\Administrator\Helper;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Language\Text;
  15  use Joomla\CMS\Router\Route;
  16  use Joomla\CMS\Session\Session;
  17  use Joomla\Database\DatabaseInterface;
  18  use Joomla\Registry\Registry;
  19  
  20  // phpcs:disable PSR1.Files.SideEffects
  21  \defined('_JEXEC') or die;
  22  // phpcs:enable PSR1.Files.SideEffects
  23  
  24  /**
  25   * Helper for mod_logged
  26   *
  27   * @since  1.5
  28   */
  29  abstract class LoggedHelper
  30  {
  31      /**
  32       * Get a list of logged users.
  33       *
  34       * @param   Registry           $params  The module parameters
  35       * @param   CMSApplication     $app     The application
  36       * @param   DatabaseInterface  $db      The database
  37       *
  38       * @return  mixed  An array of users, or false on error.
  39       *
  40       * @throws  \RuntimeException
  41       */
  42      public static function getList(Registry $params, CMSApplication $app, DatabaseInterface $db)
  43      {
  44          $user  = $app->getIdentity();
  45          $query = $db->getQuery(true)
  46              ->select('s.time, s.client_id, u.id, u.name, u.username')
  47              ->from('#__session AS s')
  48              ->join('LEFT', '#__users AS u ON s.userid = u.id')
  49              ->where('s.guest = 0')
  50              ->setLimit($params->get('count', 5), 0);
  51  
  52          $db->setQuery($query);
  53  
  54          try {
  55              $results = $db->loadObjectList();
  56          } catch (\RuntimeException $e) {
  57              throw $e;
  58          }
  59  
  60          foreach ($results as $k => $result) {
  61              $results[$k]->logoutLink = '';
  62  
  63              if ($user->authorise('core.manage', 'com_users')) {
  64                  $results[$k]->editLink   = Route::_('index.php?option=com_users&task=user.edit&id=' . $result->id);
  65                  $results[$k]->logoutLink = Route::_(
  66                      'index.php?option=com_login&task=logout&uid=' . $result->id . '&' . Session::getFormToken() . '=1'
  67                  );
  68              }
  69  
  70              if ($params->get('name', 1) == 0) {
  71                  $results[$k]->name = $results[$k]->username;
  72              }
  73          }
  74  
  75          return $results;
  76      }
  77  
  78      /**
  79       * Get the alternate title for the module
  80       *
  81       * @param   \Joomla\Registry\Registry  $params  The module parameters.
  82       *
  83       * @return  string    The alternate title for the module.
  84       */
  85      public static function getTitle($params)
  86      {
  87          return Text::plural('MOD_LOGGED_TITLE', $params->get('count', 5));
  88      }
  89  }


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