[ Index ] |
PHP Cross Reference of Joomla 4.2.2 documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * @package Joomla.Administrator 5 * @subpackage com_modules 6 * 7 * @copyright (C) 2010 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\Modules\Administrator\Service\HTML; 12 13 use Joomla\CMS\Factory; 14 use Joomla\CMS\HTML\HTMLHelper; 15 use Joomla\CMS\Language\Text; 16 use Joomla\Component\Modules\Administrator\Helper\ModulesHelper; 17 use Joomla\Component\Templates\Administrator\Helper\TemplatesHelper; 18 use Joomla\Database\ParameterType; 19 use Joomla\Utilities\ArrayHelper; 20 21 // phpcs:disable PSR1.Files.SideEffects 22 \defined('_JEXEC') or die; 23 // phpcs:enable PSR1.Files.SideEffects 24 25 /** 26 * HTMLHelper module helper class. 27 * 28 * @since 1.6 29 */ 30 class Modules 31 { 32 /** 33 * Builds an array of template options 34 * 35 * @param integer $clientId The client id. 36 * @param string $state The state of the template. 37 * 38 * @return array 39 */ 40 public function templates($clientId = 0, $state = '') 41 { 42 $options = array(); 43 $templates = ModulesHelper::getTemplates($clientId, $state); 44 45 foreach ($templates as $template) { 46 $options[] = HTMLHelper::_('select.option', $template->element, $template->name); 47 } 48 49 return $options; 50 } 51 52 /** 53 * Builds an array of template type options 54 * 55 * @return array 56 */ 57 public function types() 58 { 59 $options = array(); 60 $options[] = HTMLHelper::_('select.option', 'user', 'COM_MODULES_OPTION_POSITION_USER_DEFINED'); 61 $options[] = HTMLHelper::_('select.option', 'template', 'COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED'); 62 63 return $options; 64 } 65 66 /** 67 * Builds an array of template state options 68 * 69 * @return array 70 */ 71 public function templateStates() 72 { 73 $options = array(); 74 $options[] = HTMLHelper::_('select.option', '1', 'JENABLED'); 75 $options[] = HTMLHelper::_('select.option', '0', 'JDISABLED'); 76 77 return $options; 78 } 79 80 /** 81 * Returns a published state on a grid 82 * 83 * @param integer $value The state value. 84 * @param integer $i The row index 85 * @param boolean $enabled An optional setting for access control on the action. 86 * @param string $checkbox An optional prefix for checkboxes. 87 * 88 * @return string The Html code 89 * 90 * @see HTMLHelperJGrid::state 91 * @since 1.7.1 92 */ 93 public function state($value, $i, $enabled = true, $checkbox = 'cb') 94 { 95 $states = array( 96 1 => array( 97 'unpublish', 98 'COM_MODULES_EXTENSION_PUBLISHED_ENABLED', 99 'COM_MODULES_HTML_UNPUBLISH_ENABLED', 100 'COM_MODULES_EXTENSION_PUBLISHED_ENABLED', 101 true, 102 'publish', 103 'publish', 104 ), 105 0 => array( 106 'publish', 107 'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED', 108 'COM_MODULES_HTML_PUBLISH_ENABLED', 109 'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED', 110 true, 111 'unpublish', 112 'unpublish', 113 ), 114 -1 => array( 115 'unpublish', 116 'COM_MODULES_EXTENSION_PUBLISHED_DISABLED', 117 'COM_MODULES_HTML_UNPUBLISH_DISABLED', 118 'COM_MODULES_EXTENSION_PUBLISHED_DISABLED', 119 true, 120 'warning', 121 'warning', 122 ), 123 -2 => array( 124 'publish', 125 'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED', 126 'COM_MODULES_HTML_PUBLISH_DISABLED', 127 'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED', 128 true, 129 'unpublish', 130 'unpublish', 131 ), 132 ); 133 134 return HTMLHelper::_('jgrid.state', $states, $value, $i, 'modules.', $enabled, true, $checkbox); 135 } 136 137 /** 138 * Display a batch widget for the module position selector. 139 * 140 * @param integer $clientId The client ID. 141 * @param integer $state The state of the module (enabled, unenabled, trashed). 142 * @param string $selectedPosition The currently selected position for the module. 143 * 144 * @return string The necessary positions for the widget. 145 * 146 * @since 2.5 147 */ 148 public function positions($clientId, $state = 1, $selectedPosition = '') 149 { 150 $templates = array_keys(ModulesHelper::getTemplates($clientId, $state)); 151 $templateGroups = array(); 152 153 // Add an empty value to be able to deselect a module position 154 $option = ModulesHelper::createOption('', Text::_('COM_MODULES_NONE')); 155 $templateGroups[''] = ModulesHelper::createOptionGroup('', array($option)); 156 157 // Add positions from templates 158 $isTemplatePosition = false; 159 160 foreach ($templates as $template) { 161 $options = array(); 162 163 $positions = TemplatesHelper::getPositions($clientId, $template); 164 165 if (is_array($positions)) { 166 foreach ($positions as $position) { 167 $text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']'; 168 $options[] = ModulesHelper::createOption($position, $text); 169 170 if (!$isTemplatePosition && $selectedPosition === $position) { 171 $isTemplatePosition = true; 172 } 173 } 174 175 $options = ArrayHelper::sortObjects($options, 'text'); 176 } 177 178 $templateGroups[$template] = ModulesHelper::createOptionGroup(ucfirst($template), $options); 179 } 180 181 // Add custom position to options 182 $customGroupText = Text::_('COM_MODULES_CUSTOM_POSITION'); 183 $editPositions = true; 184 $customPositions = ModulesHelper::getPositions($clientId, $editPositions); 185 186 $app = Factory::getApplication(); 187 188 $position = $app->getUserState('com_modules.modules.' . $clientId . '.filter.position'); 189 190 if ($position) { 191 $customPositions[] = HTMLHelper::_('select.option', $position); 192 193 $customPositions = array_unique($customPositions, SORT_REGULAR); 194 } 195 196 $templateGroups[$customGroupText] = ModulesHelper::createOptionGroup($customGroupText, $customPositions); 197 198 return $templateGroups; 199 } 200 201 /** 202 * Get a select with the batch action options 203 * 204 * @return void 205 */ 206 public function batchOptions() 207 { 208 // Create the copy/move options. 209 $options = array( 210 HTMLHelper::_('select.option', 'c', Text::_('JLIB_HTML_BATCH_COPY')), 211 HTMLHelper::_('select.option', 'm', Text::_('JLIB_HTML_BATCH_MOVE')) 212 ); 213 214 echo HTMLHelper::_('select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm'); 215 } 216 217 /** 218 * Method to get the field options. 219 * 220 * @param integer $clientId The client ID 221 * 222 * @return array The field option objects. 223 * 224 * @since 2.5 225 * 226 * @deprecated 5.0 Will be removed with no replacement 227 */ 228 public function positionList($clientId = 0) 229 { 230 $clientId = (int) $clientId; 231 $db = Factory::getDbo(); 232 $query = $db->getQuery(true) 233 ->select('DISTINCT ' . $db->quoteName('position', 'value')) 234 ->select($db->quoteName('position', 'text')) 235 ->from($db->quoteName('#__modules')) 236 ->where($db->quoteName('client_id') . ' = :clientid') 237 ->order($db->quoteName('position')) 238 ->bind(':clientid', $clientId, ParameterType::INTEGER); 239 240 // Get the options. 241 $db->setQuery($query); 242 243 try { 244 $options = $db->loadObjectList(); 245 } catch (\RuntimeException $e) { 246 Factory::getApplication()->enqueueMessage($e->getMessage(), 'error'); 247 } 248 249 // Pop the first item off the array if it's blank 250 if (count($options)) { 251 if (strlen($options[0]->text) < 1) { 252 array_shift($options); 253 } 254 } 255 256 return $options; 257 } 258 }
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 |