[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_contact/src/View/Contacts/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_contact
   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\Contact\Administrator\View\Contacts;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Helper\ContentHelper;
  15  use Joomla\CMS\Language\Multilanguage;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\MVC\View\GenericDataException;
  18  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  19  use Joomla\CMS\Toolbar\Toolbar;
  20  use Joomla\CMS\Toolbar\ToolbarHelper;
  21  
  22  // phpcs:disable PSR1.Files.SideEffects
  23  \defined('_JEXEC') or die;
  24  // phpcs:enable PSR1.Files.SideEffects
  25  
  26  /**
  27   * View class for a list of contacts.
  28   *
  29   * @since  1.6
  30   */
  31  class HtmlView extends BaseHtmlView
  32  {
  33      /**
  34       * An array of items
  35       *
  36       * @var  array
  37       */
  38      protected $items;
  39  
  40      /**
  41       * The pagination object
  42       *
  43       * @var  \Joomla\CMS\Pagination\Pagination
  44       */
  45      protected $pagination;
  46  
  47      /**
  48       * The model state
  49       *
  50       * @var  \Joomla\CMS\Object\CMSObject
  51       */
  52      protected $state;
  53  
  54      /**
  55       * Form object for search filters
  56       *
  57       * @var  \Joomla\CMS\Form\Form
  58       */
  59      public $filterForm;
  60  
  61      /**
  62       * The active search filters
  63       *
  64       * @var  array
  65       */
  66      public $activeFilters;
  67  
  68      /**
  69       * Is this view an Empty State
  70       *
  71       * @var   boolean
  72       *
  73       * @since 4.0.0
  74       */
  75      private $isEmptyState = false;
  76  
  77      /**
  78       * Display the view.
  79       *
  80       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  81       *
  82       * @return  void
  83       */
  84      public function display($tpl = null)
  85      {
  86          $this->items         = $this->get('Items');
  87          $this->pagination    = $this->get('Pagination');
  88          $this->state         = $this->get('State');
  89          $this->filterForm    = $this->get('FilterForm');
  90          $this->activeFilters = $this->get('ActiveFilters');
  91  
  92          if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
  93              $this->setLayout('emptystate');
  94          }
  95  
  96          // Check for errors.
  97          if (\count($errors = $this->get('Errors'))) {
  98              throw new GenericDataException(implode("\n", $errors), 500);
  99          }
 100  
 101          // Preprocess the list of items to find ordering divisions.
 102          // @todo: Complete the ordering stuff with nested sets
 103          foreach ($this->items as &$item) {
 104              $item->order_up = true;
 105              $item->order_dn = true;
 106          }
 107  
 108          // We don't need toolbar in the modal window.
 109          if ($this->getLayout() !== 'modal') {
 110              $this->addToolbar();
 111  
 112              // We do not need to filter by language when multilingual is disabled
 113              if (!Multilanguage::isEnabled()) {
 114                  unset($this->activeFilters['language']);
 115                  $this->filterForm->removeField('language', 'filter');
 116              }
 117          } else {
 118              // In article associations modal we need to remove language filter if forcing a language.
 119              // We also need to change the category filter to show show categories with All or the forced language.
 120              if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
 121                  // If the language is forced we can't allow to select the language, so transform the language selector filter into a hidden field.
 122                  $languageXml = new \SimpleXMLElement('<field name="language" type="hidden" default="' . $forcedLanguage . '" />');
 123                  $this->filterForm->setField($languageXml, 'filter', true);
 124  
 125                  // Also, unset the active language filter so the search tools is not open by default with this filter.
 126                  unset($this->activeFilters['language']);
 127  
 128                  // One last changes needed is to change the category filter to just show categories with All language or with the forced language.
 129                  $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
 130              }
 131          }
 132  
 133          parent::display($tpl);
 134      }
 135  
 136      /**
 137       * Add the page title and toolbar.
 138       *
 139       * @return  void
 140       *
 141       * @since   1.6
 142       */
 143      protected function addToolbar()
 144      {
 145          $canDo = ContentHelper::getActions('com_contact', 'category', $this->state->get('filter.category_id'));
 146          $user  = Factory::getApplication()->getIdentity();
 147  
 148          // Get the toolbar object instance
 149          $toolbar = Toolbar::getInstance('toolbar');
 150  
 151          ToolbarHelper::title(Text::_('COM_CONTACT_MANAGER_CONTACTS'), 'address-book contact');
 152  
 153          if ($canDo->get('core.create') || \count($user->getAuthorisedCategories('com_contact', 'core.create')) > 0) {
 154              $toolbar->addNew('contact.add');
 155          }
 156  
 157          if (!$this->isEmptyState && $canDo->get('core.edit.state')) {
 158              $dropdown = $toolbar->dropdownButton('status-group')
 159                  ->text('JTOOLBAR_CHANGE_STATUS')
 160                  ->toggleSplit(false)
 161                  ->icon('icon-ellipsis-h')
 162                  ->buttonClass('btn btn-action')
 163                  ->listCheck(true);
 164  
 165              $childBar = $dropdown->getChildToolbar();
 166  
 167              $childBar->publish('contacts.publish')->listCheck(true);
 168  
 169              $childBar->unpublish('contacts.unpublish')->listCheck(true);
 170  
 171              $childBar->standardButton('featured')
 172                  ->text('JFEATURE')
 173                  ->task('contacts.featured')
 174                  ->listCheck(true);
 175              $childBar->standardButton('unfeatured')
 176                  ->text('JUNFEATURE')
 177                  ->task('contacts.unfeatured')
 178                  ->listCheck(true);
 179  
 180              $childBar->archive('contacts.archive')->listCheck(true);
 181  
 182              if ($user->authorise('core.admin')) {
 183                  $childBar->checkin('contacts.checkin')->listCheck(true);
 184              }
 185  
 186              if ($this->state->get('filter.published') != -2) {
 187                  $childBar->trash('contacts.trash')->listCheck(true);
 188              }
 189  
 190              // Add a batch button
 191              if (
 192                  $user->authorise('core.create', 'com_contact')
 193                  && $user->authorise('core.edit', 'com_contact')
 194                  && $user->authorise('core.edit.state', 'com_contact')
 195              ) {
 196                  $childBar->popupButton('batch')
 197                      ->text('JTOOLBAR_BATCH')
 198                      ->selector('collapseModal')
 199                      ->listCheck(true);
 200              }
 201          }
 202  
 203          if (!$this->isEmptyState && $this->state->get('filter.published') == -2 && $canDo->get('core.delete')) {
 204              $toolbar->delete('contacts.delete')
 205                  ->text('JTOOLBAR_EMPTY_TRASH')
 206                  ->message('JGLOBAL_CONFIRM_DELETE')
 207                  ->listCheck(true);
 208          }
 209  
 210          if ($user->authorise('core.admin', 'com_contact') || $user->authorise('core.options', 'com_contact')) {
 211              $toolbar->preferences('com_contact');
 212          }
 213  
 214          $toolbar->help('Contacts');
 215      }
 216  }


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