[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_associations/src/View/Associations/ -> HtmlView.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Administrator
   5   * @subpackage  com_associations
   6   *
   7   * @copyright   (C) 2017 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\Associations\Administrator\View\Associations;
  12  
  13  use Joomla\CMS\Factory;
  14  use Joomla\CMS\Language\Associations;
  15  use Joomla\CMS\Language\Text;
  16  use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
  17  use Joomla\CMS\Router\Route;
  18  use Joomla\CMS\Toolbar\ToolbarHelper;
  19  use Joomla\Component\Associations\Administrator\Helper\AssociationsHelper;
  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 articles.
  27   *
  28   * @since  3.7.0
  29   */
  30  class HtmlView extends BaseHtmlView
  31  {
  32      /**
  33       * An array of items
  34       *
  35       * @var   array
  36       *
  37       * @since  3.7.0
  38       */
  39      protected $items;
  40  
  41      /**
  42       * The pagination object
  43       *
  44       * @var    \Joomla\CMS\Pagination\Pagination
  45       *
  46       * @since  3.7.0
  47       */
  48      protected $pagination;
  49  
  50      /**
  51       * The model state
  52       *
  53       * @var    object
  54       *
  55       * @since  3.7.0
  56       */
  57      protected $state;
  58  
  59      /**
  60       * Selected item type properties.
  61       *
  62       * @var    \Joomla\Registry\Registry
  63       *
  64       * @since  3.7.0
  65       */
  66      public $itemType = null;
  67  
  68      /**
  69       * Display the view
  70       *
  71       * @param   string  $tpl  The name of the template file to parse; automatically searches through the template paths.
  72       *
  73       * @return  void
  74       *
  75       * @since  3.7.0
  76       */
  77      public function display($tpl = null)
  78      {
  79          $this->state         = $this->get('State');
  80          $this->filterForm    = $this->get('FilterForm');
  81          $this->activeFilters = $this->get('ActiveFilters');
  82  
  83          if (!Associations::isEnabled()) {
  84              $link = Route::_('index.php?option=com_plugins&task=plugin.edit&extension_id=' . AssociationsHelper::getLanguagefilterPluginId());
  85              Factory::getApplication()->enqueueMessage(Text::sprintf('COM_ASSOCIATIONS_ERROR_NO_ASSOC', $link), 'warning');
  86          } elseif ($this->state->get('itemtype') != '' && $this->state->get('language') != '') {
  87              $type = null;
  88  
  89              list($extensionName, $typeName) = explode('.', $this->state->get('itemtype'), 2);
  90  
  91              $extension = AssociationsHelper::getSupportedExtension($extensionName);
  92  
  93              $types = $extension->get('types');
  94  
  95              if (\array_key_exists($typeName, $types)) {
  96                  $type = $types[$typeName];
  97              }
  98  
  99              $this->itemType = $type;
 100  
 101              if (\is_null($type)) {
 102                  Factory::getApplication()->enqueueMessage(Text::_('COM_ASSOCIATIONS_ERROR_NO_TYPE'), 'warning');
 103              } else {
 104                  $this->extensionName = $extensionName;
 105                  $this->typeName      = $typeName;
 106                  $this->typeSupports  = array();
 107                  $this->typeFields    = array();
 108  
 109                  $details = $type->get('details');
 110  
 111                  if (\array_key_exists('support', $details)) {
 112                      $support = $details['support'];
 113                      $this->typeSupports = $support;
 114                  }
 115  
 116                  if (\array_key_exists('fields', $details)) {
 117                      $fields = $details['fields'];
 118                      $this->typeFields = $fields;
 119                  }
 120  
 121                  // Dynamic filter form.
 122                  // This selectors doesn't have to activate the filter bar.
 123                  unset($this->activeFilters['itemtype']);
 124                  unset($this->activeFilters['language']);
 125  
 126                  // Remove filters options depending on selected type.
 127                  if (empty($support['state'])) {
 128                      unset($this->activeFilters['state']);
 129                      $this->filterForm->removeField('state', 'filter');
 130                  }
 131  
 132                  if (empty($support['category'])) {
 133                      unset($this->activeFilters['category_id']);
 134                      $this->filterForm->removeField('category_id', 'filter');
 135                  }
 136  
 137                  if ($extensionName !== 'com_menus') {
 138                      unset($this->activeFilters['menutype']);
 139                      $this->filterForm->removeField('menutype', 'filter');
 140                  }
 141  
 142                  if (empty($support['level'])) {
 143                      unset($this->activeFilters['level']);
 144                      $this->filterForm->removeField('level', 'filter');
 145                  }
 146  
 147                  if (empty($support['acl'])) {
 148                      unset($this->activeFilters['access']);
 149                      $this->filterForm->removeField('access', 'filter');
 150                  }
 151  
 152                  // Add extension attribute to category filter.
 153                  if (empty($support['catid'])) {
 154                      $this->filterForm->setFieldAttribute('category_id', 'extension', $extensionName, 'filter');
 155  
 156                      if ($this->getLayout() == 'modal') {
 157                          // We need to change the category filter to only show categories tagged to All or to the forced language.
 158                          if ($forcedLanguage = Factory::getApplication()->input->get('forcedLanguage', '', 'CMD')) {
 159                              $this->filterForm->setFieldAttribute('category_id', 'language', '*,' . $forcedLanguage, 'filter');
 160                          }
 161                      }
 162                  }
 163  
 164                  $this->items      = $this->get('Items');
 165                  $this->pagination = $this->get('Pagination');
 166  
 167                  $linkParameters = array(
 168                      'layout'     => 'edit',
 169                      'itemtype'   => $extensionName . '.' . $typeName,
 170                      'task'       => 'association.edit',
 171                  );
 172  
 173                  $this->editUri = 'index.php?option=com_associations&view=association&' . http_build_query($linkParameters);
 174              }
 175          }
 176  
 177          // Check for errors.
 178          if (\count($errors = $this->get('Errors'))) {
 179              throw new \Exception(implode("\n", $errors), 500);
 180          }
 181  
 182          $this->addToolbar();
 183  
 184          parent::display($tpl);
 185      }
 186  
 187      /**
 188       * Add the page title and toolbar.
 189       *
 190       * @return  void
 191       *
 192       * @since  3.7.0
 193       */
 194      protected function addToolbar()
 195      {
 196          $user = $this->getCurrentUser();
 197  
 198          if (isset($this->typeName) && isset($this->extensionName)) {
 199              $helper = AssociationsHelper::getExtensionHelper($this->extensionName);
 200              $title  = $helper->getTypeTitle($this->typeName);
 201  
 202              $languageKey = strtoupper($this->extensionName . '_' . $title . 'S');
 203  
 204              if ($this->typeName === 'category') {
 205                  $languageKey = strtoupper($this->extensionName) . '_CATEGORIES';
 206              }
 207  
 208              ToolbarHelper::title(
 209                  Text::sprintf(
 210                      'COM_ASSOCIATIONS_TITLE_LIST',
 211                      Text::_($this->extensionName),
 212                      Text::_($languageKey)
 213                  ),
 214                  'language assoc'
 215              );
 216          } else {
 217              ToolbarHelper::title(Text::_('COM_ASSOCIATIONS_TITLE_LIST_SELECT'), 'language assoc');
 218          }
 219  
 220          if ($user->authorise('core.admin', 'com_associations') || $user->authorise('core.options', 'com_associations')) {
 221              if (!isset($this->typeName)) {
 222                  ToolbarHelper::custom('associations.purge', 'purge', '', 'COM_ASSOCIATIONS_PURGE', false, false);
 223                  ToolbarHelper::custom('associations.clean', 'refresh', '', 'COM_ASSOCIATIONS_DELETE_ORPHANS', false, false);
 224              }
 225  
 226              ToolbarHelper::preferences('com_associations');
 227          }
 228  
 229          ToolbarHelper::help('Multilingual_Associations');
 230      }
 231  }


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