raw.php
8.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
<?php
/**
* @package FrameworkOnFramework
* @subpackage view
* @copyright Copyright (C) 2010-2016 Nicholas K. Dionysopoulos / Akeeba Ltd. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
// Protect from unauthorized access
defined('FOF_INCLUDED') or die;
/**
* FrameworkOnFramework raw output class. It works like an HTML view, but the
* output is bare HTML.
*
* @package FrameworkOnFramework
* @since 2.1
*/
class FOFViewRaw extends FOFView
{
/** @var array Data lists */
protected $lists = null;
/** @var array Permissions map */
protected $perms = null;
/**
* Class constructor
*
* @param array $config Configuration parameters
*/
public function __construct($config = array())
{
// Make sure $config is an array
if (is_object($config))
{
$config = (array) $config;
}
elseif (!is_array($config))
{
$config = array();
}
parent::__construct($config);
$this->config = $config;
// Get the input
if (array_key_exists('input', $config))
{
if ($config['input'] instanceof FOFInput)
{
$this->input = $config['input'];
}
else
{
$this->input = new FOFInput($config['input']);
}
}
else
{
$this->input = new FOFInput;
}
if (!array_key_exists('option', $this->config))
{
$this->config['option'] = $this->input->getCmd('option', 'com_foobar');
}
if (!array_key_exists('view', $this->config))
{
$this->config['view'] = $this->input->getCmd('view', 'cpanel');
}
$this->lists = new FOFUtilsObject;
if (!FOFPlatform::getInstance()->isCli())
{
$platform = FOFPlatform::getInstance();
$perms = (object) array(
'create' => $platform->authorise('core.create' , $this->input->getCmd('option', 'com_foobar')),
'edit' => $platform->authorise('core.edit' , $this->input->getCmd('option', 'com_foobar')),
'editown' => $platform->authorise('core.edit.own' , $this->input->getCmd('option', 'com_foobar')),
'editstate' => $platform->authorise('core.edit.state' , $this->input->getCmd('option', 'com_foobar')),
'delete' => $platform->authorise('core.delete' , $this->input->getCmd('option', 'com_foobar')),
);
$this->aclperms = $perms;
$this->perms = $perms;
}
}
/**
* Displays the view
*
* @param string $tpl The template to use
*
* @return boolean|null False if we can't render anything
*/
public function display($tpl = null)
{
// Get the task set in the model
$model = $this->getModel();
$task = $model->getState('task', 'browse');
// Call the relevant method
$method_name = 'on' . ucfirst($task);
if (method_exists($this, $method_name))
{
$result = $this->$method_name($tpl);
}
else
{
$result = $this->onDisplay();
}
if ($result === false)
{
return;
}
// Show the view
if ($this->doPreRender)
{
$this->preRender();
}
parent::display($tpl);
if ($this->doPostRender)
{
$this->postRender();
}
}
/**
* Last chance to output something before rendering the view template
*
* @return void
*/
protected function preRender()
{
}
/**
* Last chance to output something after rendering the view template and
* before returning to the caller
*
* @return void
*/
protected function postRender()
{
}
/**
* Executes before rendering the page for the Browse task.
*
* @param string $tpl Subtemplate to use
*
* @return boolean Return true to allow rendering of the page
*/
protected function onBrowse($tpl = null)
{
// When in interactive browsing mode, save the state to the session
$this->getModel()->savestate(1);
return $this->onDisplay($tpl);
}
/**
* Executes before rendering a generic page, default to actions necessary
* for the Browse task.
*
* @param string $tpl Subtemplate to use
*
* @return boolean Return true to allow rendering of the page
*/
protected function onDisplay($tpl = null)
{
$view = $this->input->getCmd('view', 'cpanel');
if (in_array($view, array('cpanel', 'cpanels')))
{
return;
}
// Load the model
$model = $this->getModel();
// ...ordering
$this->lists->set('order', $model->getState('filter_order', 'id', 'cmd'));
$this->lists->set('order_Dir', $model->getState('filter_order_Dir', 'DESC', 'cmd'));
// Assign data to the view
$this->items = $model->getItemList();
$this->pagination = $model->getPagination();
// Pass page params on frontend only
if (FOFPlatform::getInstance()->isFrontend())
{
$params = JFactory::getApplication()->getParams();
$this->params = $params;
}
return true;
}
/**
* Executes before rendering the page for the Add task.
*
* @param string $tpl Subtemplate to use
*
* @return boolean Return true to allow rendering of the page
*/
protected function onAdd($tpl = null)
{
JRequest::setVar('hidemainmenu', true);
$model = $this->getModel();
$this->item = $model->getItem();
return true;
}
/**
* Executes before rendering the page for the Edit task.
*
* @param string $tpl Subtemplate to use
*
* @return boolean Return true to allow rendering of the page
*/
protected function onEdit($tpl = null)
{
// This perms are used only for hestetic reasons (ie showing toolbar buttons), "real" checks
// are made by the controller
// It seems that I can't edit records, maybe I can edit only this one due asset tracking?
if (!$this->perms->edit || !$this->perms->editown)
{
$model = $this->getModel();
if($model)
{
$table = $model->getTable();
// Ok, record is tracked, let's see if I can this record
if($table->isAssetsTracked())
{
$platform = FOFPlatform::getInstance();
if(!$this->perms->edit)
{
$this->perms->edit = $platform->authorise('core.edit', $table->getAssetName());
}
if(!$this->perms->editown)
{
$this->perms->editown = $platform->authorise('core.edit.own', $table->getAssetName());
}
}
}
}
return $this->onAdd($tpl);
}
/**
* Executes before rendering the page for the Read task.
*
* @param string $tpl Subtemplate to use
*
* @return boolean Return true to allow rendering of the page
*/
protected function onRead($tpl = null)
{
// All I need is to read the record
return $this->onAdd($tpl);
}
/**
* Determines if the current Joomla! version and your current table support
* AJAX-powered drag and drop reordering. If they do, it will set up the
* drag & drop reordering feature.
*
* @return boolean|array False if not suported, a table with necessary
* information (saveOrder: should you enabled DnD
* reordering; orderingColumn: which column has the
* ordering information).
*/
public function hasAjaxOrderingSupport()
{
if (version_compare(JVERSION, '3.0', 'lt'))
{
return false;
}
$model = $this->getModel();
if (!method_exists($model, 'getTable'))
{
return false;
}
$table = $this->getModel()->getTable();
if (!method_exists($table, 'getColumnAlias') || !method_exists($table, 'getTableFields'))
{
return false;
}
$orderingColumn = $table->getColumnAlias('ordering');
$fields = $table->getTableFields();
if (!is_array($fields) || !array_key_exists($orderingColumn, $fields))
{
return false;
}
$listOrder = $this->escape($model->getState('filter_order', null, 'cmd'));
$listDirn = $this->escape($model->getState('filter_order_Dir', 'ASC', 'cmd'));
$saveOrder = $listOrder == $orderingColumn;
if ($saveOrder)
{
$saveOrderingUrl = 'index.php?option=' . $this->config['option'] . '&view=' . $this->config['view'] . '&task=saveorder&format=json';
JHtml::_('sortablelist.sortable', 'itemsList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
}
return array(
'saveOrder' => $saveOrder,
'orderingColumn' => $orderingColumn
);
}
/**
* Returns the internal list of useful variables to the benefit of
* FOFFormHeader fields.
*
* @return array
*
* @since 2.0
*/
public function getLists()
{
return $this->lists;
}
/**
* Returns a reference to the permissions object of this view
*
* @return stdClass
*/
public function getPerms()
{
return $this->perms;
}
}