/libraries/fof/render/abstract.php

https://github.com/pjwiseman/joomla-cms · PHP · 282 lines · 94 code · 25 blank · 163 comment · 9 complexity · 0b11c2ce7fbd90102be791c492274475 MD5 · raw file

  1. <?php
  2. /**
  3. * @package FrameworkOnFramework
  4. * @subpackage render
  5. * @copyright Copyright (C) 2010 - 2015 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
  6. * @license GNU General Public License version 2 or later; see LICENSE.txt
  7. */
  8. defined('FOF_INCLUDED') or die;
  9. /**
  10. * Abstract view renderer class. The renderer is what turns XML view templates
  11. * into actual HTML code, renders the submenu links and potentially wraps the
  12. * HTML output in a div with a component-specific ID.
  13. *
  14. * @package FrameworkOnFramework
  15. * @since 2.0
  16. */
  17. abstract class FOFRenderAbstract
  18. {
  19. /** @var int Priority of this renderer. Higher means more important */
  20. protected $priority = 50;
  21. /** @var int Is this renderer enabled? */
  22. protected $enabled = false;
  23. /**
  24. * Returns the information about this renderer
  25. *
  26. * @return object
  27. */
  28. public function getInformation()
  29. {
  30. return (object) array(
  31. 'priority' => $this->priority,
  32. 'enabled' => $this->enabled,
  33. );
  34. }
  35. /**
  36. * Echoes any HTML to show before the view template
  37. *
  38. * @param string $view The current view
  39. * @param string $task The current task
  40. * @param FOFInput $input The input array (request parameters)
  41. * @param array $config The view configuration array
  42. *
  43. * @return void
  44. */
  45. abstract public function preRender($view, $task, $input, $config = array());
  46. /**
  47. * Echoes any HTML to show after the view template
  48. *
  49. * @param string $view The current view
  50. * @param string $task The current task
  51. * @param FOFInput $input The input array (request parameters)
  52. * @param array $config The view configuration array
  53. *
  54. * @return void
  55. */
  56. abstract public function postRender($view, $task, $input, $config = array());
  57. /**
  58. * Renders a FOFForm and returns the corresponding HTML
  59. *
  60. * @param FOFForm &$form The form to render
  61. * @param FOFModel $model The model providing our data
  62. * @param FOFInput $input The input object
  63. * @param string $formType The form type: edit, browse or read
  64. * @param boolean $raw If true, the raw form fields rendering (without the surrounding form tag) is returned.
  65. *
  66. * @return string The HTML rendering of the form
  67. */
  68. public function renderForm(FOFForm &$form, FOFModel $model, FOFInput $input, $formType = null, $raw = false)
  69. {
  70. if (is_null($formType))
  71. {
  72. $formType = $form->getAttribute('type', 'edit');
  73. }
  74. else
  75. {
  76. $formType = strtolower($formType);
  77. }
  78. switch ($formType)
  79. {
  80. case 'browse':
  81. return $this->renderFormBrowse($form, $model, $input);
  82. break;
  83. case 'read':
  84. if ($raw)
  85. {
  86. return $this->renderFormRaw($form, $model, $input, 'read');
  87. }
  88. else
  89. {
  90. return $this->renderFormRead($form, $model, $input);
  91. }
  92. break;
  93. default:
  94. if ($raw)
  95. {
  96. return $this->renderFormRaw($form, $model, $input, 'edit');
  97. }
  98. else
  99. {
  100. return $this->renderFormEdit($form, $model, $input);
  101. }
  102. break;
  103. }
  104. }
  105. /**
  106. * Renders the submenu (link bar) for a category view when it is used in a
  107. * extension
  108. *
  109. * Note: this function has to be called from the addSubmenu function in
  110. * the ExtensionNameHelper class located in
  111. * administrator/components/com_ExtensionName/helpers/Extensionname.php
  112. *
  113. * Example Code:
  114. *
  115. * class ExtensionNameHelper
  116. * {
  117. * public static function addSubmenu($vName)
  118. * {
  119. * // Load FOF
  120. * include_once JPATH_LIBRARIES . '/fof/include.php';
  121. *
  122. * if (!defined('FOF_INCLUDED'))
  123. * {
  124. * JError::raiseError('500', 'FOF is not installed');
  125. * }
  126. *
  127. * if (version_compare(JVERSION, '3.0', 'ge'))
  128. * {
  129. * $strapper = new FOFRenderJoomla3;
  130. * }
  131. * else
  132. * {
  133. * $strapper = new FOFRenderJoomla;
  134. * }
  135. *
  136. * $strapper->renderCategoryLinkbar('com_babioonevent');
  137. * }
  138. * }
  139. *
  140. * @param string $extension The name of the extension
  141. * @param array $config Extra configuration variables for the toolbar
  142. *
  143. * @return void
  144. */
  145. public function renderCategoryLinkbar($extension, $config = array())
  146. {
  147. // On command line don't do anything
  148. if (FOFPlatform::getInstance()->isCli())
  149. {
  150. return;
  151. }
  152. // Do not render a category submenu unless we are in the the admin area
  153. if (!FOFPlatform::getInstance()->isBackend())
  154. {
  155. return;
  156. }
  157. $toolbar = FOFToolbar::getAnInstance($extension, $config);
  158. $toolbar->renderSubmenu();
  159. $this->renderLinkbarItems($toolbar);
  160. }
  161. /**
  162. * Renders a FOFForm for a Browse view and returns the corresponding HTML
  163. *
  164. * @param FOFForm &$form The form to render
  165. * @param FOFModel $model The model providing our data
  166. * @param FOFInput $input The input object
  167. *
  168. * @return string The HTML rendering of the form
  169. */
  170. abstract protected function renderFormBrowse(FOFForm &$form, FOFModel $model, FOFInput $input);
  171. /**
  172. * Renders a FOFForm for a Read view and returns the corresponding HTML
  173. *
  174. * @param FOFForm &$form The form to render
  175. * @param FOFModel $model The model providing our data
  176. * @param FOFInput $input The input object
  177. *
  178. * @return string The HTML rendering of the form
  179. */
  180. abstract protected function renderFormRead(FOFForm &$form, FOFModel $model, FOFInput $input);
  181. /**
  182. * Renders a FOFForm for an Edit view and returns the corresponding HTML
  183. *
  184. * @param FOFForm &$form The form to render
  185. * @param FOFModel $model The model providing our data
  186. * @param FOFInput $input The input object
  187. *
  188. * @return string The HTML rendering of the form
  189. */
  190. abstract protected function renderFormEdit(FOFForm &$form, FOFModel $model, FOFInput $input);
  191. /**
  192. * Renders a raw FOFForm and returns the corresponding HTML
  193. *
  194. * @param FOFForm &$form The form to render
  195. * @param FOFModel $model The model providing our data
  196. * @param FOFInput $input The input object
  197. * @param string $formType The form type e.g. 'edit' or 'read'
  198. *
  199. * @return string The HTML rendering of the form
  200. */
  201. abstract protected function renderFormRaw(FOFForm &$form, FOFModel $model, FOFInput $input, $formType);
  202. /**
  203. * Renders a raw fieldset of a FOFForm and returns the corresponding HTML
  204. *
  205. * @TODO: Convert to an abstract method or interface at FOF3
  206. *
  207. * @param stdClass &$fieldset The fieldset to render
  208. * @param FOFForm &$form The form to render
  209. * @param FOFModel $model The model providing our data
  210. * @param FOFInput $input The input object
  211. * @param string $formType The form type e.g. 'edit' or 'read'
  212. * @param boolean $showHeader Should I render the fieldset's header?
  213. *
  214. * @return string The HTML rendering of the fieldset
  215. */
  216. protected function renderFieldset(stdClass &$fieldset, FOFForm &$form, FOFModel $model, FOFInput $input, $formType, $showHeader = true)
  217. {
  218. }
  219. /**
  220. * Renders a label for a fieldset.
  221. *
  222. * @TODO: Convert to an abstract method or interface at FOF3
  223. *
  224. * @param object $field The field of the label to render
  225. * @param FOFForm &$form The form to render
  226. * @param string $title The title of the label
  227. *
  228. * @return string The rendered label
  229. */
  230. protected function renderFieldsetLabel($field, FOFForm &$form, $title)
  231. {
  232. }
  233. /**
  234. * Checks if the fieldset defines a tab pane
  235. *
  236. * @param SimpleXMLElement $fieldset
  237. *
  238. * @return boolean
  239. */
  240. protected function isTabFieldset($fieldset)
  241. {
  242. if (!isset($fieldset->class) || !$fieldset->class)
  243. {
  244. return false;
  245. }
  246. $class = $fieldset->class;
  247. $classes = explode(' ', $class);
  248. if (!in_array('tab-pane', $classes))
  249. {
  250. return false;
  251. }
  252. else
  253. {
  254. return in_array('active', $classes) ? 2 : 1;
  255. }
  256. }
  257. }