1 <?php
  2   3   4   5   6   7 
  8 
  9 defined('FOF_INCLUDED') or die;
 10 
 11  12  13  14  15  16  17 
 18 class FOFViewRaw extends FOFView
 19 {
 20     
 21     protected $lists = null;
 22 
 23     
 24     protected $perms = null;
 25 
 26      27  28  29  30 
 31     public function __construct($config = array())
 32     {
 33         
 34         if (is_object($config))
 35         {
 36             $config = (array) $config;
 37         }
 38         elseif (!is_array($config))
 39         {
 40             $config = array();
 41         }
 42 
 43         parent::__construct($config);
 44 
 45         $this->config = $config;
 46 
 47         
 48         if (array_key_exists('input', $config))
 49         {
 50             if ($config['input'] instanceof FOFInput)
 51             {
 52                 $this->input = $config['input'];
 53             }
 54             else
 55             {
 56                 $this->input = new FOFInput($config['input']);
 57             }
 58         }
 59         else
 60         {
 61             $this->input = new FOFInput;
 62         }
 63 
 64         if (!array_key_exists('option', $this->config))
 65         {
 66             $this->config['option'] = $this->input->getCmd('option', 'com_foobar');
 67         }
 68 
 69         if (!array_key_exists('view', $this->config))
 70         {
 71             $this->config['view'] = $this->input->getCmd('view', 'cpanel');
 72         }
 73 
 74         $this->lists = new FOFUtilsObject;
 75 
 76         if (!FOFPlatform::getInstance()->isCli())
 77         {
 78             $platform = FOFPlatform::getInstance();
 79             $perms = (object) array(
 80                     'create'     => $platform->authorise('core.create'     , $this->input->getCmd('option', 'com_foobar')),
 81                     'edit'       => $platform->authorise('core.edit'       , $this->input->getCmd('option', 'com_foobar')),
 82                     'editown'    => $platform->authorise('core.edit.own'   , $this->input->getCmd('option', 'com_foobar')),
 83                     'editstate'  => $platform->authorise('core.edit.state' , $this->input->getCmd('option', 'com_foobar')),
 84                     'delete'     => $platform->authorise('core.delete'     , $this->input->getCmd('option', 'com_foobar')),
 85             );
 86 
 87             $this->aclperms = $perms;
 88             $this->perms    = $perms;
 89         }
 90     }
 91 
 92      93  94  95  96  97  98 
 99     public function display($tpl = null)
100     {
101         
102         $model = $this->getModel();
103         $task = $model->getState('task', 'browse');
104 
105         
106         $method_name = 'on' . ucfirst($task);
107 
108         if (method_exists($this, $method_name))
109         {
110             $result = $this->$method_name($tpl);
111         }
112         else
113         {
114             $result = $this->onDisplay();
115         }
116 
117         if ($result === false)
118         {
119             return;
120         }
121 
122         
123         if ($this->doPreRender)
124         {
125             $this->preRender();
126         }
127 
128         parent::display($tpl);
129 
130         if ($this->doPostRender)
131         {
132             $this->postRender();
133         }
134     }
135 
136     137 138 139 140 
141     protected function preRender()
142     {
143     }
144 
145     146 147 148 149 150 
151     protected function postRender()
152     {
153     }
154 
155     156 157 158 159 160 161 
162     protected function onBrowse($tpl = null)
163     {
164         
165         $this->getModel()->savestate(1);
166 
167         return $this->onDisplay($tpl);
168     }
169 
170     171 172 173 174 175 176 177 
178     protected function onDisplay($tpl = null)
179     {
180         $view = $this->input->getCmd('view', 'cpanel');
181 
182         if (in_array($view, array('cpanel', 'cpanels')))
183         {
184             return;
185         }
186 
187         
188         $model = $this->getModel();
189 
190         
191         $this->lists->set('order', $model->getState('filter_order', 'id', 'cmd'));
192         $this->lists->set('order_Dir', $model->getState('filter_order_Dir', 'DESC', 'cmd'));
193 
194         
195         $this->items      = $model->getItemList();
196         $this->pagination = $model->getPagination();
197 
198         
199         if (FOFPlatform::getInstance()->isFrontend())
200         {
201             $params = JFactory::getApplication()->getParams();
202             $this->params = $params;
203         }
204 
205         return true;
206     }
207 
208     209 210 211 212 213 214 
215     protected function onAdd($tpl = null)
216     {
217         JRequest::setVar('hidemainmenu', true);
218         $model = $this->getModel();
219         $this->item = $model->getItem();
220 
221         return true;
222     }
223 
224     225 226 227 228 229 230 
231     protected function onEdit($tpl = null)
232     {
233         
234         
235         
236         if (!$this->perms->edit || !$this->perms->editown)
237         {
238             $model = $this->getModel();
239 
240             if($model)
241             {
242                 $table = $model->getTable();
243 
244                 
245                 if($table->isAssetsTracked())
246                 {
247                     $platform = FOFPlatform::getInstance();
248 
249                     if(!$this->perms->edit)
250                     {
251                         $this->perms->edit = $platform->authorise('core.edit', $table->getAssetName());
252                     }
253 
254                     if(!$this->perms->editown)
255                     {
256                         $this->perms->editown = $platform->authorise('core.edit.own', $table->getAssetName());
257                     }
258                 }
259             }
260         }
261 
262         return $this->onAdd($tpl);
263     }
264 
265     266 267 268 269 270 271 
272     protected function onRead($tpl = null)
273     {
274         
275 
276         return $this->onAdd($tpl);
277     }
278 
279     280 281 282 283 284 285 286 287 288 
289     public function hasAjaxOrderingSupport()
290     {
291         if (version_compare(JVERSION, '3.0', 'lt'))
292         {
293             return false;
294         }
295 
296         $model = $this->getModel();
297 
298         if (!method_exists($model, 'getTable'))
299         {
300             return false;
301         }
302 
303         $table = $this->getModel()->getTable();
304 
305         if (!method_exists($table, 'getColumnAlias') || !method_exists($table, 'getTableFields'))
306         {
307             return false;
308         }
309 
310         $orderingColumn = $table->getColumnAlias('ordering');
311         $fields = $table->getTableFields();
312 
313         if (!is_array($fields) || !array_key_exists($orderingColumn, $fields))
314         {
315             return false;
316         }
317 
318         $listOrder = $this->escape($model->getState('filter_order', null, 'cmd'));
319         $listDirn = $this->escape($model->getState('filter_order_Dir', 'ASC', 'cmd'));
320         $saveOrder = $listOrder == $orderingColumn;
321 
322         if ($saveOrder)
323         {
324             $saveOrderingUrl = 'index.php?option=' . $this->config['option'] . '&view=' . $this->config['view'] . '&task=saveorder&format=json';
325             JHtml::_('sortablelist.sortable', 'itemsList', 'adminForm', strtolower($listDirn), $saveOrderingUrl);
326         }
327 
328         return array(
329             'saveOrder'      => $saveOrder,
330             'orderingColumn' => $orderingColumn
331         );
332     }
333 
334     335 336 337 338 339 340 341 
342     public function getLists()
343     {
344         return $this->lists;
345     }
346 
347     348 349 350 351 
352     public function getPerms()
353     {
354         return $this->perms;
355     }
356 }
357