[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/Controller/ -> UsersController.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2009 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\Controller;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Input\Input;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\Controller\AdminController;
  17  use Joomla\CMS\MVC\Controller\BaseController;
  18  use Joomla\CMS\MVC\Factory\MVCFactoryInterface;
  19  use Joomla\CMS\Response\JsonResponse;
  20  use Joomla\Utilities\ArrayHelper;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * Users list controller class.
  28   *
  29   * @since  1.6
  30   */
  31  class UsersController extends AdminController
  32  {
  33      /**
  34       * @var    string  The prefix to use with controller messages.
  35       * @since  1.6
  36       */
  37      protected $text_prefix = 'COM_USERS_USERS';
  38  
  39      /**
  40       * Constructor.
  41       *
  42       * @param   array                $config   An optional associative array of configuration settings.
  43       * @param   MVCFactoryInterface  $factory  The factory.
  44       * @param   CMSApplication       $app      The CMSApplication for the dispatcher
  45       * @param   Input                $input    Input
  46       *
  47       * @since  1.6
  48       * @see    BaseController
  49       * @throws \Exception
  50       */
  51      public function __construct($config = array(), MVCFactoryInterface $factory = null, $app = null, $input = null)
  52      {
  53          parent::__construct($config, $factory, $app, $input);
  54  
  55          $this->registerTask('block', 'changeBlock');
  56          $this->registerTask('unblock', 'changeBlock');
  57      }
  58  
  59      /**
  60       * Proxy for getModel.
  61       *
  62       * @param   string  $name    The model name. Optional.
  63       * @param   string  $prefix  The class prefix. Optional.
  64       * @param   array   $config  Configuration array for model. Optional.
  65       *
  66       * @return  object  The model.
  67       *
  68       * @since   1.6
  69       */
  70      public function getModel($name = 'User', $prefix = 'Administrator', $config = array('ignore_request' => true))
  71      {
  72          return parent::getModel($name, $prefix, $config);
  73      }
  74  
  75      /**
  76       * Method to change the block status on a record.
  77       *
  78       * @return  void
  79       *
  80       * @since   1.6
  81       */
  82      public function changeBlock()
  83      {
  84          // Check for request forgeries.
  85          $this->checkToken();
  86  
  87          $ids    = (array) $this->input->get('cid', array(), 'int');
  88          $values = array('block' => 1, 'unblock' => 0);
  89          $task   = $this->getTask();
  90          $value  = ArrayHelper::getValue($values, $task, 0, 'int');
  91  
  92          // Remove zero values resulting from input filter
  93          $ids = array_filter($ids);
  94  
  95          if (empty($ids)) {
  96              $this->setMessage(Text::_('COM_USERS_USERS_NO_ITEM_SELECTED'), 'warning');
  97          } else {
  98              // Get the model.
  99              $model = $this->getModel();
 100  
 101              // Change the state of the records.
 102              if (!$model->block($ids, $value)) {
 103                  $this->setMessage($model->getError(), 'error');
 104              } else {
 105                  if ($value == 1) {
 106                      $this->setMessage(Text::plural('COM_USERS_N_USERS_BLOCKED', count($ids)));
 107                  } elseif ($value == 0) {
 108                      $this->setMessage(Text::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids)));
 109                  }
 110              }
 111          }
 112  
 113          $this->setRedirect('index.php?option=com_users&view=users');
 114      }
 115  
 116      /**
 117       * Method to activate a record.
 118       *
 119       * @return  void
 120       *
 121       * @since   1.6
 122       */
 123      public function activate()
 124      {
 125          // Check for request forgeries.
 126          $this->checkToken();
 127  
 128          $ids = (array) $this->input->get('cid', array(), 'int');
 129  
 130          // Remove zero values resulting from input filter
 131          $ids = array_filter($ids);
 132  
 133          if (empty($ids)) {
 134              $this->setMessage(Text::_('COM_USERS_USERS_NO_ITEM_SELECTED'), 'error');
 135          } else {
 136              // Get the model.
 137              $model = $this->getModel();
 138  
 139              // Change the state of the records.
 140              if (!$model->activate($ids)) {
 141                  $this->setMessage($model->getError(), 'error');
 142              } else {
 143                  $this->setMessage(Text::plural('COM_USERS_N_USERS_ACTIVATED', count($ids)));
 144              }
 145          }
 146  
 147          $this->setRedirect('index.php?option=com_users&view=users');
 148      }
 149  
 150      /**
 151       * Method to get the number of active users
 152       *
 153       * @return  void
 154       *
 155       * @since   4.0.0
 156       */
 157      public function getQuickiconContent()
 158      {
 159          $model = $this->getModel('Users');
 160  
 161          $model->setState('filter.state', 0);
 162  
 163          $amount = (int) $model->getTotal();
 164  
 165          $result = [];
 166  
 167          $result['amount'] = $amount;
 168          $result['sronly'] = Text::plural('COM_USERS_N_QUICKICON_SRONLY', $amount);
 169          $result['name'] = Text::plural('COM_USERS_N_QUICKICON', $amount);
 170  
 171          echo new JsonResponse($result);
 172      }
 173  }


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