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