[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Joomla! Content Management System 5 * 6 * @copyright (C) 2016 Open Source Matters, Inc. <https://www.joomla.org> 7 * @license GNU General Public License version 2 or later; see LICENSE.txt 8 */ 9 10 namespace Joomla\CMS\MVC\View; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\Language\Text; 14 use Joomla\CMS\Layout\FileLayout; 15 use Joomla\CMS\Object\CMSObject; 16 use Joomla\CMS\Toolbar\Toolbar; 17 use Joomla\CMS\Toolbar\ToolbarHelper; 18 19 // phpcs:disable PSR1.Files.SideEffects 20 \defined('JPATH_PLATFORM') or die; 21 // phpcs:enable PSR1.Files.SideEffects 22 23 /** 24 * Base class for a Joomla List View 25 * 26 * Class holding methods for displaying presentation data. 27 * 28 * @since 2.5.5 29 */ 30 class ListView extends HtmlView 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 CMSObject 50 */ 51 protected $state; 52 53 /** 54 * The actions the user is authorised to perform 55 * 56 * @var CMSObject 57 */ 58 protected $canDo; 59 60 /** 61 * Form object for search filters 62 * 63 * @var \Joomla\CMS\Form\Form 64 */ 65 public $filterForm; 66 67 /** 68 * The active search filters 69 * 70 * @var array 71 */ 72 public $activeFilters; 73 74 /** 75 * The sidebar markup 76 * 77 * @var string 78 */ 79 protected $sidebar; 80 81 /** 82 * The toolbar title 83 * 84 * @var string 85 */ 86 protected $toolbarTitle; 87 88 /** 89 * The toolbar icon 90 * 91 * @var string 92 */ 93 protected $toolbarIcon; 94 95 /** 96 * The flag which determine whether we want to show batch button 97 * 98 * @var boolean 99 */ 100 protected $supportsBatch = true; 101 102 /** 103 * The help link for the view 104 * 105 * @var string 106 */ 107 protected $helpLink; 108 109 /** 110 * Constructor 111 * 112 * @param array $config An optional associative array of configuration settings. 113 */ 114 public function __construct(array $config) 115 { 116 parent::__construct($config); 117 118 // Set class properties from config data passed in constructor 119 if (isset($config['toolbar_title'])) { 120 $this->toolbarTitle = $config['toolbar_title']; 121 } else { 122 $this->toolbarTitle = strtoupper($this->option . '_MANAGER_' . $this->getName()); 123 } 124 125 if (isset($config['toolbar_icon'])) { 126 $this->toolbarIcon = $config['toolbar_icon']; 127 } else { 128 $this->toolbarIcon = strtolower($this->getName()); 129 } 130 131 if (isset($config['supports_batch'])) { 132 $this->supportsBatch = $config['supports_batch']; 133 } 134 135 if (isset($config['help_link'])) { 136 $this->helpLink = $config['help_link']; 137 } 138 139 // Set default value for $canDo to avoid fatal error if child class doesn't set value for this property 140 $this->canDo = new CMSObject(); 141 } 142 143 /** 144 * Execute and display a template script. 145 * 146 * @param string $tpl The name of the template file to parse; automatically searches through the template paths. 147 * 148 * @return void 149 * 150 * @throws \Exception 151 */ 152 public function display($tpl = null) 153 { 154 // Prepare view data 155 $this->initializeView(); 156 157 // Check for errors. 158 if (\count($errors = $this->get('Errors'))) { 159 throw new GenericDataException(implode("\n", $errors), 500); 160 } 161 162 // Build toolbar 163 $this->addToolbar(); 164 165 parent::display($tpl); 166 } 167 168 /** 169 * Prepare view data 170 * 171 * @return void 172 */ 173 protected function initializeView() 174 { 175 $componentName = substr($this->option, 4); 176 $helperClass = ucfirst($componentName . 'Helper'); 177 178 // Include the component helpers. 179 \JLoader::register($helperClass, JPATH_COMPONENT . '/helpers/' . $componentName . '.php'); 180 181 if ($this->getLayout() !== 'modal') { 182 if (\is_callable($helperClass . '::addSubmenu')) { 183 \call_user_func(array($helperClass, 'addSubmenu'), $this->getName()); 184 } 185 186 $this->sidebar = \JHtmlSidebar::render(); 187 } 188 189 $this->items = $this->get('Items'); 190 $this->pagination = $this->get('Pagination'); 191 $this->state = $this->get('State'); 192 $this->filterForm = $this->get('FilterForm'); 193 $this->activeFilters = $this->get('ActiveFilters'); 194 } 195 196 /** 197 * Add the page title and toolbar. 198 * 199 * @return void 200 * 201 * @since 1.6 202 */ 203 protected function addToolbar() 204 { 205 $canDo = $this->canDo; 206 $user = Factory::getUser(); 207 208 // Get the toolbar object instance 209 $bar = Toolbar::getInstance('toolbar'); 210 211 $viewName = $this->getName(); 212 $singularViewName = \Joomla\String\Inflector::getInstance()->toSingular($viewName); 213 214 ToolbarHelper::title(Text::_($this->toolbarTitle), $this->toolbarIcon); 215 216 if ($canDo->get('core.create')) { 217 ToolbarHelper::addNew($singularViewName . '.add'); 218 } 219 220 if (($canDo->get('core.edit')) || ($canDo->get('core.edit.own'))) { 221 ToolbarHelper::editList($singularViewName . '.edit'); 222 } 223 224 if ($canDo->get('core.edit.state')) { 225 ToolbarHelper::publish($viewName . '.publish', 'JTOOLBAR_PUBLISH', true); 226 ToolbarHelper::unpublish($viewName . '.unpublish', 'JTOOLBAR_UNPUBLISH', true); 227 228 if (isset($this->items[0]->featured)) { 229 ToolbarHelper::custom($viewName . '.featured', 'featured', '', 'JFEATURE', true); 230 ToolbarHelper::custom($viewName . '.unfeatured', 'unfeatured', '', 'JUNFEATURE', true); 231 } 232 233 ToolbarHelper::archiveList($viewName . '.archive'); 234 ToolbarHelper::checkin($viewName . '.checkin'); 235 } 236 237 // Add a batch button 238 if ( 239 $this->supportsBatch && $user->authorise('core.create', $this->option) 240 && $user->authorise('core.edit', $this->option) 241 && $user->authorise('core.edit.state', $this->option) 242 ) { 243 $title = Text::_('JTOOLBAR_BATCH'); 244 245 // Instantiate a new LayoutFile instance and render the popup button 246 $layout = new FileLayout('joomla.toolbar.popup'); 247 248 $dhtml = $layout->render(array('title' => $title)); 249 $bar->appendButton('Custom', $dhtml, 'batch'); 250 } 251 252 if ($this->state->get('filter.published') == -2 && $canDo->get('core.delete')) { 253 ToolbarHelper::deleteList('JGLOBAL_CONFIRM_DELETE', $viewName . '.delete', 'JTOOLBAR_EMPTY_TRASH'); 254 } elseif ($canDo->get('core.edit.state')) { 255 ToolbarHelper::trash($viewName . '.trash'); 256 } 257 258 if ($user->authorise('core.admin', $this->option) || $user->authorise('core.options', $this->option)) { 259 ToolbarHelper::preferences($this->option); 260 } 261 262 if ($this->helpLink) { 263 ToolbarHelper::help($this->helpLink); 264 } 265 } 266 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Wed Sep 7 05:41:13 2022 | Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer |