PageRenderTime 43ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 1ms

/joomla/administrator/components/com_modules/helpers/html/modules.php

https://gitlab.com/ricardosanchez/prueba
PHP | 243 lines | 139 code | 30 blank | 74 comment | 5 complexity | b3b85015d35f547e80ff811b1cf94a7e MD5 | raw file
  1. <?php
  2. /**
  3. * @package Joomla.Administrator
  4. * @subpackage com_modules
  5. *
  6. * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved.
  7. * @license GNU General Public License version 2 or later; see LICENSE.txt
  8. */
  9. defined('_JEXEC') or die;
  10. /**
  11. * JHtml module helper class.
  12. *
  13. * @since 1.6
  14. */
  15. abstract class JHtmlModules
  16. {
  17. /**
  18. * Builds an array of template options
  19. *
  20. * @param integer $clientId The client id.
  21. * @param string $state The state of the template.
  22. *
  23. * @return array
  24. */
  25. public static function templates($clientId = 0, $state = '')
  26. {
  27. $options = array();
  28. $templates = ModulesHelper::getTemplates($clientId, $state);
  29. foreach ($templates as $template)
  30. {
  31. $options[] = JHtml::_('select.option', $template->element, $template->name);
  32. }
  33. return $options;
  34. }
  35. /**
  36. * Builds an array of template type options
  37. *
  38. * @return array
  39. */
  40. public static function types()
  41. {
  42. $options = array();
  43. $options[] = JHtml::_('select.option', 'user', 'COM_MODULES_OPTION_POSITION_USER_DEFINED');
  44. $options[] = JHtml::_('select.option', 'template', 'COM_MODULES_OPTION_POSITION_TEMPLATE_DEFINED');
  45. return $options;
  46. }
  47. /**
  48. * Builds an array of template state options
  49. *
  50. * @return array
  51. */
  52. public static function templateStates()
  53. {
  54. $options = array();
  55. $options[] = JHtml::_('select.option', '1', 'JENABLED');
  56. $options[] = JHtml::_('select.option', '0', 'JDISABLED');
  57. return $options;
  58. }
  59. /**
  60. * Returns a published state on a grid
  61. *
  62. * @param integer $value The state value.
  63. * @param integer $i The row index
  64. * @param boolean $enabled An optional setting for access control on the action.
  65. * @param string $checkbox An optional prefix for checkboxes.
  66. *
  67. * @return string The Html code
  68. *
  69. * @see JHtmlJGrid::state
  70. * @since 1.7.1
  71. */
  72. public static function state($value, $i, $enabled = true, $checkbox = 'cb')
  73. {
  74. $states = array(
  75. 1 => array(
  76. 'unpublish',
  77. 'COM_MODULES_EXTENSION_PUBLISHED_ENABLED',
  78. 'COM_MODULES_HTML_UNPUBLISH_ENABLED',
  79. 'COM_MODULES_EXTENSION_PUBLISHED_ENABLED',
  80. true,
  81. 'publish',
  82. 'publish',
  83. ),
  84. 0 => array(
  85. 'publish',
  86. 'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED',
  87. 'COM_MODULES_HTML_PUBLISH_ENABLED',
  88. 'COM_MODULES_EXTENSION_UNPUBLISHED_ENABLED',
  89. true,
  90. 'unpublish',
  91. 'unpublish',
  92. ),
  93. -1 => array(
  94. 'unpublish',
  95. 'COM_MODULES_EXTENSION_PUBLISHED_DISABLED',
  96. 'COM_MODULES_HTML_UNPUBLISH_DISABLED',
  97. 'COM_MODULES_EXTENSION_PUBLISHED_DISABLED',
  98. true,
  99. 'warning',
  100. 'warning',
  101. ),
  102. -2 => array(
  103. 'publish',
  104. 'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED',
  105. 'COM_MODULES_HTML_PUBLISH_DISABLED',
  106. 'COM_MODULES_EXTENSION_UNPUBLISHED_DISABLED',
  107. true,
  108. 'unpublish',
  109. 'unpublish',
  110. ),
  111. );
  112. return JHtml::_('jgrid.state', $states, $value, $i, 'modules.', $enabled, true, $checkbox);
  113. }
  114. /**
  115. * Display a batch widget for the module position selector.
  116. *
  117. * @param integer $clientId The client ID.
  118. * @param integer $state The state of the module (enabled, unenabled, trashed).
  119. * @param string $selectedPosition The currently selected position for the module.
  120. *
  121. * @return string The necessary positions for the widget.
  122. *
  123. * @since 2.5
  124. */
  125. public static function positions($clientId, $state = 1, $selectedPosition = '')
  126. {
  127. require_once JPATH_ADMINISTRATOR . '/components/com_templates/helpers/templates.php';
  128. $templates = array_keys(ModulesHelper::getTemplates($clientId, $state));
  129. $templateGroups = array();
  130. // Add an empty value to be able to deselect a module position
  131. $option = ModulesHelper::createOption();
  132. $templateGroups[''] = ModulesHelper::createOptionGroup('', array($option));
  133. // Add positions from templates
  134. $isTemplatePosition = false;
  135. foreach ($templates as $template)
  136. {
  137. $options = array();
  138. $positions = TemplatesHelper::getPositions($clientId, $template);
  139. if (is_array($positions))
  140. {
  141. foreach ($positions as $position)
  142. {
  143. $text = ModulesHelper::getTranslatedModulePosition($clientId, $template, $position) . ' [' . $position . ']';
  144. $options[] = ModulesHelper::createOption($position, $text);
  145. if (!$isTemplatePosition && $selectedPosition === $position)
  146. {
  147. $isTemplatePosition = true;
  148. }
  149. }
  150. $options = JArrayHelper::sortObjects($options, 'text');
  151. }
  152. $templateGroups[$template] = ModulesHelper::createOptionGroup(ucfirst($template), $options);
  153. }
  154. // Add custom position to options
  155. $customGroupText = JText::_('COM_MODULES_CUSTOM_POSITION');
  156. $editPositions = true;
  157. $customPositions = ModulesHelper::getPositions($clientId, $editPositions);
  158. $templateGroups[$customGroupText] = ModulesHelper::createOptionGroup($customGroupText, $customPositions);
  159. return $templateGroups;
  160. }
  161. /**
  162. * Get a select with the batch action options
  163. *
  164. * @return void
  165. */
  166. public static function batchOptions()
  167. {
  168. // Create the copy/move options.
  169. $options = array(
  170. JHtml::_('select.option', 'c', JText::_('JLIB_HTML_BATCH_COPY')),
  171. JHtml::_('select.option', 'm', JText::_('JLIB_HTML_BATCH_MOVE'))
  172. );
  173. echo JHtml::_('select.radiolist', $options, 'batch[move_copy]', '', 'value', 'text', 'm');
  174. }
  175. /**
  176. * Method to get the field options.
  177. *
  178. * @param integer $clientId The client ID
  179. *
  180. * @return array The field option objects.
  181. *
  182. * @since 2.5
  183. */
  184. public static function positionList($clientId = 0)
  185. {
  186. $db = JFactory::getDbo();
  187. $query = $db->getQuery(true)
  188. ->select('DISTINCT(position) as value')
  189. ->select('position as text')
  190. ->from($db->quoteName('#__modules'))
  191. ->where($db->quoteName('client_id') . ' = ' . (int) $clientId)
  192. ->order('position');
  193. // Get the options.
  194. $db->setQuery($query);
  195. try
  196. {
  197. $options = $db->loadObjectList();
  198. }
  199. catch (RuntimeException $e)
  200. {
  201. JError::raiseWarning(500, $e->getMessage());
  202. }
  203. // Pop the first item off the array if it's blank
  204. if (count($options))
  205. {
  206. if (strlen($options[0]->text) < 1)
  207. {
  208. array_shift($options);
  209. }
  210. }
  211. return $options;
  212. }
  213. }