[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_messages/src/View/Messages/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_messages
   6   *
   7   * @copyright   (C) 2008 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\Messages\Administrator\View\Messages;
  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\Toolbar\Toolbar;
  19  use Joomla\CMS\Toolbar\ToolbarHelper;
  20  
  21  // phpcs:disable PSR1.Files.SideEffects
  22  \defined('_JEXEC') or die;
  23  // phpcs:enable PSR1.Files.SideEffects
  24  
  25  /**
  26   * View class for a list of messages.
  27   *
  28   * @since  1.6
  29   */
  30  class HtmlView extends BaseHtmlView
  31  {
  32      /**
  33       * An array of items
  34       *
  35       * @var  array
  36       */
  37      protected $items;
  38  
  39      /**
  40       * The pagination object
  41       *
  42       * @var  \Joomla\CMS\Pagination\Pagination
  43       */
  44      protected $pagination;
  45  
  46      /**
  47       * The model state
  48       *
  49       * @var  \Joomla\CMS\Object\CMSObject
  50       */
  51      protected $state;
  52  
  53      /**
  54       * Form object for search filters
  55       *
  56       * @var    \Joomla\CMS\Form\Form
  57       *
  58       * @since  4.0.0
  59       */
  60      public $filterForm;
  61  
  62      /**
  63       * The active search filters
  64       *
  65       * @var    array
  66       * @since  4.0.0
  67       */
  68      public $activeFilters;
  69  
  70      /**
  71       * Is this view an Empty State
  72       *
  73       * @var  boolean
  74       * @since 4.0.0
  75       */
  76      private $isEmptyState = false;
  77  
  78      /**
  79       * Execute and display a template script.
  80       *
  81       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  82       *
  83       * @return  void
  84       *
  85       * @since   1.6
  86       */
  87      public function display($tpl = null)
  88      {
  89          $this->items         = $this->get('Items');
  90          $this->pagination    = $this->get('Pagination');
  91          $this->state         = $this->get('State');
  92          $this->filterForm    = $this->get('FilterForm');
  93          $this->activeFilters = $this->get('ActiveFilters');
  94  
  95          if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
  96              $this->setLayout('emptystate');
  97          }
  98  
  99          // Check for errors.
 100          if (\count($errors = $this->get('Errors'))) {
 101              throw new GenericDataException(implode("\n", $errors), 500);
 102          }
 103  
 104          $this->addToolbar();
 105  
 106          parent::display($tpl);
 107      }
 108  
 109      /**
 110       * Add the page title and toolbar.
 111       *
 112       * @return  void
 113       *
 114       * @since   1.6
 115       */
 116      protected function addToolbar()
 117      {
 118          $state = $this->get('State');
 119          $canDo = ContentHelper::getActions('com_messages');
 120          $user  = Factory::getApplication()->getIdentity();
 121  
 122          // Get the toolbar object instance
 123          $toolbar = Toolbar::getInstance('toolbar');
 124  
 125          ToolbarHelper::title(Text::_('COM_MESSAGES_MANAGER_MESSAGES'), 'envelope inbox');
 126  
 127          // Only display the New button if the user has the access level to create a message and if they have access to the list of users
 128          if ($canDo->get('core.create') && $user->authorise('core.manage', 'com_users')) {
 129              $toolbar->addNew('message.add');
 130          }
 131  
 132          if (!$this->isEmptyState && $canDo->get('core.edit.state')) {
 133              $dropdown = $toolbar->dropdownButton('status-group')
 134                  ->text('JTOOLBAR_CHANGE_STATUS')
 135                  ->toggleSplit(false)
 136                  ->icon('icon-ellipsis-h')
 137                  ->buttonClass('btn btn-action')
 138                  ->listCheck(true);
 139  
 140              $childBar = $dropdown->getChildToolbar();
 141  
 142              $childBar->publish('messages.publish')
 143                  ->text('COM_MESSAGES_TOOLBAR_MARK_AS_READ')
 144                  ->listCheck(true);
 145  
 146              $childBar->unpublish('messages.unpublish')
 147                  ->text('COM_MESSAGES_TOOLBAR_MARK_AS_UNREAD')
 148                  ->listCheck(true);
 149  
 150              if ($this->state->get('filter.state') != -2) {
 151                  $childBar->trash('messages.trash')->listCheck(true);
 152              }
 153          }
 154  
 155          $toolbar->appendButton('Link', 'cog', 'COM_MESSAGES_TOOLBAR_MY_SETTINGS', 'index.php?option=com_messages&amp;view=config');
 156          ToolbarHelper::divider();
 157  
 158          if (!$this->isEmptyState && $this->state->get('filter.state') == -2 && $canDo->get('core.delete')) {
 159              $toolbar->delete('messages.delete')
 160                  ->text('JTOOLBAR_EMPTY_TRASH')
 161                  ->message('JGLOBAL_CONFIRM_DELETE')
 162                  ->listCheck(true);
 163          }
 164  
 165          if ($canDo->get('core.admin')) {
 166              $toolbar->preferences('com_messages');
 167          }
 168  
 169          $toolbar->help('Private_Messages');
 170      }
 171  }


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