[ 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) 2011 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\HTML\Helpers; 11 12 use Joomla\CMS\Factory; 13 use Joomla\CMS\HTML\HTMLHelper; 14 use Joomla\CMS\Language\Text; 15 use Joomla\CMS\Table\Table; 16 17 // phpcs:disable PSR1.Files.SideEffects 18 \defined('JPATH_PLATFORM') or die; 19 // phpcs:enable PSR1.Files.SideEffects 20 21 /** 22 * Utility class for creating HTML Grids 23 * 24 * @since 1.5 25 */ 26 abstract class Grid 27 { 28 /** 29 * Method to sort a column in a grid 30 * 31 * @param string $title The link title 32 * @param string $order The order field for the column 33 * @param string $direction The current direction 34 * @param string $selected The selected ordering 35 * @param string $task An optional task override 36 * @param string $newDirection An optional direction for the new column 37 * @param string $tip An optional text shown as tooltip title instead of $title 38 * @param string $form An optional form selector 39 * 40 * @return string 41 * 42 * @since 1.5 43 */ 44 public static function sort($title, $order, $direction = 'asc', $selected = '', $task = null, $newDirection = 'asc', $tip = '', $form = null) 45 { 46 HTMLHelper::_('behavior.core'); 47 HTMLHelper::_('bootstrap.popover', '.hasPopover', ['trigger' => 'hover focus']); 48 49 $direction = strtolower($direction); 50 $icon = array('arrow-up-3', 'arrow-down-3'); 51 $index = (int) ($direction === 'desc'); 52 53 if ($order != $selected) { 54 $direction = $newDirection; 55 } else { 56 $direction = $direction === 'desc' ? 'asc' : 'desc'; 57 } 58 59 if ($form) { 60 $form = ', document.getElementById(\'' . $form . '\')'; 61 } 62 63 $html = '<a href="#" onclick="Joomla.tableOrdering(\'' . $order . '\',\'' . $direction . '\',\'' . $task . '\'' . $form . ');return false;"' 64 . ' class="hasPopover" title="' . htmlspecialchars(Text::_($tip ?: $title)) . '"' 65 . ' data-bs-content="' . htmlspecialchars(Text::_('JGLOBAL_CLICK_TO_SORT_THIS_COLUMN')) . '" data-bs-placement="top">'; 66 67 if (isset($title['0']) && $title['0'] === '<') { 68 $html .= $title; 69 } else { 70 $html .= Text::_($title); 71 } 72 73 if ($order == $selected) { 74 $html .= '<span class="icon-' . $icon[$index] . '"></span>'; 75 } 76 77 $html .= '</a>'; 78 79 return $html; 80 } 81 82 /** 83 * Method to check all checkboxes in a grid 84 * 85 * @param string $name The name of the form element 86 * @param string $action The action to perform on clicking the checkbox 87 * 88 * @return string 89 * 90 * @since 3.1.2 91 */ 92 public static function checkall($name = 'checkall-toggle', $action = 'Joomla.checkAll(this)') 93 { 94 HTMLHelper::_('behavior.core'); 95 96 return '<input class="form-check-input" autocomplete="off" type="checkbox" name="' . $name . '" value="" title="' . Text::_('JGLOBAL_CHECK_ALL') . '" onclick="' . $action . '">'; 97 } 98 99 /** 100 * Method to create a checkbox for a grid row. 101 * 102 * @param integer $rowNum The row index 103 * @param integer $recId The record id 104 * @param boolean $checkedOut True if item is checked out 105 * @param string $name The name of the form element 106 * @param string $stub The name of stub identifier 107 * @param string $title The name of the item 108 * @param string $formId An optional form selector. 109 * 110 * @return mixed String of html with a checkbox if item is not checked out, null if checked out. 111 * 112 * @since 1.5 113 */ 114 public static function id($rowNum, $recId, $checkedOut = false, $name = 'cid', $stub = 'cb', $title = '', $formId = null) 115 { 116 if ($formId !== null) { 117 return $checkedOut ? '' : '<label for="' . $stub . $rowNum . '"><span class="visually-hidden">' . Text::_('JSELECT') 118 . ' ' . htmlspecialchars($title, ENT_COMPAT, 'UTF-8') . '</span></label>' 119 . '<input class="form-check-input" type="checkbox" id="' . $stub . $rowNum . '" name="' . $name . '[]" value="' . $recId 120 . '" onclick="Joomla.isChecked(this.checked, \'' . $formId . '\');">'; 121 } 122 123 return $checkedOut ? '' : '<label for="' . $stub . $rowNum . '"><span class="visually-hidden">' . Text::_('JSELECT') 124 . ' ' . htmlspecialchars($title, ENT_COMPAT, 'UTF-8') . '</span></label>' 125 . '<input class="form-check-input" autocomplete="off" type="checkbox" id="' . $stub . $rowNum . '" name="' . $name . '[]" value="' . $recId 126 . '" onclick="Joomla.isChecked(this.checked);">'; 127 } 128 129 /** 130 * Displays a checked out icon. 131 * 132 * @param object $row A data object (must contain checked out as a property). 133 * @param integer $i The index of the row. 134 * @param string $identifier The property name of the primary key or index of the row. 135 * 136 * @return string 137 * 138 * @since 1.5 139 */ 140 public static function checkedOut(&$row, $i, $identifier = 'id') 141 { 142 $user = Factory::getUser(); 143 $userid = $user->get('id'); 144 145 if ($row instanceof Table) { 146 $result = $row->isCheckedOut($userid); 147 } else { 148 $result = false; 149 } 150 151 if ($result) { 152 return static::_checkedOut($row); 153 } else { 154 if ($identifier === 'id') { 155 return HTMLHelper::_('grid.id', $i, $row->$identifier); 156 } else { 157 return HTMLHelper::_('grid.id', $i, $row->$identifier, $result, $identifier); 158 } 159 } 160 } 161 162 /** 163 * Method to create a clickable icon to change the state of an item 164 * 165 * @param mixed $value Either the scalar value or an object (for backward compatibility, deprecated) 166 * @param integer $i The index 167 * @param string $img1 Image for a positive or on value 168 * @param string $img0 Image for the empty or off value 169 * @param string $prefix An optional prefix for the task 170 * 171 * @return string 172 * 173 * @since 1.5 174 */ 175 public static function published($value, $i, $img1 = 'tick.png', $img0 = 'publish_x.png', $prefix = '') 176 { 177 if (is_object($value)) { 178 $value = $value->published; 179 } 180 181 $img = $value ? $img1 : $img0; 182 $task = $value ? 'unpublish' : 'publish'; 183 $alt = $value ? Text::_('JPUBLISHED') : Text::_('JUNPUBLISHED'); 184 $action = $value ? Text::_('JLIB_HTML_UNPUBLISH_ITEM') : Text::_('JLIB_HTML_PUBLISH_ITEM'); 185 186 return '<a href="#" onclick="return Joomla.listItemTask(\'cb' . $i . '\',\'' . $prefix . $task . '\')" title="' . $action . '">' 187 . HTMLHelper::_('image', 'admin/' . $img, $alt, null, true) . '</a>'; 188 } 189 190 /** 191 * Method to create a select list of states for filtering 192 * By default the filter shows only published and unpublished items 193 * 194 * @param string $filterState The initial filter state 195 * @param string $published The Text string for published 196 * @param string $unpublished The Text string for Unpublished 197 * @param string $archived The Text string for Archived 198 * @param string $trashed The Text string for Trashed 199 * 200 * @return string 201 * 202 * @since 1.5 203 */ 204 public static function state($filterState = '*', $published = 'JPUBLISHED', $unpublished = 'JUNPUBLISHED', $archived = null, $trashed = null) 205 { 206 $state = array('' => '- ' . Text::_('JLIB_HTML_SELECT_STATE') . ' -', 'P' => Text::_($published), 'U' => Text::_($unpublished)); 207 208 if ($archived) { 209 $state['A'] = Text::_($archived); 210 } 211 212 if ($trashed) { 213 $state['T'] = Text::_($trashed); 214 } 215 216 return HTMLHelper::_( 217 'select.genericlist', 218 $state, 219 'filter_state', 220 array( 221 'list.attr' => 'class="form-select" size="1" onchange="Joomla.submitform();"', 222 'list.select' => $filterState, 223 'option.key' => null, 224 ) 225 ); 226 } 227 228 /** 229 * Method to create an icon for saving a new ordering in a grid 230 * 231 * @param array $rows The array of rows of rows 232 * @param string $image The image [UNUSED] 233 * @param string $task The task to use, defaults to save order 234 * 235 * @return string 236 * 237 * @since 1.5 238 */ 239 public static function order($rows, $image = 'filesave.png', $task = 'saveorder') 240 { 241 return '<a href="javascript:saveorder(' 242 . (count($rows) - 1) . ', \'' . $task . '\')" rel="tooltip" class="saveorder btn btn-sm btn-secondary float-end" title="' 243 . Text::_('JLIB_HTML_SAVE_ORDER') . '"><span class="icon-sort"></span></a>'; 244 } 245 246 /** 247 * Method to create a checked out icon with optional overlib in a grid. 248 * 249 * @param object $row The row object 250 * @param boolean $overlib True if an overlib with checkout information should be created. 251 * 252 * @return string HTMl for the icon and overlib 253 * 254 * @since 1.5 255 */ 256 protected static function _checkedOut(&$row, $overlib = true) 257 { 258 $hover = ''; 259 260 if ($overlib) { 261 $date = HTMLHelper::_('date', $row->checked_out_time, Text::_('DATE_FORMAT_LC1')); 262 $time = HTMLHelper::_('date', $row->checked_out_time, 'H:i'); 263 264 $hover = '<span class="editlinktip hasTooltip" title="' . HTMLHelper::_('tooltipText', 'JLIB_HTML_CHECKED_OUT', $row->editor) 265 . '<br>' . $date . '<br>' . $time . '">'; 266 } 267 268 return $hover . HTMLHelper::_('image', 'admin/checked_out.png', null, null, true) . '</span>'; 269 } 270 }
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 |