[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_users/src/View/User/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_users
   6   *
   7   * @copyright   (C) 2007 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\View\User;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\ContentHelper;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\View\GenericDataException;
  17  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  18  use Joomla\CMS\Object\CMSObject;
  19  use Joomla\CMS\Toolbar\ToolbarHelper;
  20  use Joomla\CMS\User\User;
  21  use Joomla\CMS\User\UserFactoryInterface;
  22  use Joomla\Component\Users\Administrator\Helper\Mfa;
  23  
  24  // phpcs:disable PSR1.Files.SideEffects
  25  \defined('_JEXEC') or die;
  26  // phpcs:enable PSR1.Files.SideEffects
  27  
  28  /**
  29   * User view class.
  30   *
  31   * @since  1.5
  32   */
  33  class HtmlView extends BaseHtmlView
  34  {
  35      /**
  36       * The Form object
  37       *
  38       * @var  \Joomla\CMS\Form\Form
  39       */
  40      protected $form;
  41  
  42      /**
  43       * The active item
  44       *
  45       * @var  object
  46       */
  47      protected $item;
  48  
  49      /**
  50       * Gets the available groups
  51       *
  52       * @var  array
  53       */
  54      protected $grouplist;
  55  
  56      /**
  57       * The groups this user is assigned to
  58       *
  59       * @var     array
  60       * @since   1.6
  61       */
  62      protected $groups;
  63  
  64      /**
  65       * The model state
  66       *
  67       * @var  CMSObject
  68       */
  69      protected $state;
  70  
  71      /**
  72       * The Multi-factor Authentication configuration interface for the user.
  73       *
  74       * @var   string|null
  75       * @since 4.2.0
  76       */
  77      protected $mfaConfigurationUI;
  78  
  79      /**
  80       * Display the view
  81       *
  82       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  83       *
  84       * @return  void
  85       *
  86       * @since   1.5
  87       */
  88      public function display($tpl = null)
  89      {
  90          // If no item found, dont show the edit screen, redirect with message
  91          if (false === $this->item = $this->get('Item')) {
  92              $app = Factory::getApplication();
  93              $app->enqueueMessage(Text::_('JLIB_APPLICATION_ERROR_NOT_EXIST'), 'error');
  94              $app->redirect('index.php?option=com_users&view=users');
  95          }
  96  
  97          $this->form  = $this->get('Form');
  98          $this->state = $this->get('State');
  99  
 100          // Check for errors.
 101          if (count($errors = $this->get('Errors'))) {
 102              throw new GenericDataException(implode("\n", $errors), 500);
 103          }
 104  
 105          // Prevent user from modifying own group(s)
 106          $user = Factory::getApplication()->getIdentity();
 107  
 108          if ((int) $user->id != (int) $this->item->id || $user->authorise('core.admin')) {
 109              $this->grouplist = $this->get('Groups');
 110              $this->groups    = $this->get('AssignedGroups');
 111          }
 112  
 113          $this->form->setValue('password', null);
 114          $this->form->setValue('password2', null);
 115  
 116          /** @var User $userBeingEdited */
 117          $userBeingEdited = Factory::getContainer()
 118              ->get(UserFactoryInterface::class)
 119              ->loadUserById($this->item->id);
 120  
 121          if ($this->item->id > 0 && (int) $userBeingEdited->id == (int) $this->item->id) {
 122              try {
 123                  $this->mfaConfigurationUI = Mfa::canShowConfigurationInterface($userBeingEdited)
 124                      ? Mfa::getConfigurationInterface($userBeingEdited)
 125                      : '';
 126              } catch (\Exception $e) {
 127                  // In case something goes really wrong with the plugins; prevents hard breaks.
 128                  $this->mfaConfigurationUI = null;
 129              }
 130          }
 131  
 132          parent::display($tpl);
 133  
 134          $this->addToolbar();
 135      }
 136  
 137      /**
 138       * Add the page title and toolbar.
 139       *
 140       * @return void
 141       *
 142       * @since   1.6
 143       * @throws  \Exception
 144       */
 145      protected function addToolbar()
 146      {
 147          Factory::getApplication()->input->set('hidemainmenu', true);
 148  
 149          $user      = Factory::getApplication()->getIdentity();
 150          $canDo     = ContentHelper::getActions('com_users');
 151          $isNew     = ($this->item->id == 0);
 152          $isProfile = $this->item->id == $user->id;
 153  
 154          ToolbarHelper::title(
 155              Text::_(
 156                  $isNew ? 'COM_USERS_VIEW_NEW_USER_TITLE' : ($isProfile ? 'COM_USERS_VIEW_EDIT_PROFILE_TITLE' : 'COM_USERS_VIEW_EDIT_USER_TITLE')
 157              ),
 158              'user ' . ($isNew ? 'user-add' : ($isProfile ? 'user-profile' : 'user-edit'))
 159          );
 160  
 161          $toolbarButtons = [];
 162  
 163          if ($canDo->get('core.edit') || $canDo->get('core.create') || $isProfile) {
 164              ToolbarHelper::apply('user.apply');
 165              $toolbarButtons[] = ['save', 'user.save'];
 166          }
 167  
 168          if ($canDo->get('core.create') && $canDo->get('core.manage')) {
 169              $toolbarButtons[] = ['save2new', 'user.save2new'];
 170          }
 171  
 172          ToolbarHelper::saveGroup(
 173              $toolbarButtons,
 174              'btn-success'
 175          );
 176  
 177          if (empty($this->item->id)) {
 178              ToolbarHelper::cancel('user.cancel');
 179          } else {
 180              ToolbarHelper::cancel('user.cancel', 'JTOOLBAR_CLOSE');
 181          }
 182  
 183          ToolbarHelper::divider();
 184          ToolbarHelper::help('Users:_Edit_Profile');
 185      }
 186  }


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