[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_banners/src/View/Banners/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_banners
   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\Banners\Administrator\View\Banners;
  12  
  13  use Exception;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\Form\Form;
  16  use Joomla\CMS\Helper\ContentHelper;
  17  use Joomla\CMS\Language\Multilanguage;
  18  use Joomla\CMS\Language\Text;
  19  use Joomla\CMS\MVC\View\GenericDataException;
  20  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  21  use Joomla\CMS\Pagination\Pagination;
  22  use Joomla\CMS\Toolbar\Toolbar;
  23  use Joomla\CMS\Toolbar\ToolbarHelper;
  24  use Joomla\Component\Banners\Administrator\Model\BannersModel;
  25  use Joomla\Registry\Registry;
  26  
  27  // phpcs:disable PSR1.Files.SideEffects
  28  \defined('_JEXEC') or die;
  29  // phpcs:enable PSR1.Files.SideEffects
  30  
  31  /**
  32   * View class for a list of banners.
  33   *
  34   * @since  1.6
  35   */
  36  class HtmlView extends BaseHtmlView
  37  {
  38      /**
  39       * The search tools form
  40       *
  41       * @var    Form
  42       * @since  1.6
  43       */
  44      public $filterForm;
  45  
  46      /**
  47       * The active search filters
  48       *
  49       * @var    array
  50       * @since  1.6
  51       */
  52      public $activeFilters = [];
  53  
  54      /**
  55       * Category data
  56       *
  57       * @var    array
  58       * @since  1.6
  59       */
  60      protected $categories = [];
  61  
  62      /**
  63       * An array of items
  64       *
  65       * @var    array
  66       * @since  1.6
  67       */
  68      protected $items = [];
  69  
  70      /**
  71       * The pagination object
  72       *
  73       * @var    Pagination
  74       * @since  1.6
  75       */
  76      protected $pagination;
  77  
  78      /**
  79       * The model state
  80       *
  81       * @var    Registry
  82       * @since  1.6
  83       */
  84      protected $state;
  85  
  86      /**
  87       * Is this view an Empty State
  88       *
  89       * @var  boolean
  90       * @since 4.0.0
  91       */
  92      private $isEmptyState = false;
  93  
  94      /**
  95       * Method to display the view.
  96       *
  97       * @param   string  $tpl  A template file to load. [optional]
  98       *
  99       * @return  void
 100       *
 101       * @since   1.6
 102       * @throws  Exception
 103       */
 104      public function display($tpl = null): void
 105      {
 106          /** @var BannersModel $model */
 107          $model               = $this->getModel();
 108          $this->categories    = $model->getCategoryOrders();
 109          $this->items         = $model->getItems();
 110          $this->pagination    = $model->getPagination();
 111          $this->state         = $model->getState();
 112          $this->filterForm    = $model->getFilterForm();
 113          $this->activeFilters = $model->getActiveFilters();
 114  
 115          if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
 116              $this->setLayout('emptystate');
 117          }
 118  
 119          // Check for errors.
 120          if (\count($errors = $this->get('Errors'))) {
 121              throw new GenericDataException(implode("\n", $errors), 500);
 122          }
 123  
 124          $this->addToolbar();
 125  
 126          // We do not need to filter by language when multilingual is disabled
 127          if (!Multilanguage::isEnabled()) {
 128              unset($this->activeFilters['language']);
 129              $this->filterForm->removeField('language', 'filter');
 130          }
 131  
 132          parent::display($tpl);
 133      }
 134  
 135      /**
 136       * Add the page title and toolbar.
 137       *
 138       * @return  void
 139       *
 140       * @since   1.6
 141       */
 142      protected function addToolbar(): void
 143      {
 144          $canDo = ContentHelper::getActions('com_banners', 'category', $this->state->get('filter.category_id'));
 145          $user  = Factory::getApplication()->getIdentity();
 146  
 147          // Get the toolbar object instance
 148          $toolbar = Toolbar::getInstance('toolbar');
 149  
 150          ToolbarHelper::title(Text::_('COM_BANNERS_MANAGER_BANNERS'), 'bookmark banners');
 151  
 152          if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_banners', 'core.create')) > 0) {
 153              $toolbar->addNew('banner.add');
 154          }
 155  
 156          if (!$this->isEmptyState && ($canDo->get('core.edit.state') || ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')))) {
 157              $dropdown = $toolbar->dropdownButton('status-group')
 158                  ->text('JTOOLBAR_CHANGE_STATUS')
 159                  ->toggleSplit(false)
 160                  ->icon('icon-ellipsis-h')
 161                  ->buttonClass('btn btn-action')
 162                  ->listCheck(true);
 163  
 164              $childBar = $dropdown->getChildToolbar();
 165  
 166              if ($canDo->get('core.edit.state')) {
 167                  if ($this->state->get('filter.published') != 2) {
 168                      $childBar->publish('banners.publish')->listCheck(true);
 169  
 170                      $childBar->unpublish('banners.unpublish')->listCheck(true);
 171                  }
 172  
 173                  if ($this->state->get('filter.published') != -1) {
 174                      if ($this->state->get('filter.published') != 2) {
 175                          $childBar->archive('banners.archive')->listCheck(true);
 176                      } elseif ($this->state->get('filter.published') == 2) {
 177                          $childBar->publish('publish')->task('banners.publish')->listCheck(true);
 178                      }
 179                  }
 180  
 181                  $childBar->checkin('banners.checkin')->listCheck(true);
 182  
 183                  if ($this->state->get('filter.published') != -2) {
 184                      $childBar->trash('banners.trash')->listCheck(true);
 185                  }
 186              }
 187  
 188              if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
 189                  $toolbar->delete('banners.delete')
 190                      ->text('JTOOLBAR_EMPTY_TRASH')
 191                      ->message('JGLOBAL_CONFIRM_DELETE')
 192                      ->listCheck(true);
 193              }
 194  
 195              // Add a batch button
 196              if (
 197                  $user->authorise('core.create', 'com_banners')
 198                  && $user->authorise('core.edit', 'com_banners')
 199                  && $user->authorise('core.edit.state', 'com_banners')
 200              ) {
 201                  $childBar->popupButton('batch')
 202                      ->text('JTOOLBAR_BATCH')
 203                      ->selector('collapseModal')
 204                      ->listCheck(true);
 205              }
 206          }
 207  
 208          if ($user->authorise('core.admin', 'com_banners') || $user->authorise('core.options', 'com_banners')) {
 209              $toolbar->preferences('com_banners');
 210          }
 211  
 212          $toolbar->help('Banners');
 213      }
 214  }


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