Completed
Push — master ( 2a36d1...bf34f3 )
by Michael
03:21
created
class/smartobjecthandler.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
     /**
191 191
      * @param $criteria
192
-     * @param $perm_name
192
+     * @param boolean $perm_name
193 193
      * @return bool
194 194
      */
195 195
     public function setGrantedObjectsCriteria(&$criteria, $perm_name)
@@ -383,7 +383,7 @@  discard block
 block discarded – undo
383 383
     }
384 384
 
385 385
     /**
386
-     * @param        $sql
386
+     * @param        string $sql
387 387
      * @param        $criteria
388 388
      * @param  bool  $force
389 389
      * @param  bool  $debug
Please login to merge, or discard this patch.
Indentation   +976 added lines, -976 removed lines patch added patch discarded remove patch
@@ -25,980 +25,980 @@
 block discarded – undo
25 25
  */
26 26
 class SmartPersistableObjectHandler extends XoopsObjectHandler
27 27
 {
28
-    public $_itemname;
29
-
30
-    /**
31
-     * Name of the table use to store this {@link SmartObject}
32
-     *
33
-     * Note that the name of the table needs to be free of the database prefix.
34
-     * For example "smartsection_categories"
35
-     * @var string
36
-     */
37
-    public $table;
38
-
39
-    /**
40
-     * Name of the table key that uniquely identify each {@link SmartObject}
41
-     *
42
-     * For example: "categoryid"
43
-     * @var string
44
-     */
45
-    public $keyName;
46
-
47
-    /**
48
-     * Name of the class derived from {@link SmartObject} and which this handler is handling
49
-     *
50
-     * Note that this string needs to be lowercase
51
-     *
52
-     * For example: "smartsectioncategory"
53
-     * @var string
54
-     */
55
-    public $className;
56
-
57
-    /**
58
-     * Name of the field which properly identify the {@link SmartObject}
59
-     *
60
-     * For example: "name" (this will be the category's name)
61
-     * @var string
62
-     */
63
-    public $identifierName;
64
-
65
-    /**
66
-     * Name of the field which will be use as a summary for the object
67
-     *
68
-     * For example: "summary"
69
-     * @var string
70
-     */
71
-    public $summaryName;
72
-
73
-    /**
74
-     * Page name use to basically manage and display the {@link SmartObject}
75
-     *
76
-     * This page needs to be the same in user side and admin side
77
-     *
78
-     * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
79
-     * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
80
-     * @var string
81
-     */
82
-    public $_page;
83
-
84
-    /**
85
-     * Full path of the module using this {@link SmartObject}
86
-     *
87
-     * <code>XOOPS_URL . "/modules/smartsection/"</code>
88
-     * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
89
-     * @var string
90
-     */
91
-    public $_modulePath;
92
-
93
-    public $_moduleUrl;
94
-
95
-    public $_moduleName;
96
-
97
-    public $_uploadUrl;
98
-
99
-    public $_uploadPath;
100
-
101
-    public $_allowedMimeTypes = 0;
102
-
103
-    public $_maxFileSize = 1000000;
104
-
105
-    public $_maxWidth = 500;
106
-
107
-    public $_maxHeight = 500;
108
-
109
-    public $highlightFields = [];
110
-
111
-    /**
112
-     * Array containing the events name and functions
113
-     *
114
-     * @var array
115
-     */
116
-    public $eventArray = [];
117
-
118
-    /**
119
-     * Array containing the permissions that this handler will manage on the objects
120
-     *
121
-     * @var array
122
-     */
123
-    public $permissionsArray = false;
124
-
125
-    public $generalSQL = false;
126
-
127
-    public $_eventHooks     = [];
128
-    public $_disabledEvents = [];
129
-
130
-    /**
131
-     * Constructor - called from child classes
132
-     *
133
-     * @param XoopsDatabase $db           {@link XoopsDatabase}
134
-     * @param string        $itemname     Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
135
-     * @param string        $keyname      Name of the table key that uniquely identify each {@link SmartObject}
136
-     * @param string        $idenfierName Name of the field which properly identify the {@link SmartObject}
137
-     * @param string        $summaryName
138
-     * @param string        $modulename
139
-     * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
140
-     * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
141
-     * @internal param string $moduleName name of the module
142
-     */
143
-    public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
144
-    {
145
-        parent::__construct($db);
146
-
147
-        $this->_itemname      = $itemname;
148
-        $this->_moduleName    = $modulename;
149
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
150
-        $this->keyName        = $keyname;
151
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
152
-        $this->identifierName = $idenfierName;
153
-        $this->summaryName    = $summaryName;
154
-        $this->_page          = $itemname . '.php';
155
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
156
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
157
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
158
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
159
-    }
160
-
161
-    /**
162
-     * @param $event
163
-     * @param $method
164
-     */
165
-    public function addEventHook($event, $method)
166
-    {
167
-        $this->_eventHooks[$event] = $method;
168
-    }
169
-
170
-    /**
171
-     * Add a permission that this handler will manage for its objects
172
-     *
173
-     * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
174
-     *
175
-     * @param string      $perm_name   name of the permission
176
-     * @param string      $caption     caption of the control that will be displayed in the form
177
-     * @param bool|string $description description of the control that will be displayed in the form
178
-     */
179
-    public function addPermission($perm_name, $caption, $description = false)
180
-    {
181
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
182
-
183
-        $this->permissionsArray[] = [
184
-            'perm_name'   => $perm_name,
185
-            'caption'     => $caption,
186
-            'description' => $description
187
-        ];
188
-    }
189
-
190
-    /**
191
-     * @param $criteria
192
-     * @param $perm_name
193
-     * @return bool
194
-     */
195
-    public function setGrantedObjectsCriteria(&$criteria, $perm_name)
196
-    {
197
-        $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
198
-        $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
199
-        if (count($grantedItems) > 0) {
200
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
201
-
202
-            return true;
203
-        } else {
204
-            return false;
205
-        }
206
-    }
207
-
208
-    /**
209
-     * @param bool $_uploadPath
210
-     * @param bool $_allowedMimeTypes
211
-     * @param bool $_maxFileSize
212
-     * @param bool $_maxWidth
213
-     * @param bool $_maxHeight
214
-     */
215
-    public function setUploaderConfig(
216
-        $_uploadPath = false,
217
-        $_allowedMimeTypes = false,
218
-        $_maxFileSize = false,
219
-        $_maxWidth = false,
220
-        $_maxHeight = false
221
-    ) {
222
-        $this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
223
-        $this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
224
-        $this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
225
-        $this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
226
-        $this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
227
-    }
228
-
229
-    /**
230
-     * create a new {@link SmartObject}
231
-     *
232
-     * @param bool $isNew Flag the new objects as "new"?
233
-     *
234
-     * @return SmartObject {@link SmartObject}
235
-     */
236
-    public function create($isNew = true)
237
-    {
238
-        $obj = new $this->className($this);
239
-        $obj->setImageDir($this->getImageUrl(), $this->getImagePath());
240
-        if (!$obj->handler) {
241
-            $obj->Handler = $this;
242
-        }
243
-
244
-        if ($isNew === true) {
245
-            $obj->setNew();
246
-        }
247
-
248
-        return $obj;
249
-    }
250
-
251
-    /**
252
-     * @return string
253
-     */
254
-    public function getImageUrl()
255
-    {
256
-        return $this->_uploadUrl . $this->_itemname . '/';
257
-    }
258
-
259
-    /**
260
-     * @return string
261
-     */
262
-    public function getImagePath()
263
-    {
264
-        $dir = $this->_uploadPath . $this->_itemname;
265
-        if (!file_exists($dir)) {
266
-            smart_admin_mkdir($dir);
267
-        }
268
-
269
-        return $dir . '/';
270
-    }
271
-
272
-    /**
273
-     * retrieve a {@link SmartObject}
274
-     *
275
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
276
-     * @param  bool  $as_object whether to return an object or an array
277
-     * @param  bool  $debug
278
-     * @param  bool  $criteria
279
-     * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
280
-     *                          FALSE if failed
281
-     */
282
-    public function get($id, $as_object = true, $debug = false, $criteria = false)
283
-    {
284
-        if (!$criteria) {
285
-            $criteria = new CriteriaCompo();
286
-        }
287
-        if (is_array($this->keyName)) {
288
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
289
-                /**
290
-                 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
291
-                 * Is the fact that we removed the (int)() represents a security risk ?
292
-                 */
293
-                //$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
294
-                $criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
295
-            }
296
-        } else {
297
-            //$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname);
298
-            /**
299
-             * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
300
-             * Is the fact that we removed the (int)() represents a security risk ?
301
-             */
302
-            $criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
303
-        }
304
-        $criteria->setLimit(1);
305
-        if ($debug) {
306
-            $obj_array = $this->getObjectsD($criteria, false, $as_object);
307
-        } else {
308
-            $obj_array = $this->getObjects($criteria, false, $as_object);
309
-            //patch: weird bug of indexing by id even if id_as_key = false;
310
-            if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
311
-                $obj_array[0] = $obj_array[$id];
312
-                unset($obj_array[$id]);
313
-                $obj_array[0]->unsetNew();
314
-            }
315
-        }
316
-
317
-        if (count($obj_array) != 1) {
318
-            $obj = $this->create();
319
-
320
-            return $obj;
321
-        }
322
-
323
-        return $obj_array[0];
324
-    }
325
-
326
-    /**
327
-     * retrieve a {@link SmartObject}
328
-     *
329
-     * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
330
-     * @param  bool  $as_object whether to return an object or an array
331
-     * @return mixed reference to the {@link SmartObject}, FALSE if failed
332
-     */
333
-    public function &getD($id, $as_object = true)
334
-    {
335
-        return $this->get($id, $as_object, true);
336
-    }
337
-
338
-    /**
339
-     * retrieve objects from the database
340
-     *
341
-     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
342
-     * @param bool            $id_as_key use the ID as key for the array?
343
-     * @param bool            $as_object return an array of objects?
344
-     *
345
-     * @param  bool           $sql
346
-     * @param  bool           $debug
347
-     * @return array
348
-     */
349
-    public function getObjects(
350
-        CriteriaElement $criteria = null,
351
-        $id_as_key = false,
352
-        $as_object = true,
353
-        $sql = false,
354
-        $debug = false
355
-    ) {
356
-        $ret   = [];
357
-        $limit = $start = 0;
358
-
359
-        if ($this->generalSQL) {
360
-            $sql = $this->generalSQL;
361
-        } elseif (!$sql) {
362
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
363
-        }
364
-
365
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
366
-            $sql .= ' ' . $criteria->renderWhere();
367
-            if ($criteria->getSort() !== '') {
368
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
369
-            }
370
-            $limit = $criteria->getLimit();
371
-            $start = $criteria->getStart();
372
-        }
373
-        if ($debug) {
374
-            xoops_debug($sql);
375
-        }
376
-
377
-        $result = $this->db->query($sql, $limit, $start);
378
-        if (!$result) {
379
-            return $ret;
380
-        }
381
-
382
-        return $this->convertResultSet($result, $id_as_key, $as_object);
383
-    }
384
-
385
-    /**
386
-     * @param        $sql
387
-     * @param        $criteria
388
-     * @param  bool  $force
389
-     * @param  bool  $debug
390
-     * @return array
391
-     */
392
-    public function query($sql, $criteria, $force = false, $debug = false)
393
-    {
394
-        $ret = [];
395
-
396
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
397
-            $sql .= ' ' . $criteria->renderWhere();
398
-            if ($criteria->groupby) {
399
-                $sql .= $criteria->getGroupby();
400
-            }
401
-            if ($criteria->getSort() !== '') {
402
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
403
-            }
404
-        }
405
-        if ($debug) {
406
-            xoops_debug($sql);
407
-        }
408
-
409
-        if ($force) {
410
-            $result = $this->db->queryF($sql);
411
-        } else {
412
-            $result = $this->db->query($sql);
413
-        }
414
-
415
-        if (!$result) {
416
-            return $ret;
417
-        }
418
-
419
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
420
-            $ret[] = $myrow;
421
-        }
422
-
423
-        return $ret;
424
-    }
425
-
426
-    /**
427
-     * retrieve objects with debug mode - so will show the query
428
-     *
429
-     * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
430
-     * @param bool            $id_as_key use the ID as key for the array?
431
-     * @param bool            $as_object return an array of objects?
432
-     *
433
-     * @param  bool           $sql
434
-     * @return array
435
-     */
436
-    public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
437
-    {
438
-        return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
439
-    }
440
-
441
-    /**
442
-     * @param $arrayObjects
443
-     * @return array|bool
444
-     */
445
-    public function getObjectsAsArray($arrayObjects)
446
-    {
447
-        $ret = [];
448
-        foreach ($arrayObjects as $key => $object) {
449
-            $ret[$key] = $object->toArray();
450
-        }
451
-        if (count($ret > 0)) {
452
-            return $ret;
453
-        } else {
454
-            return false;
455
-        }
456
-    }
457
-
458
-    /**
459
-     * Convert a database resultset to a returnable array
460
-     *
461
-     * @param object $result    database resultset
462
-     * @param bool   $id_as_key - should NOT be used with joint keys
463
-     * @param bool   $as_object
464
-     *
465
-     * @return array
466
-     */
467
-    public function convertResultSet($result, $id_as_key = false, $as_object = true)
468
-    {
469
-        $ret = [];
470
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
471
-            $obj = $this->create(false);
472
-            $obj->assignVars($myrow);
473
-            if (!$id_as_key) {
474
-                if ($as_object) {
475
-                    $ret[] =& $obj;
476
-                } else {
477
-                    $ret[] = $obj->toArray();
478
-                }
479
-            } else {
480
-                if ($as_object) {
481
-                    $value =& $obj;
482
-                } else {
483
-                    $value = $obj->toArray();
484
-                }
485
-                if ($id_as_key === 'parentid') {
486
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
487
-                } else {
488
-                    $ret[$obj->getVar($this->keyName)] = $value;
489
-                }
490
-            }
491
-            unset($obj);
492
-        }
493
-
494
-        return $ret;
495
-    }
496
-
497
-    /**
498
-     * @param  null $criteria
499
-     * @param  int  $limit
500
-     * @param  int  $start
501
-     * @return array
502
-     */
503
-    public function getListD($criteria = null, $limit = 0, $start = 0)
504
-    {
505
-        return $this->getList($criteria, $limit, $start, true);
506
-    }
507
-
508
-    /**
509
-     * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
510
-     *
511
-     * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
512
-     * @param int             $limit    Max number of objects to fetch
513
-     * @param int             $start    Which record to start at
514
-     *
515
-     * @param  bool           $debug
516
-     * @return array
517
-     */
518
-    public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
519
-    {
520
-        $ret = [];
521
-        if ($criteria === null) {
522
-            $criteria = new CriteriaCompo();
523
-        }
524
-
525
-        if ($criteria->getSort() === '') {
526
-            $criteria->setSort($this->getIdentifierName());
527
-        }
528
-
529
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
530
-        if (!empty($this->identifierName)) {
531
-            $sql .= ', ' . $this->getIdentifierName();
532
-        }
533
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
534
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
535
-            $sql .= ' ' . $criteria->renderWhere();
536
-            if ($criteria->getSort() !== '') {
537
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
538
-            }
539
-            $limit = $criteria->getLimit();
540
-            $start = $criteria->getStart();
541
-        }
542
-
543
-        if ($debug) {
544
-            xoops_debug($sql);
545
-        }
546
-
547
-        $result = $this->db->query($sql, $limit, $start);
548
-        if (!$result) {
549
-            return $ret;
550
-        }
551
-
552
-        $myts = MyTextSanitizer::getInstance();
553
-        while (false !== ($myrow = $this->db->fetchArray($result))) {
554
-            //identifiers should be textboxes, so sanitize them like that
555
-            $ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
556
-        }
557
-
558
-        return $ret;
559
-    }
560
-
561
-    /**
562
-     * count objects matching a condition
563
-     *
564
-     * @param  CriteriaElement $criteria {@link CriteriaElement} to match
565
-     * @return int             count of objects
566
-     */
567
-    public function getCount(CriteriaElement $criteria = null)
568
-    {
569
-        $field   = '';
570
-        $groupby = false;
571
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
572
-            if ($criteria->groupby !== '') {
573
-                $groupby = true;
574
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
575
-            }
576
-        }
577
-        /**
578
-         * if we have a generalSQL, lets used this one.
579
-         * This needs to be improved...
580
-         */
581
-        if ($this->generalSQL) {
582
-            $sql = $this->generalSQL;
583
-            $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
584
-        } else {
585
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
586
-        }
587
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
588
-            $sql .= ' ' . $criteria->renderWhere();
589
-            if ($criteria->groupby !== '') {
590
-                $sql .= $criteria->getGroupby();
591
-            }
592
-        }
593
-
594
-        $result = $this->db->query($sql);
595
-        if (!$result) {
596
-            return 0;
597
-        }
598
-        if ($groupby === false) {
599
-            list($count) = $this->db->fetchRow($result);
600
-
601
-            return $count;
602
-        } else {
603
-            $ret = [];
604
-            while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
605
-                $ret[$id] = $count;
606
-            }
607
-
608
-            return $ret;
609
-        }
610
-    }
611
-
612
-    /**
613
-     * delete an object from the database
614
-     *
615
-     * @param  XoopsObject $obj reference to the object to delete
616
-     * @param  bool        $force
617
-     * @return bool        FALSE if failed.
618
-     */
619
-    public function delete(XoopsObject $obj, $force = false)
620
-    {
621
-        $eventResult = $this->executeEvent('beforeDelete', $obj);
622
-        if (!$eventResult) {
623
-            $obj->setErrors('An error occured during the BeforeDelete event');
624
-
625
-            return false;
626
-        }
627
-
628
-        if (is_array($this->keyName)) {
629
-            $clause = [];
630
-            for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
631
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
632
-            }
633
-            $whereclause = implode(' AND ', $clause);
634
-        } else {
635
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
636
-        }
637
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
638
-        if (false !== $force) {
639
-            $result = $this->db->queryF($sql);
640
-        } else {
641
-            $result = $this->db->query($sql);
642
-        }
643
-        if (!$result) {
644
-            return false;
645
-        }
646
-
647
-        $eventResult = $this->executeEvent('afterDelete', $obj);
648
-        if (!$eventResult) {
649
-            $obj->setErrors('An error occured during the AfterDelete event');
650
-
651
-            return false;
652
-        }
653
-
654
-        return true;
655
-    }
656
-
657
-    /**
658
-     * @param $event
659
-     */
660
-    public function disableEvent($event)
661
-    {
662
-        if (is_array($event)) {
663
-            foreach ($event as $v) {
664
-                $this->_disabledEvents[] = $v;
665
-            }
666
-        } else {
667
-            $this->_disabledEvents[] = $event;
668
-        }
669
-    }
670
-
671
-    /**
672
-     * @return array
673
-     */
674
-    public function getPermissions()
675
-    {
676
-        return $this->permissionsArray;
677
-    }
678
-
679
-    /**
680
-     * insert a new object in the database
681
-     *
682
-     * @param  XoopsObject $obj         reference to the object
683
-     * @param  bool        $force       whether to force the query execution despite security settings
684
-     * @param  bool        $checkObject check if the object is dirty and clean the attributes
685
-     * @param  bool        $debug
686
-     * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
687
-     */
688
-    public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
689
-    {
690
-        if ($checkObject !== false) {
691
-            if (!is_object($obj)) {
692
-                return false;
693
-            }
694
-            /**
695
-             * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
696
-             */
697
-            if (!is_a($obj, $this->className)) {
698
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
699
-
700
-                return false;
701
-            }
702
-            if (!$obj->isDirty()) {
703
-                $obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
704
-
705
-                return true;
706
-            }
707
-        }
708
-
709
-        if ($obj->seoEnabled) {
710
-            // Auto create meta tags if empty
711
-            $smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
712
-
713
-            if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
714
-                if (!$obj->meta_keywords()) {
715
-                    $obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
716
-                }
717
-
718
-                if (!$obj->meta_description()) {
719
-                    $obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
720
-                }
721
-            }
722
-
723
-            // Auto create short_url if empty
724
-            if (!$obj->short_url()) {
725
-                $obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
726
-            }
727
-        }
728
-
729
-        $eventResult = $this->executeEvent('beforeSave', $obj);
730
-        if (!$eventResult) {
731
-            $obj->setErrors('An error occured during the BeforeSave event');
732
-
733
-            return false;
734
-        }
735
-
736
-        if ($obj->isNew()) {
737
-            $eventResult = $this->executeEvent('beforeInsert', $obj);
738
-            if (!$eventResult) {
739
-                $obj->setErrors('An error occured during the BeforeInsert event');
740
-
741
-                return false;
742
-            }
743
-        } else {
744
-            $eventResult = $this->executeEvent('beforeUpdate', $obj);
745
-            if (!$eventResult) {
746
-                $obj->setErrors('An error occured during the BeforeUpdate event');
747
-
748
-                return false;
749
-            }
750
-        }
751
-        if (!$obj->cleanVars()) {
752
-            $obj->setErrors('Variables were not cleaned properly.');
753
-
754
-            return false;
755
-        }
756
-        $fieldsToStoreInDB = [];
757
-        foreach ($obj->cleanVars as $k => $v) {
758
-            if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
759
-                $cleanvars[$k] = (int)$v;
760
-            } elseif (is_array($v)) {
761
-                $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
762
-            } else {
763
-                $cleanvars[$k] = $this->db->quoteString($v);
764
-            }
765
-            if ($obj->vars[$k]['persistent']) {
766
-                $fieldsToStoreInDB[$k] = $cleanvars[$k];
767
-            }
768
-        }
769
-        if ($obj->isNew()) {
770
-            if (!is_array($this->keyName)) {
771
-                if ($cleanvars[$this->keyName] < 1) {
772
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
773
-                }
774
-            }
775
-
776
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
777
-        } else {
778
-            $sql = 'UPDATE ' . $this->table . ' SET';
779
-            foreach ($fieldsToStoreInDB as $key => $value) {
780
-                if ((!is_array($this->keyName) && $key == $this->keyName)
781
-                    || (is_array($this->keyName)
782
-                        && in_array($key, $this->keyName))) {
783
-                    continue;
784
-                }
785
-                if (isset($notfirst)) {
786
-                    $sql .= ',';
787
-                }
788
-                $sql      .= ' ' . $key . ' = ' . $value;
789
-                $notfirst = true;
790
-            }
791
-            if (is_array($this->keyName)) {
792
-                $whereclause = '';
793
-                for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
794
-                    if ($i > 0) {
795
-                        $whereclause .= ' AND ';
796
-                    }
797
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
798
-                }
799
-            } else {
800
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
801
-            }
802
-            $sql .= ' WHERE ' . $whereclause;
803
-        }
804
-
805
-        if ($debug) {
806
-            xoops_debug($sql);
807
-        }
808
-
809
-        if (false != $force) {
810
-            $result = $this->db->queryF($sql);
811
-        } else {
812
-            $result = $this->db->query($sql);
813
-        }
814
-
815
-        if (!$result) {
816
-            $obj->setErrors($this->db->error());
817
-
818
-            return false;
819
-        }
820
-
821
-        if ($obj->isNew() && !is_array($this->keyName)) {
822
-            $obj->assignVar($this->keyName, $this->db->getInsertId());
823
-        }
824
-        $eventResult = $this->executeEvent('afterSave', $obj);
825
-        if (!$eventResult) {
826
-            $obj->setErrors('An error occured during the AfterSave event');
827
-
828
-            return false;
829
-        }
830
-
831
-        if ($obj->isNew()) {
832
-            $obj->unsetNew();
833
-            $eventResult = $this->executeEvent('afterInsert', $obj);
834
-            if (!$eventResult) {
835
-                $obj->setErrors('An error occured during the AfterInsert event');
836
-
837
-                return false;
838
-            }
839
-        } else {
840
-            $eventResult = $this->executeEvent('afterUpdate', $obj);
841
-            if (!$eventResult) {
842
-                $obj->setErrors('An error occured during the AfterUpdate event');
843
-
844
-                return false;
845
-            }
846
-        }
847
-
848
-        return true;
849
-    }
850
-
851
-    /**
852
-     * @param       $obj
853
-     * @param  bool $force
854
-     * @param  bool $checkObject
855
-     * @param  bool $debug
856
-     * @return bool
857
-     */
858
-    public function insertD($obj, $force = false, $checkObject = true, $debug = false)
859
-    {
860
-        return $this->insert($obj, $force, $checkObject, true);
861
-    }
862
-
863
-    /**
864
-     * Change a value for objects with a certain criteria
865
-     *
866
-     * @param string          $fieldname  Name of the field
867
-     * @param string          $fieldvalue Value to write
868
-     * @param CriteriaElement $criteria   {@link CriteriaElement}
869
-     *
870
-     * @param  bool           $force
871
-     * @return bool
872
-     */
873
-    public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
874
-    {
875
-        $set_clause = $fieldname . ' = ';
876
-        if (is_numeric($fieldvalue)) {
877
-            $set_clause .= $fieldvalue;
878
-        } elseif (is_array($fieldvalue)) {
879
-            $set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
880
-        } else {
881
-            $set_clause .= $this->db->quoteString($fieldvalue);
882
-        }
883
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
884
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
885
-            $sql .= ' ' . $criteria->renderWhere();
886
-        }
887
-        if (false != $force) {
888
-            $result = $this->db->queryF($sql);
889
-        } else {
890
-            $result = $this->db->query($sql);
891
-        }
892
-        if (!$result) {
893
-            return false;
894
-        }
895
-
896
-        return true;
897
-    }
898
-
899
-    /**
900
-     * delete all objects meeting the conditions
901
-     *
902
-     * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
903
-     * @return bool
904
-     */
905
-
906
-    public function deleteAll(CriteriaElement $criteria = null)
907
-    {
908
-        if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
909
-            $sql = 'DELETE FROM ' . $this->table;
910
-            $sql .= ' ' . $criteria->renderWhere();
911
-            if (!$this->db->query($sql)) {
912
-                return false;
913
-            }
914
-            $rows = $this->db->getAffectedRows();
915
-
916
-            return $rows > 0 ? $rows : true;
917
-        }
918
-
919
-        return false;
920
-    }
921
-
922
-    /**
923
-     * @return mixed
924
-     */
925
-    public function getModuleInfo()
926
-    {
927
-        return smart_getModuleInfo($this->_moduleName);
928
-    }
929
-
930
-    /**
931
-     * @return bool
932
-     */
933
-    public function getModuleConfig()
934
-    {
935
-        return smart_getModuleConfig($this->_moduleName);
936
-    }
937
-
938
-    /**
939
-     * @return string
940
-     */
941
-    public function getModuleItemString()
942
-    {
943
-        $ret = $this->_moduleName . '_' . $this->_itemname;
944
-
945
-        return $ret;
946
-    }
947
-
948
-    /**
949
-     * @param $object
950
-     */
951
-    public function updateCounter($object)
952
-    {
953
-        if (isset($object->vars['counter'])) {
954
-            $new_counter = $object->getVar('counter') + 1;
955
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
956
-            $this->query($sql, null, true);
957
-        }
958
-    }
959
-
960
-    /**
961
-     * Execute the function associated with an event
962
-     * This method will check if the function is available
963
-     *
964
-     * @param  string $event name of the event
965
-     * @param         $executeEventObj
966
-     * @return mixed  result of the execution of the function or FALSE if the function was not executed
967
-     * @internal param object $obj $object on which is performed the event
968
-     */
969
-    public function executeEvent($event, &$executeEventObj)
970
-    {
971
-        if (!in_array($event, $this->_disabledEvents)) {
972
-            if (method_exists($this, $event)) {
973
-                $ret = $this->$event($executeEventObj);
974
-            } else {
975
-                // check to see if there is a hook for this event
976
-                if (isset($this->_eventHooks[$event])) {
977
-                    $method = $this->_eventHooks[$event];
978
-                    // check to see if the method specified by this hook exists
979
-                    if (method_exists($this, $method)) {
980
-                        $ret = $this->$method($executeEventObj);
981
-                    }
982
-                }
983
-                $ret = true;
984
-            }
985
-
986
-            return $ret;
987
-        }
988
-
989
-        return true;
990
-    }
991
-
992
-    /**
993
-     * @param  bool $withprefix
994
-     * @return string
995
-     */
996
-    public function getIdentifierName($withprefix = true)
997
-    {
998
-        if ($withprefix) {
999
-            return $this->_itemname . '.' . $this->identifierName;
1000
-        } else {
1001
-            return $this->identifierName;
1002
-        }
1003
-    }
28
+	public $_itemname;
29
+
30
+	/**
31
+	 * Name of the table use to store this {@link SmartObject}
32
+	 *
33
+	 * Note that the name of the table needs to be free of the database prefix.
34
+	 * For example "smartsection_categories"
35
+	 * @var string
36
+	 */
37
+	public $table;
38
+
39
+	/**
40
+	 * Name of the table key that uniquely identify each {@link SmartObject}
41
+	 *
42
+	 * For example: "categoryid"
43
+	 * @var string
44
+	 */
45
+	public $keyName;
46
+
47
+	/**
48
+	 * Name of the class derived from {@link SmartObject} and which this handler is handling
49
+	 *
50
+	 * Note that this string needs to be lowercase
51
+	 *
52
+	 * For example: "smartsectioncategory"
53
+	 * @var string
54
+	 */
55
+	public $className;
56
+
57
+	/**
58
+	 * Name of the field which properly identify the {@link SmartObject}
59
+	 *
60
+	 * For example: "name" (this will be the category's name)
61
+	 * @var string
62
+	 */
63
+	public $identifierName;
64
+
65
+	/**
66
+	 * Name of the field which will be use as a summary for the object
67
+	 *
68
+	 * For example: "summary"
69
+	 * @var string
70
+	 */
71
+	public $summaryName;
72
+
73
+	/**
74
+	 * Page name use to basically manage and display the {@link SmartObject}
75
+	 *
76
+	 * This page needs to be the same in user side and admin side
77
+	 *
78
+	 * For example category.php - we will deduct smartsection/category.php as well as smartsection/admin/category.php
79
+	 * @todo this could probably be automatically deducted from the class name - for example, the class SmartsectionCategory will have "category.php" as it's managing page
80
+	 * @var string
81
+	 */
82
+	public $_page;
83
+
84
+	/**
85
+	 * Full path of the module using this {@link SmartObject}
86
+	 *
87
+	 * <code>XOOPS_URL . "/modules/smartsection/"</code>
88
+	 * @todo this could probably be automatically deducted from the class name as it is always prefixed with the module name
89
+	 * @var string
90
+	 */
91
+	public $_modulePath;
92
+
93
+	public $_moduleUrl;
94
+
95
+	public $_moduleName;
96
+
97
+	public $_uploadUrl;
98
+
99
+	public $_uploadPath;
100
+
101
+	public $_allowedMimeTypes = 0;
102
+
103
+	public $_maxFileSize = 1000000;
104
+
105
+	public $_maxWidth = 500;
106
+
107
+	public $_maxHeight = 500;
108
+
109
+	public $highlightFields = [];
110
+
111
+	/**
112
+	 * Array containing the events name and functions
113
+	 *
114
+	 * @var array
115
+	 */
116
+	public $eventArray = [];
117
+
118
+	/**
119
+	 * Array containing the permissions that this handler will manage on the objects
120
+	 *
121
+	 * @var array
122
+	 */
123
+	public $permissionsArray = false;
124
+
125
+	public $generalSQL = false;
126
+
127
+	public $_eventHooks     = [];
128
+	public $_disabledEvents = [];
129
+
130
+	/**
131
+	 * Constructor - called from child classes
132
+	 *
133
+	 * @param XoopsDatabase $db           {@link XoopsDatabase}
134
+	 * @param string        $itemname     Name of the class derived from <a href='psi_element://SmartObject'>SmartObject</a> and which this handler is handling and which this handler is handling
135
+	 * @param string        $keyname      Name of the table key that uniquely identify each {@link SmartObject}
136
+	 * @param string        $idenfierName Name of the field which properly identify the {@link SmartObject}
137
+	 * @param string        $summaryName
138
+	 * @param string        $modulename
139
+	 * @internal param string $tablename Name of the table use to store this <a href='psi_element://SmartObject'>SmartObject</a>
140
+	 * @internal param string $page Page name use to basically manage and display the <a href='psi_element://SmartObject'>SmartObject</a>
141
+	 * @internal param string $moduleName name of the module
142
+	 */
143
+	public function __construct(XoopsDatabase $db, $itemname, $keyname, $idenfierName, $summaryName, $modulename)
144
+	{
145
+		parent::__construct($db);
146
+
147
+		$this->_itemname      = $itemname;
148
+		$this->_moduleName    = $modulename;
149
+		$this->table          = $db->prefix($modulename . '_' . $itemname);
150
+		$this->keyName        = $keyname;
151
+		$this->className      = ucfirst($modulename) . ucfirst($itemname);
152
+		$this->identifierName = $idenfierName;
153
+		$this->summaryName    = $summaryName;
154
+		$this->_page          = $itemname . '.php';
155
+		$this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
156
+		$this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
157
+		$this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
158
+		$this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
159
+	}
160
+
161
+	/**
162
+	 * @param $event
163
+	 * @param $method
164
+	 */
165
+	public function addEventHook($event, $method)
166
+	{
167
+		$this->_eventHooks[$event] = $method;
168
+	}
169
+
170
+	/**
171
+	 * Add a permission that this handler will manage for its objects
172
+	 *
173
+	 * Example: $this->addPermission('view', _AM_SSHOP_CAT_PERM_READ, _AM_SSHOP_CAT_PERM_READ_DSC);
174
+	 *
175
+	 * @param string      $perm_name   name of the permission
176
+	 * @param string      $caption     caption of the control that will be displayed in the form
177
+	 * @param bool|string $description description of the control that will be displayed in the form
178
+	 */
179
+	public function addPermission($perm_name, $caption, $description = false)
180
+	{
181
+		require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
182
+
183
+		$this->permissionsArray[] = [
184
+			'perm_name'   => $perm_name,
185
+			'caption'     => $caption,
186
+			'description' => $description
187
+		];
188
+	}
189
+
190
+	/**
191
+	 * @param $criteria
192
+	 * @param $perm_name
193
+	 * @return bool
194
+	 */
195
+	public function setGrantedObjectsCriteria(&$criteria, $perm_name)
196
+	{
197
+		$smartPermissionsHandler = new SmartobjectPermissionHandler($this);
198
+		$grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
199
+		if (count($grantedItems) > 0) {
200
+			$criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
201
+
202
+			return true;
203
+		} else {
204
+			return false;
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * @param bool $_uploadPath
210
+	 * @param bool $_allowedMimeTypes
211
+	 * @param bool $_maxFileSize
212
+	 * @param bool $_maxWidth
213
+	 * @param bool $_maxHeight
214
+	 */
215
+	public function setUploaderConfig(
216
+		$_uploadPath = false,
217
+		$_allowedMimeTypes = false,
218
+		$_maxFileSize = false,
219
+		$_maxWidth = false,
220
+		$_maxHeight = false
221
+	) {
222
+		$this->_uploadPath       = $_uploadPath ?: $this->_uploadPath;
223
+		$this->_allowedMimeTypes = $_allowedMimeTypes ?: $this->_allowedMimeTypes;
224
+		$this->_maxFileSize      = $_maxFileSize ?: $this->_maxFileSize;
225
+		$this->_maxWidth         = $_maxWidth ?: $this->_maxWidth;
226
+		$this->_maxHeight        = $_maxHeight ?: $this->_maxHeight;
227
+	}
228
+
229
+	/**
230
+	 * create a new {@link SmartObject}
231
+	 *
232
+	 * @param bool $isNew Flag the new objects as "new"?
233
+	 *
234
+	 * @return SmartObject {@link SmartObject}
235
+	 */
236
+	public function create($isNew = true)
237
+	{
238
+		$obj = new $this->className($this);
239
+		$obj->setImageDir($this->getImageUrl(), $this->getImagePath());
240
+		if (!$obj->handler) {
241
+			$obj->Handler = $this;
242
+		}
243
+
244
+		if ($isNew === true) {
245
+			$obj->setNew();
246
+		}
247
+
248
+		return $obj;
249
+	}
250
+
251
+	/**
252
+	 * @return string
253
+	 */
254
+	public function getImageUrl()
255
+	{
256
+		return $this->_uploadUrl . $this->_itemname . '/';
257
+	}
258
+
259
+	/**
260
+	 * @return string
261
+	 */
262
+	public function getImagePath()
263
+	{
264
+		$dir = $this->_uploadPath . $this->_itemname;
265
+		if (!file_exists($dir)) {
266
+			smart_admin_mkdir($dir);
267
+		}
268
+
269
+		return $dir . '/';
270
+	}
271
+
272
+	/**
273
+	 * retrieve a {@link SmartObject}
274
+	 *
275
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
276
+	 * @param  bool  $as_object whether to return an object or an array
277
+	 * @param  bool  $debug
278
+	 * @param  bool  $criteria
279
+	 * @return mixed reference to the <a href='psi_element://SmartObject'>SmartObject</a>, FALSE if failed
280
+	 *                          FALSE if failed
281
+	 */
282
+	public function get($id, $as_object = true, $debug = false, $criteria = false)
283
+	{
284
+		if (!$criteria) {
285
+			$criteria = new CriteriaCompo();
286
+		}
287
+		if (is_array($this->keyName)) {
288
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
289
+				/**
290
+				 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
291
+				 * Is the fact that we removed the (int)() represents a security risk ?
292
+				 */
293
+				//$criteria->add(new Criteria($this->keyName[$i], ($id[$i]), '=', $this->_itemname));
294
+				$criteria->add(new Criteria($this->keyName[$i], $id[$i], '=', $this->_itemname));
295
+			}
296
+		} else {
297
+			//$criteria = new Criteria($this->keyName, (int)($id), '=', $this->_itemname);
298
+			/**
299
+			 * In some situations, the $id is not an INTEGER. SmartObjectTag is an example.
300
+			 * Is the fact that we removed the (int)() represents a security risk ?
301
+			 */
302
+			$criteria->add(new Criteria($this->keyName, $id, '=', $this->_itemname));
303
+		}
304
+		$criteria->setLimit(1);
305
+		if ($debug) {
306
+			$obj_array = $this->getObjectsD($criteria, false, $as_object);
307
+		} else {
308
+			$obj_array = $this->getObjects($criteria, false, $as_object);
309
+			//patch: weird bug of indexing by id even if id_as_key = false;
310
+			if (!isset($obj_array[0]) && is_object($obj_array[$id])) {
311
+				$obj_array[0] = $obj_array[$id];
312
+				unset($obj_array[$id]);
313
+				$obj_array[0]->unsetNew();
314
+			}
315
+		}
316
+
317
+		if (count($obj_array) != 1) {
318
+			$obj = $this->create();
319
+
320
+			return $obj;
321
+		}
322
+
323
+		return $obj_array[0];
324
+	}
325
+
326
+	/**
327
+	 * retrieve a {@link SmartObject}
328
+	 *
329
+	 * @param  mixed $id        ID of the object - or array of ids for joint keys. Joint keys MUST be given in the same order as in the constructor
330
+	 * @param  bool  $as_object whether to return an object or an array
331
+	 * @return mixed reference to the {@link SmartObject}, FALSE if failed
332
+	 */
333
+	public function &getD($id, $as_object = true)
334
+	{
335
+		return $this->get($id, $as_object, true);
336
+	}
337
+
338
+	/**
339
+	 * retrieve objects from the database
340
+	 *
341
+	 * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
342
+	 * @param bool            $id_as_key use the ID as key for the array?
343
+	 * @param bool            $as_object return an array of objects?
344
+	 *
345
+	 * @param  bool           $sql
346
+	 * @param  bool           $debug
347
+	 * @return array
348
+	 */
349
+	public function getObjects(
350
+		CriteriaElement $criteria = null,
351
+		$id_as_key = false,
352
+		$as_object = true,
353
+		$sql = false,
354
+		$debug = false
355
+	) {
356
+		$ret   = [];
357
+		$limit = $start = 0;
358
+
359
+		if ($this->generalSQL) {
360
+			$sql = $this->generalSQL;
361
+		} elseif (!$sql) {
362
+			$sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
363
+		}
364
+
365
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
366
+			$sql .= ' ' . $criteria->renderWhere();
367
+			if ($criteria->getSort() !== '') {
368
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
369
+			}
370
+			$limit = $criteria->getLimit();
371
+			$start = $criteria->getStart();
372
+		}
373
+		if ($debug) {
374
+			xoops_debug($sql);
375
+		}
376
+
377
+		$result = $this->db->query($sql, $limit, $start);
378
+		if (!$result) {
379
+			return $ret;
380
+		}
381
+
382
+		return $this->convertResultSet($result, $id_as_key, $as_object);
383
+	}
384
+
385
+	/**
386
+	 * @param        $sql
387
+	 * @param        $criteria
388
+	 * @param  bool  $force
389
+	 * @param  bool  $debug
390
+	 * @return array
391
+	 */
392
+	public function query($sql, $criteria, $force = false, $debug = false)
393
+	{
394
+		$ret = [];
395
+
396
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
397
+			$sql .= ' ' . $criteria->renderWhere();
398
+			if ($criteria->groupby) {
399
+				$sql .= $criteria->getGroupby();
400
+			}
401
+			if ($criteria->getSort() !== '') {
402
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
403
+			}
404
+		}
405
+		if ($debug) {
406
+			xoops_debug($sql);
407
+		}
408
+
409
+		if ($force) {
410
+			$result = $this->db->queryF($sql);
411
+		} else {
412
+			$result = $this->db->query($sql);
413
+		}
414
+
415
+		if (!$result) {
416
+			return $ret;
417
+		}
418
+
419
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
420
+			$ret[] = $myrow;
421
+		}
422
+
423
+		return $ret;
424
+	}
425
+
426
+	/**
427
+	 * retrieve objects with debug mode - so will show the query
428
+	 *
429
+	 * @param CriteriaElement $criteria  {@link CriteriaElement} conditions to be met
430
+	 * @param bool            $id_as_key use the ID as key for the array?
431
+	 * @param bool            $as_object return an array of objects?
432
+	 *
433
+	 * @param  bool           $sql
434
+	 * @return array
435
+	 */
436
+	public function getObjectsD(CriteriaElement $criteria = null, $id_as_key = false, $as_object = true, $sql = false)
437
+	{
438
+		return $this->getObjects($criteria, $id_as_key, $as_object, $sql, true);
439
+	}
440
+
441
+	/**
442
+	 * @param $arrayObjects
443
+	 * @return array|bool
444
+	 */
445
+	public function getObjectsAsArray($arrayObjects)
446
+	{
447
+		$ret = [];
448
+		foreach ($arrayObjects as $key => $object) {
449
+			$ret[$key] = $object->toArray();
450
+		}
451
+		if (count($ret > 0)) {
452
+			return $ret;
453
+		} else {
454
+			return false;
455
+		}
456
+	}
457
+
458
+	/**
459
+	 * Convert a database resultset to a returnable array
460
+	 *
461
+	 * @param object $result    database resultset
462
+	 * @param bool   $id_as_key - should NOT be used with joint keys
463
+	 * @param bool   $as_object
464
+	 *
465
+	 * @return array
466
+	 */
467
+	public function convertResultSet($result, $id_as_key = false, $as_object = true)
468
+	{
469
+		$ret = [];
470
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
471
+			$obj = $this->create(false);
472
+			$obj->assignVars($myrow);
473
+			if (!$id_as_key) {
474
+				if ($as_object) {
475
+					$ret[] =& $obj;
476
+				} else {
477
+					$ret[] = $obj->toArray();
478
+				}
479
+			} else {
480
+				if ($as_object) {
481
+					$value =& $obj;
482
+				} else {
483
+					$value = $obj->toArray();
484
+				}
485
+				if ($id_as_key === 'parentid') {
486
+					$ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
487
+				} else {
488
+					$ret[$obj->getVar($this->keyName)] = $value;
489
+				}
490
+			}
491
+			unset($obj);
492
+		}
493
+
494
+		return $ret;
495
+	}
496
+
497
+	/**
498
+	 * @param  null $criteria
499
+	 * @param  int  $limit
500
+	 * @param  int  $start
501
+	 * @return array
502
+	 */
503
+	public function getListD($criteria = null, $limit = 0, $start = 0)
504
+	{
505
+		return $this->getList($criteria, $limit, $start, true);
506
+	}
507
+
508
+	/**
509
+	 * Retrieve a list of objects as arrays - DON'T USE WITH JOINT KEYS
510
+	 *
511
+	 * @param CriteriaElement $criteria {@link CriteriaElement} conditions to be met
512
+	 * @param int             $limit    Max number of objects to fetch
513
+	 * @param int             $start    Which record to start at
514
+	 *
515
+	 * @param  bool           $debug
516
+	 * @return array
517
+	 */
518
+	public function getList(CriteriaElement $criteria = null, $limit = 0, $start = 0, $debug = false)
519
+	{
520
+		$ret = [];
521
+		if ($criteria === null) {
522
+			$criteria = new CriteriaCompo();
523
+		}
524
+
525
+		if ($criteria->getSort() === '') {
526
+			$criteria->setSort($this->getIdentifierName());
527
+		}
528
+
529
+		$sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
530
+		if (!empty($this->identifierName)) {
531
+			$sql .= ', ' . $this->getIdentifierName();
532
+		}
533
+		$sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
534
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
535
+			$sql .= ' ' . $criteria->renderWhere();
536
+			if ($criteria->getSort() !== '') {
537
+				$sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
538
+			}
539
+			$limit = $criteria->getLimit();
540
+			$start = $criteria->getStart();
541
+		}
542
+
543
+		if ($debug) {
544
+			xoops_debug($sql);
545
+		}
546
+
547
+		$result = $this->db->query($sql, $limit, $start);
548
+		if (!$result) {
549
+			return $ret;
550
+		}
551
+
552
+		$myts = MyTextSanitizer::getInstance();
553
+		while (false !== ($myrow = $this->db->fetchArray($result))) {
554
+			//identifiers should be textboxes, so sanitize them like that
555
+			$ret[$myrow[$this->keyName]] = empty($this->identifierName) ? 1 : $myts->displayTarea($myrow[$this->identifierName]);
556
+		}
557
+
558
+		return $ret;
559
+	}
560
+
561
+	/**
562
+	 * count objects matching a condition
563
+	 *
564
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} to match
565
+	 * @return int             count of objects
566
+	 */
567
+	public function getCount(CriteriaElement $criteria = null)
568
+	{
569
+		$field   = '';
570
+		$groupby = false;
571
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
572
+			if ($criteria->groupby !== '') {
573
+				$groupby = true;
574
+				$field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
575
+			}
576
+		}
577
+		/**
578
+		 * if we have a generalSQL, lets used this one.
579
+		 * This needs to be improved...
580
+		 */
581
+		if ($this->generalSQL) {
582
+			$sql = $this->generalSQL;
583
+			$sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
584
+		} else {
585
+			$sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
586
+		}
587
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
588
+			$sql .= ' ' . $criteria->renderWhere();
589
+			if ($criteria->groupby !== '') {
590
+				$sql .= $criteria->getGroupby();
591
+			}
592
+		}
593
+
594
+		$result = $this->db->query($sql);
595
+		if (!$result) {
596
+			return 0;
597
+		}
598
+		if ($groupby === false) {
599
+			list($count) = $this->db->fetchRow($result);
600
+
601
+			return $count;
602
+		} else {
603
+			$ret = [];
604
+			while (false !== (list($id, $count) = $this->db->fetchRow($result))) {
605
+				$ret[$id] = $count;
606
+			}
607
+
608
+			return $ret;
609
+		}
610
+	}
611
+
612
+	/**
613
+	 * delete an object from the database
614
+	 *
615
+	 * @param  XoopsObject $obj reference to the object to delete
616
+	 * @param  bool        $force
617
+	 * @return bool        FALSE if failed.
618
+	 */
619
+	public function delete(XoopsObject $obj, $force = false)
620
+	{
621
+		$eventResult = $this->executeEvent('beforeDelete', $obj);
622
+		if (!$eventResult) {
623
+			$obj->setErrors('An error occured during the BeforeDelete event');
624
+
625
+			return false;
626
+		}
627
+
628
+		if (is_array($this->keyName)) {
629
+			$clause = [];
630
+			for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
631
+				$clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
632
+			}
633
+			$whereclause = implode(' AND ', $clause);
634
+		} else {
635
+			$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
636
+		}
637
+		$sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
638
+		if (false !== $force) {
639
+			$result = $this->db->queryF($sql);
640
+		} else {
641
+			$result = $this->db->query($sql);
642
+		}
643
+		if (!$result) {
644
+			return false;
645
+		}
646
+
647
+		$eventResult = $this->executeEvent('afterDelete', $obj);
648
+		if (!$eventResult) {
649
+			$obj->setErrors('An error occured during the AfterDelete event');
650
+
651
+			return false;
652
+		}
653
+
654
+		return true;
655
+	}
656
+
657
+	/**
658
+	 * @param $event
659
+	 */
660
+	public function disableEvent($event)
661
+	{
662
+		if (is_array($event)) {
663
+			foreach ($event as $v) {
664
+				$this->_disabledEvents[] = $v;
665
+			}
666
+		} else {
667
+			$this->_disabledEvents[] = $event;
668
+		}
669
+	}
670
+
671
+	/**
672
+	 * @return array
673
+	 */
674
+	public function getPermissions()
675
+	{
676
+		return $this->permissionsArray;
677
+	}
678
+
679
+	/**
680
+	 * insert a new object in the database
681
+	 *
682
+	 * @param  XoopsObject $obj         reference to the object
683
+	 * @param  bool        $force       whether to force the query execution despite security settings
684
+	 * @param  bool        $checkObject check if the object is dirty and clean the attributes
685
+	 * @param  bool        $debug
686
+	 * @return bool        FALSE if failed, TRUE if already present and unchanged or successful
687
+	 */
688
+	public function insert(XoopsObject $obj, $force = false, $checkObject = true, $debug = false)
689
+	{
690
+		if ($checkObject !== false) {
691
+			if (!is_object($obj)) {
692
+				return false;
693
+			}
694
+			/**
695
+			 * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
696
+			 */
697
+			if (!is_a($obj, $this->className)) {
698
+				$obj->setError(get_class($obj) . ' Differs from ' . $this->className);
699
+
700
+				return false;
701
+			}
702
+			if (!$obj->isDirty()) {
703
+				$obj->setErrors('Not dirty'); //will usually not be outputted as errors are not displayed when the method returns true, but it can be helpful when troubleshooting code - Mith
704
+
705
+				return true;
706
+			}
707
+		}
708
+
709
+		if ($obj->seoEnabled) {
710
+			// Auto create meta tags if empty
711
+			$smartobjectMetagen = new SmartMetagen($obj->title(), $obj->getVar('meta_keywords'), $obj->summary());
712
+
713
+			if (!$obj->getVar('meta_keywords') || !$obj->getVar('meta_description')) {
714
+				if (!$obj->meta_keywords()) {
715
+					$obj->setVar('meta_keywords', $smartobjectMetagen->_keywords);
716
+				}
717
+
718
+				if (!$obj->meta_description()) {
719
+					$obj->setVar('meta_description', $smartobjectMetagen->_meta_description);
720
+				}
721
+			}
722
+
723
+			// Auto create short_url if empty
724
+			if (!$obj->short_url()) {
725
+				$obj->setVar('short_url', $smartobjectMetagen->generateSeoTitle($obj->title('n'), false));
726
+			}
727
+		}
728
+
729
+		$eventResult = $this->executeEvent('beforeSave', $obj);
730
+		if (!$eventResult) {
731
+			$obj->setErrors('An error occured during the BeforeSave event');
732
+
733
+			return false;
734
+		}
735
+
736
+		if ($obj->isNew()) {
737
+			$eventResult = $this->executeEvent('beforeInsert', $obj);
738
+			if (!$eventResult) {
739
+				$obj->setErrors('An error occured during the BeforeInsert event');
740
+
741
+				return false;
742
+			}
743
+		} else {
744
+			$eventResult = $this->executeEvent('beforeUpdate', $obj);
745
+			if (!$eventResult) {
746
+				$obj->setErrors('An error occured during the BeforeUpdate event');
747
+
748
+				return false;
749
+			}
750
+		}
751
+		if (!$obj->cleanVars()) {
752
+			$obj->setErrors('Variables were not cleaned properly.');
753
+
754
+			return false;
755
+		}
756
+		$fieldsToStoreInDB = [];
757
+		foreach ($obj->cleanVars as $k => $v) {
758
+			if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
759
+				$cleanvars[$k] = (int)$v;
760
+			} elseif (is_array($v)) {
761
+				$cleanvars[$k] = $this->db->quoteString(implode(',', $v));
762
+			} else {
763
+				$cleanvars[$k] = $this->db->quoteString($v);
764
+			}
765
+			if ($obj->vars[$k]['persistent']) {
766
+				$fieldsToStoreInDB[$k] = $cleanvars[$k];
767
+			}
768
+		}
769
+		if ($obj->isNew()) {
770
+			if (!is_array($this->keyName)) {
771
+				if ($cleanvars[$this->keyName] < 1) {
772
+					$cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
773
+				}
774
+			}
775
+
776
+			$sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
777
+		} else {
778
+			$sql = 'UPDATE ' . $this->table . ' SET';
779
+			foreach ($fieldsToStoreInDB as $key => $value) {
780
+				if ((!is_array($this->keyName) && $key == $this->keyName)
781
+					|| (is_array($this->keyName)
782
+						&& in_array($key, $this->keyName))) {
783
+					continue;
784
+				}
785
+				if (isset($notfirst)) {
786
+					$sql .= ',';
787
+				}
788
+				$sql      .= ' ' . $key . ' = ' . $value;
789
+				$notfirst = true;
790
+			}
791
+			if (is_array($this->keyName)) {
792
+				$whereclause = '';
793
+				for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
794
+					if ($i > 0) {
795
+						$whereclause .= ' AND ';
796
+					}
797
+					$whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
798
+				}
799
+			} else {
800
+				$whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
801
+			}
802
+			$sql .= ' WHERE ' . $whereclause;
803
+		}
804
+
805
+		if ($debug) {
806
+			xoops_debug($sql);
807
+		}
808
+
809
+		if (false != $force) {
810
+			$result = $this->db->queryF($sql);
811
+		} else {
812
+			$result = $this->db->query($sql);
813
+		}
814
+
815
+		if (!$result) {
816
+			$obj->setErrors($this->db->error());
817
+
818
+			return false;
819
+		}
820
+
821
+		if ($obj->isNew() && !is_array($this->keyName)) {
822
+			$obj->assignVar($this->keyName, $this->db->getInsertId());
823
+		}
824
+		$eventResult = $this->executeEvent('afterSave', $obj);
825
+		if (!$eventResult) {
826
+			$obj->setErrors('An error occured during the AfterSave event');
827
+
828
+			return false;
829
+		}
830
+
831
+		if ($obj->isNew()) {
832
+			$obj->unsetNew();
833
+			$eventResult = $this->executeEvent('afterInsert', $obj);
834
+			if (!$eventResult) {
835
+				$obj->setErrors('An error occured during the AfterInsert event');
836
+
837
+				return false;
838
+			}
839
+		} else {
840
+			$eventResult = $this->executeEvent('afterUpdate', $obj);
841
+			if (!$eventResult) {
842
+				$obj->setErrors('An error occured during the AfterUpdate event');
843
+
844
+				return false;
845
+			}
846
+		}
847
+
848
+		return true;
849
+	}
850
+
851
+	/**
852
+	 * @param       $obj
853
+	 * @param  bool $force
854
+	 * @param  bool $checkObject
855
+	 * @param  bool $debug
856
+	 * @return bool
857
+	 */
858
+	public function insertD($obj, $force = false, $checkObject = true, $debug = false)
859
+	{
860
+		return $this->insert($obj, $force, $checkObject, true);
861
+	}
862
+
863
+	/**
864
+	 * Change a value for objects with a certain criteria
865
+	 *
866
+	 * @param string          $fieldname  Name of the field
867
+	 * @param string          $fieldvalue Value to write
868
+	 * @param CriteriaElement $criteria   {@link CriteriaElement}
869
+	 *
870
+	 * @param  bool           $force
871
+	 * @return bool
872
+	 */
873
+	public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
874
+	{
875
+		$set_clause = $fieldname . ' = ';
876
+		if (is_numeric($fieldvalue)) {
877
+			$set_clause .= $fieldvalue;
878
+		} elseif (is_array($fieldvalue)) {
879
+			$set_clause .= $this->db->quoteString(implode(',', $fieldvalue));
880
+		} else {
881
+			$set_clause .= $this->db->quoteString($fieldvalue);
882
+		}
883
+		$sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
884
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
885
+			$sql .= ' ' . $criteria->renderWhere();
886
+		}
887
+		if (false != $force) {
888
+			$result = $this->db->queryF($sql);
889
+		} else {
890
+			$result = $this->db->query($sql);
891
+		}
892
+		if (!$result) {
893
+			return false;
894
+		}
895
+
896
+		return true;
897
+	}
898
+
899
+	/**
900
+	 * delete all objects meeting the conditions
901
+	 *
902
+	 * @param  CriteriaElement $criteria {@link CriteriaElement} with conditions to meet
903
+	 * @return bool
904
+	 */
905
+
906
+	public function deleteAll(CriteriaElement $criteria = null)
907
+	{
908
+		if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
909
+			$sql = 'DELETE FROM ' . $this->table;
910
+			$sql .= ' ' . $criteria->renderWhere();
911
+			if (!$this->db->query($sql)) {
912
+				return false;
913
+			}
914
+			$rows = $this->db->getAffectedRows();
915
+
916
+			return $rows > 0 ? $rows : true;
917
+		}
918
+
919
+		return false;
920
+	}
921
+
922
+	/**
923
+	 * @return mixed
924
+	 */
925
+	public function getModuleInfo()
926
+	{
927
+		return smart_getModuleInfo($this->_moduleName);
928
+	}
929
+
930
+	/**
931
+	 * @return bool
932
+	 */
933
+	public function getModuleConfig()
934
+	{
935
+		return smart_getModuleConfig($this->_moduleName);
936
+	}
937
+
938
+	/**
939
+	 * @return string
940
+	 */
941
+	public function getModuleItemString()
942
+	{
943
+		$ret = $this->_moduleName . '_' . $this->_itemname;
944
+
945
+		return $ret;
946
+	}
947
+
948
+	/**
949
+	 * @param $object
950
+	 */
951
+	public function updateCounter($object)
952
+	{
953
+		if (isset($object->vars['counter'])) {
954
+			$new_counter = $object->getVar('counter') + 1;
955
+			$sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
956
+			$this->query($sql, null, true);
957
+		}
958
+	}
959
+
960
+	/**
961
+	 * Execute the function associated with an event
962
+	 * This method will check if the function is available
963
+	 *
964
+	 * @param  string $event name of the event
965
+	 * @param         $executeEventObj
966
+	 * @return mixed  result of the execution of the function or FALSE if the function was not executed
967
+	 * @internal param object $obj $object on which is performed the event
968
+	 */
969
+	public function executeEvent($event, &$executeEventObj)
970
+	{
971
+		if (!in_array($event, $this->_disabledEvents)) {
972
+			if (method_exists($this, $event)) {
973
+				$ret = $this->$event($executeEventObj);
974
+			} else {
975
+				// check to see if there is a hook for this event
976
+				if (isset($this->_eventHooks[$event])) {
977
+					$method = $this->_eventHooks[$event];
978
+					// check to see if the method specified by this hook exists
979
+					if (method_exists($this, $method)) {
980
+						$ret = $this->$method($executeEventObj);
981
+					}
982
+				}
983
+				$ret = true;
984
+			}
985
+
986
+			return $ret;
987
+		}
988
+
989
+		return true;
990
+	}
991
+
992
+	/**
993
+	 * @param  bool $withprefix
994
+	 * @return string
995
+	 */
996
+	public function getIdentifierName($withprefix = true)
997
+	{
998
+		if ($withprefix) {
999
+			return $this->_itemname . '.' . $this->identifierName;
1000
+		} else {
1001
+			return $this->identifierName;
1002
+		}
1003
+	}
1004 1004
 }
Please login to merge, or discard this patch.
Spacing   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -146,16 +146,16 @@  discard block
 block discarded – undo
146 146
 
147 147
         $this->_itemname      = $itemname;
148 148
         $this->_moduleName    = $modulename;
149
-        $this->table          = $db->prefix($modulename . '_' . $itemname);
149
+        $this->table          = $db->prefix($modulename.'_'.$itemname);
150 150
         $this->keyName        = $keyname;
151
-        $this->className      = ucfirst($modulename) . ucfirst($itemname);
151
+        $this->className      = ucfirst($modulename).ucfirst($itemname);
152 152
         $this->identifierName = $idenfierName;
153 153
         $this->summaryName    = $summaryName;
154
-        $this->_page          = $itemname . '.php';
155
-        $this->_modulePath    = XOOPS_ROOT_PATH . '/modules/' . $this->_moduleName . '/';
156
-        $this->_moduleUrl     = XOOPS_URL . '/modules/' . $this->_moduleName . '/';
157
-        $this->_uploadPath    = XOOPS_UPLOAD_PATH . '/' . $this->_moduleName . '/';
158
-        $this->_uploadUrl     = XOOPS_UPLOAD_URL . '/' . $this->_moduleName . '/';
154
+        $this->_page          = $itemname.'.php';
155
+        $this->_modulePath    = XOOPS_ROOT_PATH.'/modules/'.$this->_moduleName.'/';
156
+        $this->_moduleUrl     = XOOPS_URL.'/modules/'.$this->_moduleName.'/';
157
+        $this->_uploadPath    = XOOPS_UPLOAD_PATH.'/'.$this->_moduleName.'/';
158
+        $this->_uploadUrl     = XOOPS_UPLOAD_URL.'/'.$this->_moduleName.'/';
159 159
     }
160 160
 
161 161
     /**
@@ -178,7 +178,7 @@  discard block
 block discarded – undo
178 178
      */
179 179
     public function addPermission($perm_name, $caption, $description = false)
180 180
     {
181
-        require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectpermission.php';
181
+        require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectpermission.php';
182 182
 
183 183
         $this->permissionsArray[] = [
184 184
             'perm_name'   => $perm_name,
@@ -197,7 +197,7 @@  discard block
 block discarded – undo
197 197
         $smartPermissionsHandler = new SmartobjectPermissionHandler($this);
198 198
         $grantedItems            = $smartPermissionsHandler->getGrantedItems($perm_name);
199 199
         if (count($grantedItems) > 0) {
200
-            $criteria->add(new Criteria($this->keyName, '(' . implode(', ', $grantedItems) . ')', 'IN'));
200
+            $criteria->add(new Criteria($this->keyName, '('.implode(', ', $grantedItems).')', 'IN'));
201 201
 
202 202
             return true;
203 203
         } else {
@@ -253,7 +253,7 @@  discard block
 block discarded – undo
253 253
      */
254 254
     public function getImageUrl()
255 255
     {
256
-        return $this->_uploadUrl . $this->_itemname . '/';
256
+        return $this->_uploadUrl.$this->_itemname.'/';
257 257
     }
258 258
 
259 259
     /**
@@ -261,12 +261,12 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function getImagePath()
263 263
     {
264
-        $dir = $this->_uploadPath . $this->_itemname;
264
+        $dir = $this->_uploadPath.$this->_itemname;
265 265
         if (!file_exists($dir)) {
266 266
             smart_admin_mkdir($dir);
267 267
         }
268 268
 
269
-        return $dir . '/';
269
+        return $dir.'/';
270 270
     }
271 271
 
272 272
     /**
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
         if ($this->generalSQL) {
360 360
             $sql = $this->generalSQL;
361 361
         } elseif (!$sql) {
362
-            $sql = 'SELECT * FROM ' . $this->table . ' AS ' . $this->_itemname;
362
+            $sql = 'SELECT * FROM '.$this->table.' AS '.$this->_itemname;
363 363
         }
364 364
 
365 365
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
366
-            $sql .= ' ' . $criteria->renderWhere();
366
+            $sql .= ' '.$criteria->renderWhere();
367 367
             if ($criteria->getSort() !== '') {
368
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
368
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
369 369
             }
370 370
             $limit = $criteria->getLimit();
371 371
             $start = $criteria->getStart();
@@ -394,12 +394,12 @@  discard block
 block discarded – undo
394 394
         $ret = [];
395 395
 
396 396
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
397
-            $sql .= ' ' . $criteria->renderWhere();
397
+            $sql .= ' '.$criteria->renderWhere();
398 398
             if ($criteria->groupby) {
399 399
                 $sql .= $criteria->getGroupby();
400 400
             }
401 401
             if ($criteria->getSort() !== '') {
402
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
402
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
403 403
             }
404 404
         }
405 405
         if ($debug) {
@@ -472,18 +472,18 @@  discard block
 block discarded – undo
472 472
             $obj->assignVars($myrow);
473 473
             if (!$id_as_key) {
474 474
                 if ($as_object) {
475
-                    $ret[] =& $obj;
475
+                    $ret[] = & $obj;
476 476
                 } else {
477 477
                     $ret[] = $obj->toArray();
478 478
                 }
479 479
             } else {
480 480
                 if ($as_object) {
481
-                    $value =& $obj;
481
+                    $value = & $obj;
482 482
                 } else {
483 483
                     $value = $obj->toArray();
484 484
                 }
485 485
                 if ($id_as_key === 'parentid') {
486
-                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] =& $value;
486
+                    $ret[$obj->getVar('parentid', 'e')][$obj->getVar($this->keyName)] = & $value;
487 487
                 } else {
488 488
                     $ret[$obj->getVar($this->keyName)] = $value;
489 489
                 }
@@ -526,15 +526,15 @@  discard block
 block discarded – undo
526 526
             $criteria->setSort($this->getIdentifierName());
527 527
         }
528 528
 
529
-        $sql = 'SELECT ' . (is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
529
+        $sql = 'SELECT '.(is_array($this->keyName) ? implode(', ', $this->keyName) : $this->keyName);
530 530
         if (!empty($this->identifierName)) {
531
-            $sql .= ', ' . $this->getIdentifierName();
531
+            $sql .= ', '.$this->getIdentifierName();
532 532
         }
533
-        $sql .= ' FROM ' . $this->table . ' AS ' . $this->_itemname;
533
+        $sql .= ' FROM '.$this->table.' AS '.$this->_itemname;
534 534
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
535
-            $sql .= ' ' . $criteria->renderWhere();
535
+            $sql .= ' '.$criteria->renderWhere();
536 536
             if ($criteria->getSort() !== '') {
537
-                $sql .= ' ORDER BY ' . $criteria->getSort() . ' ' . $criteria->getOrder();
537
+                $sql .= ' ORDER BY '.$criteria->getSort().' '.$criteria->getOrder();
538 538
             }
539 539
             $limit = $criteria->getLimit();
540 540
             $start = $criteria->getStart();
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
572 572
             if ($criteria->groupby !== '') {
573 573
                 $groupby = true;
574
-                $field   = $criteria->groupby . ', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
574
+                $field   = $criteria->groupby.', '; //Not entirely secure unless you KNOW that no criteria's groupby clause is going to be mis-used
575 575
             }
576 576
         }
577 577
         /**
@@ -582,10 +582,10 @@  discard block
 block discarded – undo
582 582
             $sql = $this->generalSQL;
583 583
             $sql = str_replace('SELECT *', 'SELECT COUNT(*)', $sql);
584 584
         } else {
585
-            $sql = 'SELECT ' . $field . 'COUNT(*) FROM ' . $this->table . ' AS ' . $this->_itemname;
585
+            $sql = 'SELECT '.$field.'COUNT(*) FROM '.$this->table.' AS '.$this->_itemname;
586 586
         }
587 587
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
588
-            $sql .= ' ' . $criteria->renderWhere();
588
+            $sql .= ' '.$criteria->renderWhere();
589 589
             if ($criteria->groupby !== '') {
590 590
                 $sql .= $criteria->getGroupby();
591 591
             }
@@ -628,13 +628,13 @@  discard block
 block discarded – undo
628 628
         if (is_array($this->keyName)) {
629 629
             $clause = [];
630 630
             for ($i = 0, $iMax = count($this->keyName); $i < $iMax; ++$i) {
631
-                $clause[] = $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
631
+                $clause[] = $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
632 632
             }
633 633
             $whereclause = implode(' AND ', $clause);
634 634
         } else {
635
-            $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
635
+            $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
636 636
         }
637
-        $sql = 'DELETE FROM ' . $this->table . ' WHERE ' . $whereclause;
637
+        $sql = 'DELETE FROM '.$this->table.' WHERE '.$whereclause;
638 638
         if (false !== $force) {
639 639
             $result = $this->db->queryF($sql);
640 640
         } else {
@@ -695,7 +695,7 @@  discard block
 block discarded – undo
695 695
              * @TODO: Change to if (!(class_exists($this->className) && $obj instanceof $this->className)) when going fully PHP5
696 696
              */
697 697
             if (!is_a($obj, $this->className)) {
698
-                $obj->setError(get_class($obj) . ' Differs from ' . $this->className);
698
+                $obj->setError(get_class($obj).' Differs from '.$this->className);
699 699
 
700 700
                 return false;
701 701
             }
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
         $fieldsToStoreInDB = [];
757 757
         foreach ($obj->cleanVars as $k => $v) {
758 758
             if ($obj->vars[$k]['data_type'] == XOBJ_DTYPE_INT) {
759
-                $cleanvars[$k] = (int)$v;
759
+                $cleanvars[$k] = (int) $v;
760 760
             } elseif (is_array($v)) {
761 761
                 $cleanvars[$k] = $this->db->quoteString(implode(',', $v));
762 762
             } else {
@@ -769,13 +769,13 @@  discard block
 block discarded – undo
769 769
         if ($obj->isNew()) {
770 770
             if (!is_array($this->keyName)) {
771 771
                 if ($cleanvars[$this->keyName] < 1) {
772
-                    $cleanvars[$this->keyName] = $this->db->genId($this->table . '_' . $this->keyName . '_seq');
772
+                    $cleanvars[$this->keyName] = $this->db->genId($this->table.'_'.$this->keyName.'_seq');
773 773
                 }
774 774
             }
775 775
 
776
-            $sql = 'INSERT INTO ' . $this->table . ' (' . implode(',', array_keys($fieldsToStoreInDB)) . ') VALUES (' . implode(',', array_values($fieldsToStoreInDB)) . ')';
776
+            $sql = 'INSERT INTO '.$this->table.' ('.implode(',', array_keys($fieldsToStoreInDB)).') VALUES ('.implode(',', array_values($fieldsToStoreInDB)).')';
777 777
         } else {
778
-            $sql = 'UPDATE ' . $this->table . ' SET';
778
+            $sql = 'UPDATE '.$this->table.' SET';
779 779
             foreach ($fieldsToStoreInDB as $key => $value) {
780 780
                 if ((!is_array($this->keyName) && $key == $this->keyName)
781 781
                     || (is_array($this->keyName)
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
                 if (isset($notfirst)) {
786 786
                     $sql .= ',';
787 787
                 }
788
-                $sql      .= ' ' . $key . ' = ' . $value;
788
+                $sql .= ' '.$key.' = '.$value;
789 789
                 $notfirst = true;
790 790
             }
791 791
             if (is_array($this->keyName)) {
@@ -794,12 +794,12 @@  discard block
 block discarded – undo
794 794
                     if ($i > 0) {
795 795
                         $whereclause .= ' AND ';
796 796
                     }
797
-                    $whereclause .= $this->keyName[$i] . ' = ' . $obj->getVar($this->keyName[$i]);
797
+                    $whereclause .= $this->keyName[$i].' = '.$obj->getVar($this->keyName[$i]);
798 798
                 }
799 799
             } else {
800
-                $whereclause = $this->keyName . ' = ' . $obj->getVar($this->keyName);
800
+                $whereclause = $this->keyName.' = '.$obj->getVar($this->keyName);
801 801
             }
802
-            $sql .= ' WHERE ' . $whereclause;
802
+            $sql .= ' WHERE '.$whereclause;
803 803
         }
804 804
 
805 805
         if ($debug) {
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
      */
873 873
     public function updateAll($fieldname, $fieldvalue, CriteriaElement $criteria = null, $force = false)
874 874
     {
875
-        $set_clause = $fieldname . ' = ';
875
+        $set_clause = $fieldname.' = ';
876 876
         if (is_numeric($fieldvalue)) {
877 877
             $set_clause .= $fieldvalue;
878 878
         } elseif (is_array($fieldvalue)) {
@@ -880,9 +880,9 @@  discard block
 block discarded – undo
880 880
         } else {
881 881
             $set_clause .= $this->db->quoteString($fieldvalue);
882 882
         }
883
-        $sql = 'UPDATE ' . $this->table . ' SET ' . $set_clause;
883
+        $sql = 'UPDATE '.$this->table.' SET '.$set_clause;
884 884
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
885
-            $sql .= ' ' . $criteria->renderWhere();
885
+            $sql .= ' '.$criteria->renderWhere();
886 886
         }
887 887
         if (false != $force) {
888 888
             $result = $this->db->queryF($sql);
@@ -906,8 +906,8 @@  discard block
 block discarded – undo
906 906
     public function deleteAll(CriteriaElement $criteria = null)
907 907
     {
908 908
         if (isset($criteria) && is_subclass_of($criteria, 'criteriaelement')) {
909
-            $sql = 'DELETE FROM ' . $this->table;
910
-            $sql .= ' ' . $criteria->renderWhere();
909
+            $sql = 'DELETE FROM '.$this->table;
910
+            $sql .= ' '.$criteria->renderWhere();
911 911
             if (!$this->db->query($sql)) {
912 912
                 return false;
913 913
             }
@@ -940,7 +940,7 @@  discard block
 block discarded – undo
940 940
      */
941 941
     public function getModuleItemString()
942 942
     {
943
-        $ret = $this->_moduleName . '_' . $this->_itemname;
943
+        $ret = $this->_moduleName.'_'.$this->_itemname;
944 944
 
945 945
         return $ret;
946 946
     }
@@ -952,7 +952,7 @@  discard block
 block discarded – undo
952 952
     {
953 953
         if (isset($object->vars['counter'])) {
954 954
             $new_counter = $object->getVar('counter') + 1;
955
-            $sql         = 'UPDATE ' . $this->table . ' SET counter=' . $new_counter . ' WHERE ' . $this->keyName . '=' . $object->id();
955
+            $sql         = 'UPDATE '.$this->table.' SET counter='.$new_counter.' WHERE '.$this->keyName.'='.$object->id();
956 956
             $this->query($sql, null, true);
957 957
         }
958 958
     }
@@ -996,7 +996,7 @@  discard block
 block discarded – undo
996 996
     public function getIdentifierName($withprefix = true)
997 997
     {
998 998
         if ($withprefix) {
999
-            return $this->_itemname . '.' . $this->identifierName;
999
+            return $this->_itemname.'.'.$this->identifierName;
1000 1000
         } else {
1001 1001
             return $this->identifierName;
1002 1002
         }
Please login to merge, or discard this patch.
class/smartobjecttable.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 
32 32
     /**
33 33
      * SmartObjectColumn constructor.
34
-     * @param        $keyname
34
+     * @param        string $keyname
35 35
      * @param string $align
36 36
      * @param bool   $width
37 37
      * @param bool   $customMethodForValue
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
     }
194 194
 
195 195
     /**
196
-     * @param $columnObj
196
+     * @param SmartObjectColumn $columnObj
197 197
      */
198 198
     public function addColumn($columnObj)
199 199
     {
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
     }
202 202
 
203 203
     /**
204
-     * @param $name
205
-     * @param $location
204
+     * @param string $name
205
+     * @param string $location
206 206
      * @param $value
207 207
      */
208 208
     public function addIntroButton($name, $location, $value)
Please login to merge, or discard this patch.
Indentation   +879 added lines, -879 removed lines patch added patch discarded remove patch
@@ -21,84 +21,84 @@  discard block
 block discarded – undo
21 21
  */
22 22
 class SmartObjectColumn
23 23
 {
24
-    public $_keyname;
25
-    public $_align;
26
-    public $_width;
27
-    public $_customMethodForValue;
28
-    public $_extraParams;
29
-    public $_sortable;
30
-    public $_customCaption;
31
-
32
-    /**
33
-     * SmartObjectColumn constructor.
34
-     * @param        $keyname
35
-     * @param string $align
36
-     * @param bool   $width
37
-     * @param bool   $customMethodForValue
38
-     * @param bool   $param
39
-     * @param bool   $customCaption
40
-     * @param bool   $sortable
41
-     */
42
-    public function __construct(
43
-        $keyname,
44
-        $align = 'left',
45
-        $width = false,
46
-        $customMethodForValue = false,
47
-        $param = false,
48
-        $customCaption = false,
49
-        $sortable = true
50
-    ) {
51
-        $this->_keyname              = $keyname;
52
-        $this->_align                = $align;
53
-        $this->_width                = $width;
54
-        $this->_customMethodForValue = $customMethodForValue;
55
-        $this->_sortable             = $sortable;
56
-        $this->_param                = $param;
57
-        $this->_customCaption        = $customCaption;
58
-    }
59
-
60
-    public function getKeyName()
61
-    {
62
-        return $this->_keyname;
63
-    }
64
-
65
-    /**
66
-     * @return string
67
-     */
68
-    public function getAlign()
69
-    {
70
-        return $this->_align;
71
-    }
72
-
73
-    /**
74
-     * @return bool
75
-     */
76
-    public function isSortable()
77
-    {
78
-        return $this->_sortable;
79
-    }
80
-
81
-    /**
82
-     * @return bool|string
83
-     */
84
-    public function getWidth()
85
-    {
86
-        if ($this->_width) {
87
-            $ret = $this->_width;
88
-        } else {
89
-            $ret = '';
90
-        }
91
-
92
-        return $ret;
93
-    }
94
-
95
-    /**
96
-     * @return bool
97
-     */
98
-    public function getCustomCaption()
99
-    {
100
-        return $this->_customCaption;
101
-    }
24
+	public $_keyname;
25
+	public $_align;
26
+	public $_width;
27
+	public $_customMethodForValue;
28
+	public $_extraParams;
29
+	public $_sortable;
30
+	public $_customCaption;
31
+
32
+	/**
33
+	 * SmartObjectColumn constructor.
34
+	 * @param        $keyname
35
+	 * @param string $align
36
+	 * @param bool   $width
37
+	 * @param bool   $customMethodForValue
38
+	 * @param bool   $param
39
+	 * @param bool   $customCaption
40
+	 * @param bool   $sortable
41
+	 */
42
+	public function __construct(
43
+		$keyname,
44
+		$align = 'left',
45
+		$width = false,
46
+		$customMethodForValue = false,
47
+		$param = false,
48
+		$customCaption = false,
49
+		$sortable = true
50
+	) {
51
+		$this->_keyname              = $keyname;
52
+		$this->_align                = $align;
53
+		$this->_width                = $width;
54
+		$this->_customMethodForValue = $customMethodForValue;
55
+		$this->_sortable             = $sortable;
56
+		$this->_param                = $param;
57
+		$this->_customCaption        = $customCaption;
58
+	}
59
+
60
+	public function getKeyName()
61
+	{
62
+		return $this->_keyname;
63
+	}
64
+
65
+	/**
66
+	 * @return string
67
+	 */
68
+	public function getAlign()
69
+	{
70
+		return $this->_align;
71
+	}
72
+
73
+	/**
74
+	 * @return bool
75
+	 */
76
+	public function isSortable()
77
+	{
78
+		return $this->_sortable;
79
+	}
80
+
81
+	/**
82
+	 * @return bool|string
83
+	 */
84
+	public function getWidth()
85
+	{
86
+		if ($this->_width) {
87
+			$ret = $this->_width;
88
+		} else {
89
+			$ret = '';
90
+		}
91
+
92
+		return $ret;
93
+	}
94
+
95
+	/**
96
+	 * @return bool
97
+	 */
98
+	public function getCustomCaption()
99
+	{
100
+		return $this->_customCaption;
101
+	}
102 102
 }
103 103
 
104 104
 /**
@@ -112,805 +112,805 @@  discard block
 block discarded – undo
112 112
  */
113 113
 class SmartObjectTable
114 114
 {
115
-    public $_id;
116
-    public $_objectHandler;
117
-    public $_columns;
118
-    public $_criteria;
119
-    public $_actions;
120
-    public $_objects = false;
121
-    public $_aObjects;
122
-    public $_custom_actions;
123
-    public $_sortsel;
124
-    public $_ordersel;
125
-    public $_limitsel;
126
-    public $_filtersel;
127
-    public $_filterseloptions;
128
-    public $_filtersel2;
129
-    public $_filtersel2options;
130
-    public $_filtersel2optionsDefault;
131
-
132
-    public $_tempObject;
133
-    public $_tpl;
134
-    public $_introButtons;
135
-    public $_quickSearch            = false;
136
-    public $_actionButtons          = false;
137
-    public $_head_css_class         = 'bg3';
138
-    public $_hasActions             = false;
139
-    public $_userSide               = false;
140
-    public $_printerFriendlyPage    = false;
141
-    public $_tableHeader            = false;
142
-    public $_tableFooter            = false;
143
-    public $_showActionsColumnTitle = true;
144
-    public $_isTree                 = false;
145
-    public $_showFilterAndLimit     = true;
146
-    public $_enableColumnsSorting   = true;
147
-    public $_customTemplate         = false;
148
-    public $_withSelectedActions    = [];
149
-
150
-    /**
151
-     * Constructor
152
-     *
153
-     * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler}
154
-     * @param CriteriaElement               $criteria
155
-     * @param array                         $actions       array representing the actions to offer
156
-     *
157
-     * @param bool                          $userSide
158
-     */
159
-    public function __construct(
160
-        SmartPersistableObjectHandler $objectHandler,
161
-        CriteriaElement $criteria = null,
162
-        $actions = ['edit', 'delete'],
163
-        $userSide = false
164
-    ) {
165
-        $this->_id            = $objectHandler->className;
166
-        $this->_objectHandler = $objectHandler;
167
-
168
-        if (!$criteria) {
169
-            $criteria = new CriteriaCompo();
170
-        }
171
-        $this->_criteria       = $criteria;
172
-        $this->_actions        = $actions;
173
-        $this->_custom_actions = [];
174
-        $this->_userSide       = $userSide;
175
-        if ($userSide) {
176
-            $this->_head_css_class = 'head';
177
-        }
178
-    }
179
-
180
-    /**
181
-     * @param      $op
182
-     * @param bool $caption
183
-     * @param bool $text
184
-     */
185
-    public function addActionButton($op, $caption = false, $text = false)
186
-    {
187
-        $action                 = [
188
-            'op'      => $op,
189
-            'caption' => $caption,
190
-            'text'    => $text
191
-        ];
192
-        $this->_actionButtons[] = $action;
193
-    }
194
-
195
-    /**
196
-     * @param $columnObj
197
-     */
198
-    public function addColumn($columnObj)
199
-    {
200
-        $this->_columns[] = $columnObj;
201
-    }
202
-
203
-    /**
204
-     * @param $name
205
-     * @param $location
206
-     * @param $value
207
-     */
208
-    public function addIntroButton($name, $location, $value)
209
-    {
210
-        $introButton             = [];
211
-        $introButton['name']     = $name;
212
-        $introButton['location'] = $location;
213
-        $introButton['value']    = $value;
214
-        $this->_introButtons[]   = $introButton;
215
-        unset($introButton);
216
-    }
217
-
218
-    public function addPrinterFriendlyLink()
219
-    {
220
-        $current_urls               = smart_getCurrentUrls();
221
-        $current_url                = $current_urls['full'];
222
-        $this->_printerFriendlyPage = $current_url . '&print';
223
-    }
224
-
225
-    /**
226
-     * @param        $fields
227
-     * @param string $caption
228
-     */
229
-    public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH)
230
-    {
231
-        $this->_quickSearch = ['fields' => $fields, 'caption' => $caption];
232
-    }
233
-
234
-    /**
235
-     * @param $content
236
-     */
237
-    public function addHeader($content)
238
-    {
239
-        $this->_tableHeader = $content;
240
-    }
241
-
242
-    /**
243
-     * @param $content
244
-     */
245
-    public function addFooter($content)
246
-    {
247
-        $this->_tableFooter = $content;
248
-    }
249
-
250
-    /**
251
-     * @param $caption
252
-     */
253
-    public function addDefaultIntroButton($caption)
254
-    {
255
-        $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption);
256
-    }
257
-
258
-    /**
259
-     * @param $method
260
-     */
261
-    public function addCustomAction($method)
262
-    {
263
-        $this->_custom_actions[] = $method;
264
-    }
265
-
266
-    /**
267
-     * @param $default_sort
268
-     */
269
-    public function setDefaultSort($default_sort)
270
-    {
271
-        $this->_sortsel = $default_sort;
272
-    }
273
-
274
-    /**
275
-     * @return string
276
-     */
277
-    public function getDefaultSort()
278
-    {
279
-        if ($this->_sortsel) {
280
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
281
-        } else {
282
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName);
283
-        }
284
-    }
285
-
286
-    /**
287
-     * @param $default_order
288
-     */
289
-    public function setDefaultOrder($default_order)
290
-    {
291
-        $this->_ordersel = $default_order;
292
-    }
293
-
294
-    /**
295
-     * @return string
296
-     */
297
-    public function getDefaultOrder()
298
-    {
299
-        if ($this->_ordersel) {
300
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
301
-        } else {
302
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC');
303
-        }
304
-    }
305
-
306
-    /**
307
-     * @param array $actions
308
-     */
309
-    public function addWithSelectedActions($actions = [])
310
-    {
311
-        $this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, '&nbsp;'));
312
-        $this->_withSelectedActions = $actions;
313
-    }
314
-
315
-    /**
316
-     * Adding a filter in the table
317
-     *
318
-     * @param string $key    key to the field that will be used for sorting
319
-     * @param string $method method of the handler that will be called to populate the options when this filter is selected
320
-     * @param bool   $default
321
-     */
322
-    public function addFilter($key, $method, $default = false)
323
-    {
324
-        $this->_filterseloptions[$key]   = $method;
325
-        $this->_filtersel2optionsDefault = $default;
326
-    }
327
-
328
-    /**
329
-     * @param $default_filter
330
-     */
331
-    public function setDefaultFilter($default_filter)
332
-    {
333
-        $this->_filtersel = $default_filter;
334
-    }
335
-
336
-    public function isForUserSide()
337
-    {
338
-        $this->_userSide = true;
339
-    }
340
-
341
-    /**
342
-     * @param $template
343
-     */
344
-    public function setCustomTemplate($template)
345
-    {
346
-        $this->_customTemplate = $template;
347
-    }
348
-
349
-    public function setSortOrder()
350
-    {
351
-        $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
352
-        //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel;
353
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
354
-        $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
355
-
356
-        if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])
357
-            && $this->_tempObject->vars[$this->_sortsel]['itemName']) {
358
-            $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel);
359
-        } else {
360
-            $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel);
361
-        }
362
-
363
-        $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
364
-        //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel;
365
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
366
-        $ordersArray = $this->getOrdersArray();
367
-        $this->_criteria->setOrder($this->_ordersel);
368
-    }
369
-
370
-    /**
371
-     * @param $id
372
-     */
373
-    public function setTableId($id)
374
-    {
375
-        $this->_id = $id;
376
-    }
377
-
378
-    /**
379
-     * @param $objects
380
-     */
381
-    public function setObjects($objects)
382
-    {
383
-        $this->_objects = $objects;
384
-    }
385
-
386
-    public function createTableRows()
387
-    {
388
-        $this->_aObjects = [];
389
-
390
-        $doWeHaveActions = false;
391
-
392
-        $objectclass = 'odd';
393
-        if (count($this->_objects) > 0) {
394
-            foreach ($this->_objects as $object) {
395
-                $aObject = [];
396
-
397
-                $i = 0;
398
-
399
-                $aColumns = [];
400
-
401
-                foreach ($this->_columns as $column) {
402
-                    $aColumn = [];
403
-
404
-                    if (0 == $i) {
405
-                        $class = 'head';
406
-                    } elseif (0 == $i % 2) {
407
-                        $class = 'even';
408
-                    } else {
409
-                        $class = 'odd';
410
-                    }
411
-                    if (method_exists($object, 'initiateCustomFields')) {
412
-                        //$object->initiateCustomFields();
413
-                    }
414
-                    if ('checked' === $column->_keyname) {
415
-                        $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">';
416
-                    } elseif ($column->_customMethodForValue
417
-                              && method_exists($object, $column->_customMethodForValue)) {
418
-                        $method = $column->_customMethodForValue;
419
-                        if ($column->_param) {
420
-                            $value = $object->$method($column->_param);
421
-                        } else {
422
-                            $value = $object->$method();
423
-                        }
424
-                    } else {
425
-                        /**
426
-                         * If the column is the identifier, then put a link on it
427
-                         */
428
-                        if ($column->getKeyName() == $this->_objectHandler->identifierName) {
429
-                            $value = $object->getItemLink();
430
-                        } else {
431
-                            $value = $object->getVar($column->getKeyName());
432
-                        }
433
-                    }
434
-
435
-                    $aColumn['value'] = $value;
436
-                    $aColumn['class'] = $class;
437
-                    $aColumn['width'] = $column->getWidth();
438
-                    $aColumn['align'] = $column->getAlign();
439
-
440
-                    $aColumns[] = $aColumn;
441
-                    ++$i;
442
-                }
443
-
444
-                $aObject['columns'] = $aColumns;
445
-                $aObject['id']      = $object->id();
446
-
447
-                $objectclass = ('even' === $objectclass) ? 'odd' : 'even';
448
-
449
-                $aObject['class'] = $objectclass;
450
-
451
-                $actions = [];
452
-
453
-                // Adding the custom actions if any
454
-                foreach ($this->_custom_actions as $action) {
455
-                    if (method_exists($object, $action)) {
456
-                        $actions[] = $object->$action();
457
-                    }
458
-                }
459
-
460
-                require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
461
-                $controller = new SmartObjectController($this->_objectHandler);
462
-
463
-                if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
464
-                    $actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide);
465
-                }
466
-                if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) {
467
-                    $actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide);
468
-                }
469
-                $aObject['actions'] = $actions;
470
-
471
-                $this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30);
472
-
473
-                $doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0;
474
-
475
-                $this->_aObjects[] = $aObject;
476
-            }
477
-            $this->_tpl->assign('smartobject_objects', $this->_aObjects);
478
-        } else {
479
-            $colspan = count($this->_columns) + 1;
480
-            $this->_tpl->assign('smartobject_colspan', $colspan);
481
-        }
482
-        $this->_hasActions = $doWeHaveActions;
483
-    }
484
-
485
-    /**
486
-     * @param  bool $debug
487
-     * @return mixed
488
-     */
489
-    public function fetchObjects($debug = false)
490
-    {
491
-        return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug);
492
-    }
493
-
494
-    /**
495
-     * @return string
496
-     */
497
-    public function getDefaultFilter()
498
-    {
499
-        if ($this->_filtersel) {
500
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
501
-        } else {
502
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default');
503
-        }
504
-    }
505
-
506
-    /**
507
-     * @return array|bool
508
-     */
509
-    public function getFiltersArray()
510
-    {
511
-        $ret               = [];
512
-        $field             = [];
513
-        $field['caption']  = _CO_OBJ_NONE;
514
-        $field['selected'] = '';
515
-        $ret['default']    = $field;
516
-        unset($field);
517
-
518
-        if ($this->_filterseloptions) {
519
-            foreach ($this->_filterseloptions as $key => $value) {
520
-                $field = [];
521
-                if (is_array($value)) {
522
-                    $field['caption']  = $key;
523
-                    $field['selected'] = $this->_filtersel == $key ? 'selected' : '';
524
-                } else {
525
-                    $field['caption']  = $this->_tempObject->vars[$key]['form_caption'];
526
-                    $field['selected'] = $this->_filtersel == $key ? 'selected' : '';
527
-                }
528
-                $ret[$key] = $field;
529
-                unset($field);
530
-            }
531
-        } else {
532
-            $ret = false;
533
-        }
534
-
535
-        return $ret;
536
-    }
537
-
538
-    /**
539
-     * @param $default_filter2
540
-     */
541
-    public function setDefaultFilter2($default_filter2)
542
-    {
543
-        $this->_filtersel2 = $default_filter2;
544
-    }
545
-
546
-    /**
547
-     * @return string
548
-     */
549
-    public function getDefaultFilter2()
550
-    {
551
-        if ($this->_filtersel2) {
552
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
553
-        } else {
554
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default');
555
-        }
556
-    }
557
-
558
-    /**
559
-     * @return array
560
-     */
561
-    public function getFilters2Array()
562
-    {
563
-        $ret = [];
564
-
565
-        foreach ($this->_filtersel2options as $key => $value) {
566
-            $field             = [];
567
-            $field['caption']  = $value;
568
-            $field['selected'] = $this->_filtersel2 == $key ? 'selected' : '';
569
-            $ret[$key]         = $field;
570
-            unset($field);
571
-        }
572
-
573
-        return $ret;
574
-    }
575
-
576
-    /**
577
-     * @param $limitsArray
578
-     * @param $params_of_the_options_sel
579
-     */
580
-    public function renderOptionSelection($limitsArray, $params_of_the_options_sel)
581
-    {
582
-        // Rendering the form to select options on the table
583
-        $current_urls = smart_getCurrentUrls();
584
-        $current_url  = $current_urls['full'];
585
-
586
-        /**
587
-         * What was $params_of_the_options_sel doing again ?
588
-         */
589
-        //$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel));
590
-        $this->_tpl->assign('smartobject_optionssel_action', $current_url);
591
-        $this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray);
592
-    }
593
-
594
-    /**
595
-     * @return array
596
-     */
597
-    public function getLimitsArray()
598
-    {
599
-        $ret                    = [];
600
-        $ret['all']['caption']  = _CO_SOBJECT_LIMIT_ALL;
601
-        $ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : '';
602
-
603
-        $ret['5']['caption']  = '5';
604
-        $ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : '';
605
-
606
-        $ret['10']['caption']  = '10';
607
-        $ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : '';
608
-
609
-        $ret['15']['caption']  = '15';
610
-        $ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : '';
611
-
612
-        $ret['20']['caption']  = '20';
613
-        $ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : '';
614
-
615
-        $ret['25']['caption']  = '25';
616
-        $ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : '';
617
-
618
-        $ret['30']['caption']  = '30';
619
-        $ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : '';
620
-
621
-        $ret['35']['caption']  = '35';
622
-        $ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : '';
623
-
624
-        $ret['40']['caption']  = '40';
625
-        $ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : '';
626
-
627
-        return $ret;
628
-    }
629
-
630
-    /**
631
-     * @return bool
632
-     */
633
-    public function getObjects()
634
-    {
635
-        return $this->_objects;
636
-    }
637
-
638
-    public function hideActionColumnTitle()
639
-    {
640
-        $this->_showActionsColumnTitle = false;
641
-    }
642
-
643
-    public function hideFilterAndLimit()
644
-    {
645
-        $this->_showFilterAndLimit = false;
646
-    }
647
-
648
-    /**
649
-     * @return array
650
-     */
651
-    public function getOrdersArray()
652
-    {
653
-        $ret                    = [];
654
-        $ret['ASC']['caption']  = _CO_SOBJECT_SORT_ASC;
655
-        $ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : '';
656
-
657
-        $ret['DESC']['caption']  = _CO_SOBJECT_SORT_DESC;
658
-        $ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : '';
659
-
660
-        return $ret;
661
-    }
662
-
663
-    /**
664
-     * @return mixed|string|void
665
-     */
666
-    public function renderD()
667
-    {
668
-        return $this->render(false, true);
669
-    }
670
-
671
-    public function renderForPrint()
672
-    {
673
-    }
674
-
675
-    /**
676
-     * @param  bool $fetchOnly
677
-     * @param  bool $debug
678
-     * @return mixed|string|void
679
-     */
680
-    public function render($fetchOnly = false, $debug = false)
681
-    {
682
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
683
-
684
-        $this->_tpl = new XoopsTpl();
685
-
686
-        /**
687
-         * We need access to the vars of the SmartObject for a few things in the table creation.
688
-         * Since we may not have a SmartObject to look into now, let's create one for this purpose
689
-         * and we will free it after
690
-         */
691
-        $this->_tempObject = $this->_objectHandler->create();
692
-
693
-        $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0);
694
-
695
-        $this->setSortOrder();
696
-
697
-        if (!$this->_isTree) {
698
-            $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15');
699
-        } else {
700
-            $this->_limitsel = 'all';
701
-        }
702
-
703
-        $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel;
704
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel);
705
-        $limitsArray = $this->getLimitsArray();
706
-        $this->_criteria->setLimit($this->_limitsel);
707
-
708
-        $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter();
709
-        $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel;
710
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
711
-        $filtersArray = $this->getFiltersArray();
712
-
713
-        if ($filtersArray) {
714
-            $this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray);
715
-        }
716
-
717
-        // Check if the selected filter is defined and if so, create the selfilter2
718
-        if (isset($this->_filterseloptions[$this->_filtersel])) {
719
-            // check if method associate with this filter exists in the handler
720
-            if (is_array($this->_filterseloptions[$this->_filtersel])) {
721
-                $filter = $this->_filterseloptions[$this->_filtersel];
722
-                $this->_criteria->add($filter['criteria']);
723
-            } else {
724
-                if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) {
725
-
726
-                    // then we will create the selfilter2 options by calling this method
727
-                    $method                   = $this->_filterseloptions[$this->_filtersel];
728
-                    $this->_filtersel2options = $this->_objectHandler->$method();
729
-
730
-                    $this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2();
731
-                    $this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2;
732
-
733
-                    $filters2Array = $this->getFilters2Array();
734
-                    $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array);
735
-
736
-                    smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
737
-                    if ('default' !== $this->_filtersel2) {
738
-                        $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2));
739
-                    }
740
-                }
741
-            }
742
-        }
743
-        // Check if we have a quicksearch
744
-
745
-        if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) {
746
-            $quicksearch_criteria = new CriteriaCompo();
747
-            if (is_array($this->_quickSearch['fields'])) {
748
-                foreach ($this->_quickSearch['fields'] as $v) {
749
-                    $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR');
750
-                }
751
-            } else {
752
-                $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'));
753
-            }
754
-            $this->_criteria->add($quicksearch_criteria);
755
-        }
756
-
757
-        $this->_objects = $this->fetchObjects($debug);
758
-
759
-        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
760
-        if ($this->_criteria->getLimit() > 0) {
761
-
762
-            /**
763
-             * Geeting rid of the old params
764
-             * $new_get_array is an array containing the new GET parameters
765
-             */
766
-            $new_get_array = [];
767
-
768
-            /**
769
-             * $params_of_the_options_sel is an array with all the parameters of the page
770
-             * but without the pagenave parameters. This array will be used in the
771
-             * OptionsSelection
772
-             */
773
-            $params_of_the_options_sel = [];
774
-
775
-            $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName];
776
-            foreach ($_GET as $k => $v) {
777
-                if (!in_array($k, $not_needed_params)) {
778
-                    $new_get_array[]             = "$k=$v";
779
-                    $params_of_the_options_sel[] = "$k=$v";
780
-                }
781
-            }
782
-
783
-            /**
784
-             * Adding the new params of the pagenav
785
-             */
786
-            $new_get_array[] = 'sortsel=' . $this->_sortsel;
787
-            $new_get_array[] = 'ordersel=' . $this->_ordersel;
788
-            $new_get_array[] = 'limitsel=' . $this->_limitsel;
789
-            $otherParams     = implode('&', $new_get_array);
790
-
791
-            $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
792
-            $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav());
793
-        }
794
-        $this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
795
-
796
-        // retreive the current url and the query string
797
-        $current_urls = smart_getCurrentUrls();
798
-        $current_url  = $current_urls['full_phpself'];
799
-        $query_string = $current_urls['querystring'];
800
-        if ($query_string) {
801
-            $query_string = str_replace('?', '', $query_string);
802
-        }
803
-        $query_stringArray     = explode('&', $query_string);
804
-        $new_query_stringArray = [];
805
-        foreach ($query_stringArray as $query_string) {
806
-            if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) {
807
-                $new_query_stringArray[] = $query_string;
808
-            }
809
-        }
810
-        $new_query_string = implode('&', $new_query_stringArray);
811
-
812
-        $orderArray                     = [];
813
-        $orderArray['ASC']['image']     = 'desc.png';
814
-        $orderArray['ASC']['neworder']  = 'DESC';
815
-        $orderArray['DESC']['image']    = 'asc.png';
816
-        $orderArray['DESC']['neworder'] = 'ASC';
817
-
818
-        $aColumns = [];
819
-
820
-        foreach ($this->_columns as $column) {
821
-            $qs_param         = '';
822
-            $aColumn          = [];
823
-            $aColumn['width'] = $column->getWidth();
824
-            $aColumn['align'] = $column->getAlign();
825
-            $aColumn['key']   = $column->getKeyName();
826
-            if ('checked' === $column->_keyname) {
827
-                $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">';
828
-            } elseif ($column->getCustomCaption()) {
829
-                $aColumn['caption'] = $column->getCustomCaption();
830
-            } else {
831
-                $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName();
832
-            }
833
-            // Are we doing a GET sort on this column ?
834
-            $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'])
835
-                        && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName())
836
-                       || ($this->_sortsel == $column->getKeyName());
837
-            $order   = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC';
838
-
839
-            if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) {
840
-                $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id];
841
-            }
842
-            if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) {
843
-                $aColumn['caption'] = $aColumn['caption'];
844
-            } elseif ($getSort) {
845
-                $aColumn['caption'] = '<a href="'
846
-                                      . $current_url
847
-                                      . '?'
848
-                                      . $this->_objectHandler->_itemname
849
-                                      . '_'
850
-                                      . 'sortsel='
851
-                                      . $column->getKeyName()
852
-                                      . '&'
853
-                                      . $this->_objectHandler->_itemname
854
-                                      . '_'
855
-                                      . 'ordersel='
856
-                                      . $orderArray[$order]['neworder']
857
-                                      . $qs_param
858
-                                      . '&'
859
-                                      . $new_query_string
860
-                                      . '">'
861
-                                      . $aColumn['caption']
862
-                                      . ' <img src="'
863
-                                      . SMARTOBJECT_IMAGES_ACTIONS_URL
864
-                                      . $orderArray[$order]['image']
865
-                                      . '" alt="ASC"></a>';
866
-            } else {
867
-                $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
868
-            }
869
-            $aColumns[] = $aColumn;
870
-        }
871
-        $this->_tpl->assign('smartobject_columns', $aColumns);
872
-
873
-        if ($this->_quickSearch) {
874
-            $this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']);
875
-        }
876
-
877
-        $this->createTableRows();
878
-
879
-        $this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit);
880
-        $this->_tpl->assign('smartobject_isTree', $this->_isTree);
881
-        $this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle);
882
-        $this->_tpl->assign('smartobject_table_header', $this->_tableHeader);
883
-        $this->_tpl->assign('smartobject_table_footer', $this->_tableFooter);
884
-        $this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage);
885
-        $this->_tpl->assign('smartobject_user_side', $this->_userSide);
886
-        $this->_tpl->assign('smartobject_has_actions', $this->_hasActions);
887
-        $this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class);
888
-        $this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons);
889
-        $this->_tpl->assign('smartobject_introButtons', $this->_introButtons);
890
-        $this->_tpl->assign('smartobject_id', $this->_id);
891
-        if (!empty($this->_withSelectedActions)) {
892
-            $this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions);
893
-        }
894
-
895
-        $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl';
896
-        if ($fetchOnly) {
897
-            return $this->_tpl->fetch('db:' . $smartobjectTable_template);
898
-        } else {
899
-            $this->_tpl->display('db:' . $smartobjectTable_template);
900
-        }
901
-    }
902
-
903
-    public function disableColumnsSorting()
904
-    {
905
-        $this->_enableColumnsSorting = false;
906
-    }
907
-
908
-    /**
909
-     * @param  bool $debug
910
-     * @return mixed|string|void
911
-     */
912
-    public function fetch($debug = false)
913
-    {
914
-        return $this->render(true, $debug);
915
-    }
115
+	public $_id;
116
+	public $_objectHandler;
117
+	public $_columns;
118
+	public $_criteria;
119
+	public $_actions;
120
+	public $_objects = false;
121
+	public $_aObjects;
122
+	public $_custom_actions;
123
+	public $_sortsel;
124
+	public $_ordersel;
125
+	public $_limitsel;
126
+	public $_filtersel;
127
+	public $_filterseloptions;
128
+	public $_filtersel2;
129
+	public $_filtersel2options;
130
+	public $_filtersel2optionsDefault;
131
+
132
+	public $_tempObject;
133
+	public $_tpl;
134
+	public $_introButtons;
135
+	public $_quickSearch            = false;
136
+	public $_actionButtons          = false;
137
+	public $_head_css_class         = 'bg3';
138
+	public $_hasActions             = false;
139
+	public $_userSide               = false;
140
+	public $_printerFriendlyPage    = false;
141
+	public $_tableHeader            = false;
142
+	public $_tableFooter            = false;
143
+	public $_showActionsColumnTitle = true;
144
+	public $_isTree                 = false;
145
+	public $_showFilterAndLimit     = true;
146
+	public $_enableColumnsSorting   = true;
147
+	public $_customTemplate         = false;
148
+	public $_withSelectedActions    = [];
149
+
150
+	/**
151
+	 * Constructor
152
+	 *
153
+	 * @param SmartPersistableObjectHandler $objectHandler {@link SmartPersistableObjectHandler}
154
+	 * @param CriteriaElement               $criteria
155
+	 * @param array                         $actions       array representing the actions to offer
156
+	 *
157
+	 * @param bool                          $userSide
158
+	 */
159
+	public function __construct(
160
+		SmartPersistableObjectHandler $objectHandler,
161
+		CriteriaElement $criteria = null,
162
+		$actions = ['edit', 'delete'],
163
+		$userSide = false
164
+	) {
165
+		$this->_id            = $objectHandler->className;
166
+		$this->_objectHandler = $objectHandler;
167
+
168
+		if (!$criteria) {
169
+			$criteria = new CriteriaCompo();
170
+		}
171
+		$this->_criteria       = $criteria;
172
+		$this->_actions        = $actions;
173
+		$this->_custom_actions = [];
174
+		$this->_userSide       = $userSide;
175
+		if ($userSide) {
176
+			$this->_head_css_class = 'head';
177
+		}
178
+	}
179
+
180
+	/**
181
+	 * @param      $op
182
+	 * @param bool $caption
183
+	 * @param bool $text
184
+	 */
185
+	public function addActionButton($op, $caption = false, $text = false)
186
+	{
187
+		$action                 = [
188
+			'op'      => $op,
189
+			'caption' => $caption,
190
+			'text'    => $text
191
+		];
192
+		$this->_actionButtons[] = $action;
193
+	}
194
+
195
+	/**
196
+	 * @param $columnObj
197
+	 */
198
+	public function addColumn($columnObj)
199
+	{
200
+		$this->_columns[] = $columnObj;
201
+	}
202
+
203
+	/**
204
+	 * @param $name
205
+	 * @param $location
206
+	 * @param $value
207
+	 */
208
+	public function addIntroButton($name, $location, $value)
209
+	{
210
+		$introButton             = [];
211
+		$introButton['name']     = $name;
212
+		$introButton['location'] = $location;
213
+		$introButton['value']    = $value;
214
+		$this->_introButtons[]   = $introButton;
215
+		unset($introButton);
216
+	}
217
+
218
+	public function addPrinterFriendlyLink()
219
+	{
220
+		$current_urls               = smart_getCurrentUrls();
221
+		$current_url                = $current_urls['full'];
222
+		$this->_printerFriendlyPage = $current_url . '&print';
223
+	}
224
+
225
+	/**
226
+	 * @param        $fields
227
+	 * @param string $caption
228
+	 */
229
+	public function addQuickSearch($fields, $caption = _CO_SOBJECT_QUICK_SEARCH)
230
+	{
231
+		$this->_quickSearch = ['fields' => $fields, 'caption' => $caption];
232
+	}
233
+
234
+	/**
235
+	 * @param $content
236
+	 */
237
+	public function addHeader($content)
238
+	{
239
+		$this->_tableHeader = $content;
240
+	}
241
+
242
+	/**
243
+	 * @param $content
244
+	 */
245
+	public function addFooter($content)
246
+	{
247
+		$this->_tableFooter = $content;
248
+	}
249
+
250
+	/**
251
+	 * @param $caption
252
+	 */
253
+	public function addDefaultIntroButton($caption)
254
+	{
255
+		$this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption);
256
+	}
257
+
258
+	/**
259
+	 * @param $method
260
+	 */
261
+	public function addCustomAction($method)
262
+	{
263
+		$this->_custom_actions[] = $method;
264
+	}
265
+
266
+	/**
267
+	 * @param $default_sort
268
+	 */
269
+	public function setDefaultSort($default_sort)
270
+	{
271
+		$this->_sortsel = $default_sort;
272
+	}
273
+
274
+	/**
275
+	 * @return string
276
+	 */
277
+	public function getDefaultSort()
278
+	{
279
+		if ($this->_sortsel) {
280
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
281
+		} else {
282
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName);
283
+		}
284
+	}
285
+
286
+	/**
287
+	 * @param $default_order
288
+	 */
289
+	public function setDefaultOrder($default_order)
290
+	{
291
+		$this->_ordersel = $default_order;
292
+	}
293
+
294
+	/**
295
+	 * @return string
296
+	 */
297
+	public function getDefaultOrder()
298
+	{
299
+		if ($this->_ordersel) {
300
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
301
+		} else {
302
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC');
303
+		}
304
+	}
305
+
306
+	/**
307
+	 * @param array $actions
308
+	 */
309
+	public function addWithSelectedActions($actions = [])
310
+	{
311
+		$this->addColumn(new SmartObjectColumn('checked', 'center', 20, false, false, '&nbsp;'));
312
+		$this->_withSelectedActions = $actions;
313
+	}
314
+
315
+	/**
316
+	 * Adding a filter in the table
317
+	 *
318
+	 * @param string $key    key to the field that will be used for sorting
319
+	 * @param string $method method of the handler that will be called to populate the options when this filter is selected
320
+	 * @param bool   $default
321
+	 */
322
+	public function addFilter($key, $method, $default = false)
323
+	{
324
+		$this->_filterseloptions[$key]   = $method;
325
+		$this->_filtersel2optionsDefault = $default;
326
+	}
327
+
328
+	/**
329
+	 * @param $default_filter
330
+	 */
331
+	public function setDefaultFilter($default_filter)
332
+	{
333
+		$this->_filtersel = $default_filter;
334
+	}
335
+
336
+	public function isForUserSide()
337
+	{
338
+		$this->_userSide = true;
339
+	}
340
+
341
+	/**
342
+	 * @param $template
343
+	 */
344
+	public function setCustomTemplate($template)
345
+	{
346
+		$this->_customTemplate = $template;
347
+	}
348
+
349
+	public function setSortOrder()
350
+	{
351
+		$this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
352
+		//$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel;
353
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
354
+		$fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
355
+
356
+		if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])
357
+			&& $this->_tempObject->vars[$this->_sortsel]['itemName']) {
358
+			$this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel);
359
+		} else {
360
+			$this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel);
361
+		}
362
+
363
+		$this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
364
+		//$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel;
365
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
366
+		$ordersArray = $this->getOrdersArray();
367
+		$this->_criteria->setOrder($this->_ordersel);
368
+	}
369
+
370
+	/**
371
+	 * @param $id
372
+	 */
373
+	public function setTableId($id)
374
+	{
375
+		$this->_id = $id;
376
+	}
377
+
378
+	/**
379
+	 * @param $objects
380
+	 */
381
+	public function setObjects($objects)
382
+	{
383
+		$this->_objects = $objects;
384
+	}
385
+
386
+	public function createTableRows()
387
+	{
388
+		$this->_aObjects = [];
389
+
390
+		$doWeHaveActions = false;
391
+
392
+		$objectclass = 'odd';
393
+		if (count($this->_objects) > 0) {
394
+			foreach ($this->_objects as $object) {
395
+				$aObject = [];
396
+
397
+				$i = 0;
398
+
399
+				$aColumns = [];
400
+
401
+				foreach ($this->_columns as $column) {
402
+					$aColumn = [];
403
+
404
+					if (0 == $i) {
405
+						$class = 'head';
406
+					} elseif (0 == $i % 2) {
407
+						$class = 'even';
408
+					} else {
409
+						$class = 'odd';
410
+					}
411
+					if (method_exists($object, 'initiateCustomFields')) {
412
+						//$object->initiateCustomFields();
413
+					}
414
+					if ('checked' === $column->_keyname) {
415
+						$value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">';
416
+					} elseif ($column->_customMethodForValue
417
+							  && method_exists($object, $column->_customMethodForValue)) {
418
+						$method = $column->_customMethodForValue;
419
+						if ($column->_param) {
420
+							$value = $object->$method($column->_param);
421
+						} else {
422
+							$value = $object->$method();
423
+						}
424
+					} else {
425
+						/**
426
+						 * If the column is the identifier, then put a link on it
427
+						 */
428
+						if ($column->getKeyName() == $this->_objectHandler->identifierName) {
429
+							$value = $object->getItemLink();
430
+						} else {
431
+							$value = $object->getVar($column->getKeyName());
432
+						}
433
+					}
434
+
435
+					$aColumn['value'] = $value;
436
+					$aColumn['class'] = $class;
437
+					$aColumn['width'] = $column->getWidth();
438
+					$aColumn['align'] = $column->getAlign();
439
+
440
+					$aColumns[] = $aColumn;
441
+					++$i;
442
+				}
443
+
444
+				$aObject['columns'] = $aColumns;
445
+				$aObject['id']      = $object->id();
446
+
447
+				$objectclass = ('even' === $objectclass) ? 'odd' : 'even';
448
+
449
+				$aObject['class'] = $objectclass;
450
+
451
+				$actions = [];
452
+
453
+				// Adding the custom actions if any
454
+				foreach ($this->_custom_actions as $action) {
455
+					if (method_exists($object, $action)) {
456
+						$actions[] = $object->$action();
457
+					}
458
+				}
459
+
460
+				require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
461
+				$controller = new SmartObjectController($this->_objectHandler);
462
+
463
+				if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
464
+					$actions[] = $controller->getEditItemLink($object, false, true, $this->_userSide);
465
+				}
466
+				if ((!is_array($this->_actions)) || in_array('delete', $this->_actions)) {
467
+					$actions[] = $controller->getDeleteItemLink($object, false, true, $this->_userSide);
468
+				}
469
+				$aObject['actions'] = $actions;
470
+
471
+				$this->_tpl->assign('smartobject_actions_column_width', count($actions) * 30);
472
+
473
+				$doWeHaveActions = $doWeHaveActions ? true : count($actions) > 0;
474
+
475
+				$this->_aObjects[] = $aObject;
476
+			}
477
+			$this->_tpl->assign('smartobject_objects', $this->_aObjects);
478
+		} else {
479
+			$colspan = count($this->_columns) + 1;
480
+			$this->_tpl->assign('smartobject_colspan', $colspan);
481
+		}
482
+		$this->_hasActions = $doWeHaveActions;
483
+	}
484
+
485
+	/**
486
+	 * @param  bool $debug
487
+	 * @return mixed
488
+	 */
489
+	public function fetchObjects($debug = false)
490
+	{
491
+		return $this->_objectHandler->getObjects($this->_criteria, true, true, false, $debug);
492
+	}
493
+
494
+	/**
495
+	 * @return string
496
+	 */
497
+	public function getDefaultFilter()
498
+	{
499
+		if ($this->_filtersel) {
500
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
501
+		} else {
502
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default');
503
+		}
504
+	}
505
+
506
+	/**
507
+	 * @return array|bool
508
+	 */
509
+	public function getFiltersArray()
510
+	{
511
+		$ret               = [];
512
+		$field             = [];
513
+		$field['caption']  = _CO_OBJ_NONE;
514
+		$field['selected'] = '';
515
+		$ret['default']    = $field;
516
+		unset($field);
517
+
518
+		if ($this->_filterseloptions) {
519
+			foreach ($this->_filterseloptions as $key => $value) {
520
+				$field = [];
521
+				if (is_array($value)) {
522
+					$field['caption']  = $key;
523
+					$field['selected'] = $this->_filtersel == $key ? 'selected' : '';
524
+				} else {
525
+					$field['caption']  = $this->_tempObject->vars[$key]['form_caption'];
526
+					$field['selected'] = $this->_filtersel == $key ? 'selected' : '';
527
+				}
528
+				$ret[$key] = $field;
529
+				unset($field);
530
+			}
531
+		} else {
532
+			$ret = false;
533
+		}
534
+
535
+		return $ret;
536
+	}
537
+
538
+	/**
539
+	 * @param $default_filter2
540
+	 */
541
+	public function setDefaultFilter2($default_filter2)
542
+	{
543
+		$this->_filtersel2 = $default_filter2;
544
+	}
545
+
546
+	/**
547
+	 * @return string
548
+	 */
549
+	public function getDefaultFilter2()
550
+	{
551
+		if ($this->_filtersel2) {
552
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
553
+		} else {
554
+			return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default');
555
+		}
556
+	}
557
+
558
+	/**
559
+	 * @return array
560
+	 */
561
+	public function getFilters2Array()
562
+	{
563
+		$ret = [];
564
+
565
+		foreach ($this->_filtersel2options as $key => $value) {
566
+			$field             = [];
567
+			$field['caption']  = $value;
568
+			$field['selected'] = $this->_filtersel2 == $key ? 'selected' : '';
569
+			$ret[$key]         = $field;
570
+			unset($field);
571
+		}
572
+
573
+		return $ret;
574
+	}
575
+
576
+	/**
577
+	 * @param $limitsArray
578
+	 * @param $params_of_the_options_sel
579
+	 */
580
+	public function renderOptionSelection($limitsArray, $params_of_the_options_sel)
581
+	{
582
+		// Rendering the form to select options on the table
583
+		$current_urls = smart_getCurrentUrls();
584
+		$current_url  = $current_urls['full'];
585
+
586
+		/**
587
+		 * What was $params_of_the_options_sel doing again ?
588
+		 */
589
+		//$this->_tpl->assign('smartobject_optionssel_action', $_SERVER['PHP_SELF'] . "?" . implode('&', $params_of_the_options_sel));
590
+		$this->_tpl->assign('smartobject_optionssel_action', $current_url);
591
+		$this->_tpl->assign('smartobject_optionssel_limitsArray', $limitsArray);
592
+	}
593
+
594
+	/**
595
+	 * @return array
596
+	 */
597
+	public function getLimitsArray()
598
+	{
599
+		$ret                    = [];
600
+		$ret['all']['caption']  = _CO_SOBJECT_LIMIT_ALL;
601
+		$ret['all']['selected'] = ('all' === $this->_limitsel) ? 'selected' : '';
602
+
603
+		$ret['5']['caption']  = '5';
604
+		$ret['5']['selected'] = ('5' == $this->_limitsel) ? 'selected' : '';
605
+
606
+		$ret['10']['caption']  = '10';
607
+		$ret['10']['selected'] = ('10' == $this->_limitsel) ? 'selected' : '';
608
+
609
+		$ret['15']['caption']  = '15';
610
+		$ret['15']['selected'] = ('15' == $this->_limitsel) ? 'selected' : '';
611
+
612
+		$ret['20']['caption']  = '20';
613
+		$ret['20']['selected'] = ('20' == $this->_limitsel) ? 'selected' : '';
614
+
615
+		$ret['25']['caption']  = '25';
616
+		$ret['25']['selected'] = ('25' == $this->_limitsel) ? 'selected' : '';
617
+
618
+		$ret['30']['caption']  = '30';
619
+		$ret['30']['selected'] = ('30' == $this->_limitsel) ? 'selected' : '';
620
+
621
+		$ret['35']['caption']  = '35';
622
+		$ret['35']['selected'] = ('35' == $this->_limitsel) ? 'selected' : '';
623
+
624
+		$ret['40']['caption']  = '40';
625
+		$ret['40']['selected'] = ('40' == $this->_limitsel) ? 'selected' : '';
626
+
627
+		return $ret;
628
+	}
629
+
630
+	/**
631
+	 * @return bool
632
+	 */
633
+	public function getObjects()
634
+	{
635
+		return $this->_objects;
636
+	}
637
+
638
+	public function hideActionColumnTitle()
639
+	{
640
+		$this->_showActionsColumnTitle = false;
641
+	}
642
+
643
+	public function hideFilterAndLimit()
644
+	{
645
+		$this->_showFilterAndLimit = false;
646
+	}
647
+
648
+	/**
649
+	 * @return array
650
+	 */
651
+	public function getOrdersArray()
652
+	{
653
+		$ret                    = [];
654
+		$ret['ASC']['caption']  = _CO_SOBJECT_SORT_ASC;
655
+		$ret['ASC']['selected'] = ('ASC' === $this->_ordersel) ? 'selected' : '';
656
+
657
+		$ret['DESC']['caption']  = _CO_SOBJECT_SORT_DESC;
658
+		$ret['DESC']['selected'] = ('DESC' === $this->_ordersel) ? 'selected' : '';
659
+
660
+		return $ret;
661
+	}
662
+
663
+	/**
664
+	 * @return mixed|string|void
665
+	 */
666
+	public function renderD()
667
+	{
668
+		return $this->render(false, true);
669
+	}
670
+
671
+	public function renderForPrint()
672
+	{
673
+	}
674
+
675
+	/**
676
+	 * @param  bool $fetchOnly
677
+	 * @param  bool $debug
678
+	 * @return mixed|string|void
679
+	 */
680
+	public function render($fetchOnly = false, $debug = false)
681
+	{
682
+		require_once XOOPS_ROOT_PATH . '/class/template.php';
683
+
684
+		$this->_tpl = new XoopsTpl();
685
+
686
+		/**
687
+		 * We need access to the vars of the SmartObject for a few things in the table creation.
688
+		 * Since we may not have a SmartObject to look into now, let's create one for this purpose
689
+		 * and we will free it after
690
+		 */
691
+		$this->_tempObject = $this->_objectHandler->create();
692
+
693
+		$this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0);
694
+
695
+		$this->setSortOrder();
696
+
697
+		if (!$this->_isTree) {
698
+			$this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15');
699
+		} else {
700
+			$this->_limitsel = 'all';
701
+		}
702
+
703
+		$this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel;
704
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel);
705
+		$limitsArray = $this->getLimitsArray();
706
+		$this->_criteria->setLimit($this->_limitsel);
707
+
708
+		$this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter();
709
+		$this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel;
710
+		smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
711
+		$filtersArray = $this->getFiltersArray();
712
+
713
+		if ($filtersArray) {
714
+			$this->_tpl->assign('smartobject_optionssel_filtersArray', $filtersArray);
715
+		}
716
+
717
+		// Check if the selected filter is defined and if so, create the selfilter2
718
+		if (isset($this->_filterseloptions[$this->_filtersel])) {
719
+			// check if method associate with this filter exists in the handler
720
+			if (is_array($this->_filterseloptions[$this->_filtersel])) {
721
+				$filter = $this->_filterseloptions[$this->_filtersel];
722
+				$this->_criteria->add($filter['criteria']);
723
+			} else {
724
+				if (method_exists($this->_objectHandler, $this->_filterseloptions[$this->_filtersel])) {
725
+
726
+					// then we will create the selfilter2 options by calling this method
727
+					$method                   = $this->_filterseloptions[$this->_filtersel];
728
+					$this->_filtersel2options = $this->_objectHandler->$method();
729
+
730
+					$this->_filtersel2 = isset($_GET['filtersel2']) ? $_GET['filtersel2'] : $this->getDefaultFilter2();
731
+					$this->_filtersel2 = isset($_POST['filtersel2']) ? $_POST['filtersel2'] : $this->_filtersel2;
732
+
733
+					$filters2Array = $this->getFilters2Array();
734
+					$this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array);
735
+
736
+					smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
737
+					if ('default' !== $this->_filtersel2) {
738
+						$this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2));
739
+					}
740
+				}
741
+			}
742
+		}
743
+		// Check if we have a quicksearch
744
+
745
+		if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) {
746
+			$quicksearch_criteria = new CriteriaCompo();
747
+			if (is_array($this->_quickSearch['fields'])) {
748
+				foreach ($this->_quickSearch['fields'] as $v) {
749
+					$quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR');
750
+				}
751
+			} else {
752
+				$quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'));
753
+			}
754
+			$this->_criteria->add($quicksearch_criteria);
755
+		}
756
+
757
+		$this->_objects = $this->fetchObjects($debug);
758
+
759
+		require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
760
+		if ($this->_criteria->getLimit() > 0) {
761
+
762
+			/**
763
+			 * Geeting rid of the old params
764
+			 * $new_get_array is an array containing the new GET parameters
765
+			 */
766
+			$new_get_array = [];
767
+
768
+			/**
769
+			 * $params_of_the_options_sel is an array with all the parameters of the page
770
+			 * but without the pagenave parameters. This array will be used in the
771
+			 * OptionsSelection
772
+			 */
773
+			$params_of_the_options_sel = [];
774
+
775
+			$not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName];
776
+			foreach ($_GET as $k => $v) {
777
+				if (!in_array($k, $not_needed_params)) {
778
+					$new_get_array[]             = "$k=$v";
779
+					$params_of_the_options_sel[] = "$k=$v";
780
+				}
781
+			}
782
+
783
+			/**
784
+			 * Adding the new params of the pagenav
785
+			 */
786
+			$new_get_array[] = 'sortsel=' . $this->_sortsel;
787
+			$new_get_array[] = 'ordersel=' . $this->_ordersel;
788
+			$new_get_array[] = 'limitsel=' . $this->_limitsel;
789
+			$otherParams     = implode('&', $new_get_array);
790
+
791
+			$pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
792
+			$this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav());
793
+		}
794
+		$this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
795
+
796
+		// retreive the current url and the query string
797
+		$current_urls = smart_getCurrentUrls();
798
+		$current_url  = $current_urls['full_phpself'];
799
+		$query_string = $current_urls['querystring'];
800
+		if ($query_string) {
801
+			$query_string = str_replace('?', '', $query_string);
802
+		}
803
+		$query_stringArray     = explode('&', $query_string);
804
+		$new_query_stringArray = [];
805
+		foreach ($query_stringArray as $query_string) {
806
+			if (false === strpos($query_string, 'sortsel') && false === strpos($query_string, 'ordersel')) {
807
+				$new_query_stringArray[] = $query_string;
808
+			}
809
+		}
810
+		$new_query_string = implode('&', $new_query_stringArray);
811
+
812
+		$orderArray                     = [];
813
+		$orderArray['ASC']['image']     = 'desc.png';
814
+		$orderArray['ASC']['neworder']  = 'DESC';
815
+		$orderArray['DESC']['image']    = 'asc.png';
816
+		$orderArray['DESC']['neworder'] = 'ASC';
817
+
818
+		$aColumns = [];
819
+
820
+		foreach ($this->_columns as $column) {
821
+			$qs_param         = '';
822
+			$aColumn          = [];
823
+			$aColumn['width'] = $column->getWidth();
824
+			$aColumn['align'] = $column->getAlign();
825
+			$aColumn['key']   = $column->getKeyName();
826
+			if ('checked' === $column->_keyname) {
827
+				$aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">';
828
+			} elseif ($column->getCustomCaption()) {
829
+				$aColumn['caption'] = $column->getCustomCaption();
830
+			} else {
831
+				$aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName();
832
+			}
833
+			// Are we doing a GET sort on this column ?
834
+			$getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'])
835
+						&& $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName())
836
+					   || ($this->_sortsel == $column->getKeyName());
837
+			$order   = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC';
838
+
839
+			if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) {
840
+				$qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id];
841
+			}
842
+			if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) {
843
+				$aColumn['caption'] = $aColumn['caption'];
844
+			} elseif ($getSort) {
845
+				$aColumn['caption'] = '<a href="'
846
+									  . $current_url
847
+									  . '?'
848
+									  . $this->_objectHandler->_itemname
849
+									  . '_'
850
+									  . 'sortsel='
851
+									  . $column->getKeyName()
852
+									  . '&'
853
+									  . $this->_objectHandler->_itemname
854
+									  . '_'
855
+									  . 'ordersel='
856
+									  . $orderArray[$order]['neworder']
857
+									  . $qs_param
858
+									  . '&'
859
+									  . $new_query_string
860
+									  . '">'
861
+									  . $aColumn['caption']
862
+									  . ' <img src="'
863
+									  . SMARTOBJECT_IMAGES_ACTIONS_URL
864
+									  . $orderArray[$order]['image']
865
+									  . '" alt="ASC"></a>';
866
+			} else {
867
+				$aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
868
+			}
869
+			$aColumns[] = $aColumn;
870
+		}
871
+		$this->_tpl->assign('smartobject_columns', $aColumns);
872
+
873
+		if ($this->_quickSearch) {
874
+			$this->_tpl->assign('smartobject_quicksearch', $this->_quickSearch['caption']);
875
+		}
876
+
877
+		$this->createTableRows();
878
+
879
+		$this->_tpl->assign('smartobject_showFilterAndLimit', $this->_showFilterAndLimit);
880
+		$this->_tpl->assign('smartobject_isTree', $this->_isTree);
881
+		$this->_tpl->assign('smartobject_show_action_column_title', $this->_showActionsColumnTitle);
882
+		$this->_tpl->assign('smartobject_table_header', $this->_tableHeader);
883
+		$this->_tpl->assign('smartobject_table_footer', $this->_tableFooter);
884
+		$this->_tpl->assign('smartobject_printer_friendly_page', $this->_printerFriendlyPage);
885
+		$this->_tpl->assign('smartobject_user_side', $this->_userSide);
886
+		$this->_tpl->assign('smartobject_has_actions', $this->_hasActions);
887
+		$this->_tpl->assign('smartobject_head_css_class', $this->_head_css_class);
888
+		$this->_tpl->assign('smartobject_actionButtons', $this->_actionButtons);
889
+		$this->_tpl->assign('smartobject_introButtons', $this->_introButtons);
890
+		$this->_tpl->assign('smartobject_id', $this->_id);
891
+		if (!empty($this->_withSelectedActions)) {
892
+			$this->_tpl->assign('smartobject_withSelectedActions', $this->_withSelectedActions);
893
+		}
894
+
895
+		$smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl';
896
+		if ($fetchOnly) {
897
+			return $this->_tpl->fetch('db:' . $smartobjectTable_template);
898
+		} else {
899
+			$this->_tpl->display('db:' . $smartobjectTable_template);
900
+		}
901
+	}
902
+
903
+	public function disableColumnsSorting()
904
+	{
905
+		$this->_enableColumnsSorting = false;
906
+	}
907
+
908
+	/**
909
+	 * @param  bool $debug
910
+	 * @return mixed|string|void
911
+	 */
912
+	public function fetch($debug = false)
913
+	{
914
+		return $this->render(true, $debug);
915
+	}
916 916
 }
Please login to merge, or discard this patch.
Spacing   +43 added lines, -43 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function addActionButton($op, $caption = false, $text = false)
186 186
     {
187
-        $action                 = [
187
+        $action = [
188 188
             'op'      => $op,
189 189
             'caption' => $caption,
190 190
             'text'    => $text
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
     {
220 220
         $current_urls               = smart_getCurrentUrls();
221 221
         $current_url                = $current_urls['full'];
222
-        $this->_printerFriendlyPage = $current_url . '&print';
222
+        $this->_printerFriendlyPage = $current_url.'&print';
223 223
     }
224 224
 
225 225
     /**
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      */
253 253
     public function addDefaultIntroButton($caption)
254 254
     {
255
-        $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page . '?op=mod', $caption);
255
+        $this->addIntroButton($this->_objectHandler->_itemname, $this->_objectHandler->_page.'?op=mod', $caption);
256 256
     }
257 257
 
258 258
     /**
@@ -277,9 +277,9 @@  discard block
 block discarded – undo
277 277
     public function getDefaultSort()
278 278
     {
279 279
         if ($this->_sortsel) {
280
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
280
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel);
281 281
         } else {
282
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_objectHandler->identifierName);
282
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_objectHandler->identifierName);
283 283
         }
284 284
     }
285 285
 
@@ -297,9 +297,9 @@  discard block
 block discarded – undo
297 297
     public function getDefaultOrder()
298 298
     {
299 299
         if ($this->_ordersel) {
300
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
300
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel);
301 301
         } else {
302
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', 'ASC');
302
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', 'ASC');
303 303
         }
304 304
     }
305 305
 
@@ -348,21 +348,21 @@  discard block
 block discarded – undo
348 348
 
349 349
     public function setSortOrder()
350 350
     {
351
-        $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] : $this->getDefaultSort();
351
+        $this->_sortsel = isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] : $this->getDefaultSort();
352 352
         //$this->_sortsel = isset($_POST['sortsel']) ? $_POST['sortsel']: $this->_sortsel;
353
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_sortsel', $this->_sortsel);
353
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_sortsel', $this->_sortsel);
354 354
         $fieldsForSorting = $this->_tempObject->getFieldsForSorting($this->_sortsel);
355 355
 
356 356
         if (isset($this->_tempObject->vars[$this->_sortsel]['itemName'])
357 357
             && $this->_tempObject->vars[$this->_sortsel]['itemName']) {
358
-            $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'] . '.' . $this->_sortsel);
358
+            $this->_criteria->setSort($this->_tempObject->vars[$this->_sortsel]['itemName'].'.'.$this->_sortsel);
359 359
         } else {
360
-            $this->_criteria->setSort($this->_objectHandler->_itemname . '.' . $this->_sortsel);
360
+            $this->_criteria->setSort($this->_objectHandler->_itemname.'.'.$this->_sortsel);
361 361
         }
362 362
 
363
-        $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : $this->getDefaultOrder();
363
+        $this->_ordersel = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : $this->getDefaultOrder();
364 364
         //$this->_ordersel = isset($_POST['ordersel']) ? $_POST['ordersel']:$this->_ordersel;
365
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_ordersel', $this->_ordersel);
365
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_ordersel', $this->_ordersel);
366 366
         $ordersArray = $this->getOrdersArray();
367 367
         $this->_criteria->setOrder($this->_ordersel);
368 368
     }
@@ -412,7 +412,7 @@  discard block
 block discarded – undo
412 412
                         //$object->initiateCustomFields();
413 413
                     }
414 414
                     if ('checked' === $column->_keyname) {
415
-                        $value = '<input type ="checkbox" name="selected_smartobjects[]" value="' . $object->id() . '">';
415
+                        $value = '<input type ="checkbox" name="selected_smartobjects[]" value="'.$object->id().'">';
416 416
                     } elseif ($column->_customMethodForValue
417 417
                               && method_exists($object, $column->_customMethodForValue)) {
418 418
                         $method = $column->_customMethodForValue;
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
                     }
458 458
                 }
459 459
 
460
-                require_once SMARTOBJECT_ROOT_PATH . 'class/smartobjectcontroller.php';
460
+                require_once SMARTOBJECT_ROOT_PATH.'class/smartobjectcontroller.php';
461 461
                 $controller = new SmartObjectController($this->_objectHandler);
462 462
 
463 463
                 if ((!is_array($this->_actions)) || in_array('edit', $this->_actions)) {
@@ -497,9 +497,9 @@  discard block
 block discarded – undo
497 497
     public function getDefaultFilter()
498 498
     {
499 499
         if ($this->_filtersel) {
500
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
500
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel);
501 501
         } else {
502
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', 'default');
502
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', 'default');
503 503
         }
504 504
     }
505 505
 
@@ -549,9 +549,9 @@  discard block
 block discarded – undo
549 549
     public function getDefaultFilter2()
550 550
     {
551 551
         if ($this->_filtersel2) {
552
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
552
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2);
553 553
         } else {
554
-            return smart_getCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', 'default');
554
+            return smart_getCookieVar($_SERVER['PHP_SELF'].'_filtersel2', 'default');
555 555
         }
556 556
     }
557 557
 
@@ -679,7 +679,7 @@  discard block
 block discarded – undo
679 679
      */
680 680
     public function render($fetchOnly = false, $debug = false)
681 681
     {
682
-        require_once XOOPS_ROOT_PATH . '/class/template.php';
682
+        require_once XOOPS_ROOT_PATH.'/class/template.php';
683 683
 
684 684
         $this->_tpl = new XoopsTpl();
685 685
 
@@ -690,24 +690,24 @@  discard block
 block discarded – undo
690 690
          */
691 691
         $this->_tempObject = $this->_objectHandler->create();
692 692
 
693
-        $this->_criteria->setStart(isset($_GET['start' . $this->_objectHandler->keyName]) ? (int)$_GET['start' . $this->_objectHandler->keyName] : 0);
693
+        $this->_criteria->setStart(isset($_GET['start'.$this->_objectHandler->keyName]) ? (int) $_GET['start'.$this->_objectHandler->keyName] : 0);
694 694
 
695 695
         $this->setSortOrder();
696 696
 
697 697
         if (!$this->_isTree) {
698
-            $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'] . '_limitsel', '15');
698
+            $this->_limitsel = isset($_GET['limitsel']) ? $_GET['limitsel'] : smart_getCookieVar($_SERVER['PHP_SELF'].'_limitsel', '15');
699 699
         } else {
700 700
             $this->_limitsel = 'all';
701 701
         }
702 702
 
703 703
         $this->_limitsel = isset($_POST['limitsel']) ? $_POST['limitsel'] : $this->_limitsel;
704
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_limitsel', $this->_limitsel);
704
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_limitsel', $this->_limitsel);
705 705
         $limitsArray = $this->getLimitsArray();
706 706
         $this->_criteria->setLimit($this->_limitsel);
707 707
 
708 708
         $this->_filtersel = isset($_GET['filtersel']) ? $_GET['filtersel'] : $this->getDefaultFilter();
709 709
         $this->_filtersel = isset($_POST['filtersel']) ? $_POST['filtersel'] : $this->_filtersel;
710
-        smart_setCookieVar($_SERVER['PHP_SELF'] . '_' . $this->_id . '_filtersel', $this->_filtersel);
710
+        smart_setCookieVar($_SERVER['PHP_SELF'].'_'.$this->_id.'_filtersel', $this->_filtersel);
711 711
         $filtersArray = $this->getFiltersArray();
712 712
 
713 713
         if ($filtersArray) {
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
                     $filters2Array = $this->getFilters2Array();
734 734
                     $this->_tpl->assign('smartobject_optionssel_filters2Array', $filters2Array);
735 735
 
736
-                    smart_setCookieVar($_SERVER['PHP_SELF'] . '_filtersel2', $this->_filtersel2);
736
+                    smart_setCookieVar($_SERVER['PHP_SELF'].'_filtersel2', $this->_filtersel2);
737 737
                     if ('default' !== $this->_filtersel2) {
738 738
                         $this->_criteria->add(new Criteria($this->_filtersel, $this->_filtersel2));
739 739
                     }
@@ -742,21 +742,21 @@  discard block
 block discarded – undo
742 742
         }
743 743
         // Check if we have a quicksearch
744 744
 
745
-        if (isset($_POST['quicksearch_' . $this->_id]) && '' != $_POST['quicksearch_' . $this->_id]) {
745
+        if (isset($_POST['quicksearch_'.$this->_id]) && '' != $_POST['quicksearch_'.$this->_id]) {
746 746
             $quicksearch_criteria = new CriteriaCompo();
747 747
             if (is_array($this->_quickSearch['fields'])) {
748 748
                 foreach ($this->_quickSearch['fields'] as $v) {
749
-                    $quicksearch_criteria->add(new Criteria($v, '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'), 'OR');
749
+                    $quicksearch_criteria->add(new Criteria($v, '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'), 'OR');
750 750
                 }
751 751
             } else {
752
-                $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%' . $_POST['quicksearch_' . $this->_id] . '%', 'LIKE'));
752
+                $quicksearch_criteria->add(new Criteria($this->_quickSearch['fields'], '%'.$_POST['quicksearch_'.$this->_id].'%', 'LIKE'));
753 753
             }
754 754
             $this->_criteria->add($quicksearch_criteria);
755 755
         }
756 756
 
757 757
         $this->_objects = $this->fetchObjects($debug);
758 758
 
759
-        require_once XOOPS_ROOT_PATH . '/class/pagenav.php';
759
+        require_once XOOPS_ROOT_PATH.'/class/pagenav.php';
760 760
         if ($this->_criteria->getLimit() > 0) {
761 761
 
762 762
             /**
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
              */
773 773
             $params_of_the_options_sel = [];
774 774
 
775
-            $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start' . $this->_objectHandler->keyName];
775
+            $not_needed_params = ['sortsel', 'limitsel', 'ordersel', 'start'.$this->_objectHandler->keyName];
776 776
             foreach ($_GET as $k => $v) {
777 777
                 if (!in_array($k, $not_needed_params)) {
778 778
                     $new_get_array[]             = "$k=$v";
@@ -783,12 +783,12 @@  discard block
 block discarded – undo
783 783
             /**
784 784
              * Adding the new params of the pagenav
785 785
              */
786
-            $new_get_array[] = 'sortsel=' . $this->_sortsel;
787
-            $new_get_array[] = 'ordersel=' . $this->_ordersel;
788
-            $new_get_array[] = 'limitsel=' . $this->_limitsel;
786
+            $new_get_array[] = 'sortsel='.$this->_sortsel;
787
+            $new_get_array[] = 'ordersel='.$this->_ordersel;
788
+            $new_get_array[] = 'limitsel='.$this->_limitsel;
789 789
             $otherParams     = implode('&', $new_get_array);
790 790
 
791
-            $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start' . $this->_objectHandler->keyName, $otherParams);
791
+            $pagenav = new XoopsPageNav($this->_objectHandler->getCount($this->_criteria), $this->_criteria->getLimit(), $this->_criteria->getStart(), 'start'.$this->_objectHandler->keyName, $otherParams);
792 792
             $this->_tpl->assign('smartobject_pagenav', $pagenav->renderNav());
793 793
         }
794 794
         $this->renderOptionSelection($limitsArray, $params_of_the_options_sel);
@@ -824,20 +824,20 @@  discard block
 block discarded – undo
824 824
             $aColumn['align'] = $column->getAlign();
825 825
             $aColumn['key']   = $column->getKeyName();
826 826
             if ('checked' === $column->_keyname) {
827
-                $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"' . ' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_' . $this->_id . ', \'selected_smartobjects\');">';
827
+                $aColumn['caption'] = '<input type ="checkbox" id="checkall_smartobjects" name="checkall_smartobjects"'.' value="checkall_smartobjects" onclick="smartobject_checkall(window.document.form_'.$this->_id.', \'selected_smartobjects\');">';
828 828
             } elseif ($column->getCustomCaption()) {
829 829
                 $aColumn['caption'] = $column->getCustomCaption();
830 830
             } else {
831 831
                 $aColumn['caption'] = isset($this->_tempObject->vars[$column->getKeyName()]['form_caption']) ? $this->_tempObject->vars[$column->getKeyName()]['form_caption'] : $column->getKeyName();
832 832
             }
833 833
             // Are we doing a GET sort on this column ?
834
-            $getSort = (isset($_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'])
835
-                        && $_GET[$this->_objectHandler->_itemname . '_' . 'sortsel'] == $column->getKeyName())
834
+            $getSort = (isset($_GET[$this->_objectHandler->_itemname.'_'.'sortsel'])
835
+                        && $_GET[$this->_objectHandler->_itemname.'_'.'sortsel'] == $column->getKeyName())
836 836
                        || ($this->_sortsel == $column->getKeyName());
837
-            $order   = isset($_GET[$this->_objectHandler->_itemname . '_' . 'ordersel']) ? $_GET[$this->_objectHandler->_itemname . '_' . 'ordersel'] : 'DESC';
837
+            $order   = isset($_GET[$this->_objectHandler->_itemname.'_'.'ordersel']) ? $_GET[$this->_objectHandler->_itemname.'_'.'ordersel'] : 'DESC';
838 838
 
839
-            if (isset($_REQUEST['quicksearch_' . $this->_id]) && '' != $_REQUEST['quicksearch_' . $this->_id]) {
840
-                $qs_param = '&quicksearch_' . $this->_id . '=' . $_REQUEST['quicksearch_' . $this->_id];
839
+            if (isset($_REQUEST['quicksearch_'.$this->_id]) && '' != $_REQUEST['quicksearch_'.$this->_id]) {
840
+                $qs_param = '&quicksearch_'.$this->_id.'='.$_REQUEST['quicksearch_'.$this->_id];
841 841
             }
842 842
             if (!$this->_enableColumnsSorting || 'checked' === $column->_keyname || !$column->isSortable()) {
843 843
                 $aColumn['caption'] = $aColumn['caption'];
@@ -864,7 +864,7 @@  discard block
 block discarded – undo
864 864
                                       . $orderArray[$order]['image']
865 865
                                       . '" alt="ASC"></a>';
866 866
             } else {
867
-                $aColumn['caption'] = '<a href="' . $current_url . '?' . $this->_objectHandler->_itemname . '_' . 'sortsel=' . $column->getKeyName() . '&' . $this->_objectHandler->_itemname . '_' . 'ordersel=ASC' . $qs_param . '&' . $new_query_string . '">' . $aColumn['caption'] . '</a>';
867
+                $aColumn['caption'] = '<a href="'.$current_url.'?'.$this->_objectHandler->_itemname.'_'.'sortsel='.$column->getKeyName().'&'.$this->_objectHandler->_itemname.'_'.'ordersel=ASC'.$qs_param.'&'.$new_query_string.'">'.$aColumn['caption'].'</a>';
868 868
             }
869 869
             $aColumns[] = $aColumn;
870 870
         }
@@ -894,9 +894,9 @@  discard block
 block discarded – undo
894 894
 
895 895
         $smartobjectTable_template = $this->_customTemplate ?: 'smartobject_smarttable_display.tpl';
896 896
         if ($fetchOnly) {
897
-            return $this->_tpl->fetch('db:' . $smartobjectTable_template);
897
+            return $this->_tpl->fetch('db:'.$smartobjectTable_template);
898 898
         } else {
899
-            $this->_tpl->display('db:' . $smartobjectTable_template);
899
+            $this->_tpl->display('db:'.$smartobjectTable_template);
900 900
         }
901 901
     }
902 902
 
Please login to merge, or discard this patch.
include/projax/classes/JavaScript.php 3 patches
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 
28 28
     /**
29 29
      * @param $javascript
30
-     * @return mixed|string
30
+     * @return string
31 31
      */
32 32
     public function escape($javascript)
33 33
     {
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 
49 49
     /**
50 50
      * @param         $name
51
-     * @param         $function
51
+     * @param         string $function
52 52
      * @param  null   $html_options
53 53
      * @return string
54 54
      */
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      */
23 23
     public function button_to_function($name, $function = null)
24 24
     {
25
-        return '<input type="button" value="' . $name . '" onclick="' . $function . '">';
25
+        return '<input type="button" value="'.$name.'" onclick="'.$function.'">';
26 26
     }
27 27
 
28 28
     /**
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      */
44 44
     public function tag($content)
45 45
     {
46
-        return '<script type="text/javascript">' . $content . '</script>';
46
+        return '<script type="text/javascript">'.$content.'</script>';
47 47
     }
48 48
 
49 49
     /**
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      */
55 55
     public function link_to_function($name, $function, $html_options = null)
56 56
     {
57
-        return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>';
57
+        return '<a href="'.(isset($html_options['href']) ? $html_options['href'] : '#').'" onclick="'.(isset($html_options['onclick']) ? $html_options['onclick'].';' : '').$function.'; return false;">'.$name.'</a>';
58 58
     }
59 59
 
60 60
     /////////////////////////////////////////////////////////////////////////////////////
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
                 $return_val .= $value;
77 77
             }
78 78
 
79
-            return '[' . $return_val . ']';
79
+            return '['.$return_val.']';
80 80
         }
81 81
 
82 82
         return "'$option'";
@@ -99,6 +99,6 @@  discard block
 block discarded – undo
99 99
             }
100 100
         }
101 101
 
102
-        return '{' . $return_val . '}';
102
+        return '{'.$return_val.'}';
103 103
     }
104 104
 }
Please login to merge, or discard this patch.
Indentation   +75 added lines, -75 removed lines patch added patch discarded remove patch
@@ -15,90 +15,90 @@
 block discarded – undo
15 15
  */
16 16
 class JavaScript
17 17
 {
18
-    /**
19
-     * @param         $name
20
-     * @param  null   $function
21
-     * @return string
22
-     */
23
-    public function button_to_function($name, $function = null)
24
-    {
25
-        return '<input type="button" value="' . $name . '" onclick="' . $function . '">';
26
-    }
18
+	/**
19
+	 * @param         $name
20
+	 * @param  null   $function
21
+	 * @return string
22
+	 */
23
+	public function button_to_function($name, $function = null)
24
+	{
25
+		return '<input type="button" value="' . $name . '" onclick="' . $function . '">';
26
+	}
27 27
 
28
-    /**
29
-     * @param $javascript
30
-     * @return mixed|string
31
-     */
32
-    public function escape($javascript)
33
-    {
34
-        $javascript = addslashes($javascript);
35
-        $javascript = str_replace(["\r\n", "\n", "\r"], ["\n"], $javascript);
28
+	/**
29
+	 * @param $javascript
30
+	 * @return mixed|string
31
+	 */
32
+	public function escape($javascript)
33
+	{
34
+		$javascript = addslashes($javascript);
35
+		$javascript = str_replace(["\r\n", "\n", "\r"], ["\n"], $javascript);
36 36
 
37
-        return $javascript;
38
-    }
37
+		return $javascript;
38
+	}
39 39
 
40
-    /**
41
-     * @param $content
42
-     * @return string
43
-     */
44
-    public function tag($content)
45
-    {
46
-        return '<script type="text/javascript">' . $content . '</script>';
47
-    }
40
+	/**
41
+	 * @param $content
42
+	 * @return string
43
+	 */
44
+	public function tag($content)
45
+	{
46
+		return '<script type="text/javascript">' . $content . '</script>';
47
+	}
48 48
 
49
-    /**
50
-     * @param         $name
51
-     * @param         $function
52
-     * @param  null   $html_options
53
-     * @return string
54
-     */
55
-    public function link_to_function($name, $function, $html_options = null)
56
-    {
57
-        return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>';
58
-    }
49
+	/**
50
+	 * @param         $name
51
+	 * @param         $function
52
+	 * @param  null   $html_options
53
+	 * @return string
54
+	 */
55
+	public function link_to_function($name, $function, $html_options = null)
56
+	{
57
+		return '<a href="' . (isset($html_options['href']) ? $html_options['href'] : '#') . '" onclick="' . (isset($html_options['onclick']) ? $html_options['onclick'] . ';' : '') . $function . '; return false;">' . $name . '</a>';
58
+	}
59 59
 
60
-    /////////////////////////////////////////////////////////////////////////////////////
61
-    //                             Private functions
62
-    /////////////////////////////////////////////////////////////////////////////////////
60
+	/////////////////////////////////////////////////////////////////////////////////////
61
+	//                             Private functions
62
+	/////////////////////////////////////////////////////////////////////////////////////
63 63
 
64
-    /**
65
-     * @param $option
66
-     * @return string
67
-     */
68
-    public function _array_or_string_for_javascript($option)
69
-    {
70
-        $return_val = '';
71
-        if (is_array($option)) {
72
-            foreach ($option as $value) {
73
-                if (!empty($return_val)) {
74
-                    $ret_val .= ', ';
75
-                }
76
-                $return_val .= $value;
77
-            }
64
+	/**
65
+	 * @param $option
66
+	 * @return string
67
+	 */
68
+	public function _array_or_string_for_javascript($option)
69
+	{
70
+		$return_val = '';
71
+		if (is_array($option)) {
72
+			foreach ($option as $value) {
73
+				if (!empty($return_val)) {
74
+					$ret_val .= ', ';
75
+				}
76
+				$return_val .= $value;
77
+			}
78 78
 
79
-            return '[' . $return_val . ']';
80
-        }
79
+			return '[' . $return_val . ']';
80
+		}
81 81
 
82
-        return "'$option'";
83
-    }
82
+		return "'$option'";
83
+	}
84 84
 
85
-    /**
86
-     * @param $options
87
-     * @return string
88
-     */
89
-    public function _options_for_javascript($options)
90
-    {
91
-        $return_val = '';
85
+	/**
86
+	 * @param $options
87
+	 * @return string
88
+	 */
89
+	public function _options_for_javascript($options)
90
+	{
91
+		$return_val = '';
92 92
 
93
-        if (is_array($options)) {
94
-            foreach ($options as $var => $val) {
95
-                if (!empty($return_val)) {
96
-                    $return_val .= ', ';
97
-                }
98
-                $return_val .= "$var:$val";
99
-            }
100
-        }
93
+		if (is_array($options)) {
94
+			foreach ($options as $var => $val) {
95
+				if (!empty($return_val)) {
96
+					$return_val .= ', ';
97
+				}
98
+				$return_val .= "$var:$val";
99
+			}
100
+		}
101 101
 
102
-        return '{' . $return_val . '}';
103
-    }
102
+		return '{' . $return_val . '}';
103
+	}
104 104
 }
Please login to merge, or discard this patch.
include/projax/classes/Prototype.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
     }
213 213
 
214 214
     /**
215
-     * @param         $klass
215
+     * @param         string $klass
216 216
      * @param         $name
217 217
      * @param  null   $options
218 218
      * @return string
@@ -311,7 +311,7 @@  discard block
 block discarded – undo
311 311
     }
312 312
 
313 313
     /**
314
-     * @param $variable
314
+     * @param string $variable
315 315
      * @param $value
316 316
      * @return string
317 317
      */
@@ -321,7 +321,7 @@  discard block
 block discarded – undo
321 321
     }
322 322
 
323 323
     /**
324
-     * @param         $function
324
+     * @param         string $function
325 325
      * @param  null   $args
326 326
      * @return string
327 327
      */
Please login to merge, or discard this patch.
Indentation   +448 added lines, -448 removed lines patch added patch discarded remove patch
@@ -15,452 +15,452 @@
 block discarded – undo
15 15
  */
16 16
 class Prototype extends JavaScript
17 17
 {
18
-    public $CALLBACKS = [
19
-        'uninitialized',
20
-        'loading',
21
-        'loaded',
22
-        'interactive',
23
-        'complete',
24
-        'failure',
25
-        'success'
26
-    ];
27
-
28
-    public $AJAX_OPTIONS = [
29
-        'before',
30
-        'after',
31
-        'condition',
32
-        'url',
33
-        'asynchronous',
34
-        'method',
35
-        'insertion',
36
-        'position',
37
-        'form',
38
-        'with',
39
-        'update',
40
-        'script',
41
-        'uninitialized',
42
-        'loading',
43
-        'loaded',
44
-        'interactive',
45
-        'complete',
46
-        'failure',
47
-        'success'
48
-    ];
49
-
50
-    /**
51
-     * @return string
52
-     */
53
-    public function evaluate_remote_response()
54
-    {
55
-        return 'eval(request.responseText)';
56
-    }
57
-
58
-    /**
59
-     * @param $options
60
-     * @return string
61
-     */
62
-    public function form_remote_tag($options)
63
-    {
64
-        $options['form'] = true;
65
-
66
-        return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
-    }
68
-
69
-    /**
70
-     * @param         $name
71
-     * @param  null   $options
72
-     * @param  null   $html_options
73
-     * @return string
74
-     */
75
-    public function link_to_remote($name, $options = null, $html_options = null)
76
-    {
77
-        return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
-    }
79
-
80
-    /**
81
-     * @param         $field_id
82
-     * @param  null   $options
83
-     * @return string
84
-     */
85
-    public function observe_field($field_id, $options = null)
86
-    {
87
-        if (isset($options['frequency']) && $options['frequency'] > 0) {
88
-            return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
-        } else {
90
-            return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
-        }
92
-    }
93
-
94
-    /**
95
-     * @param         $form_id
96
-     * @param  null   $options
97
-     * @return string
98
-     */
99
-    public function observe_form($form_id, $options = null)
100
-    {
101
-        if (isset($options['frequency'])) {
102
-            return $this->_build_observer('Form.Observer', $form_id, $options);
103
-        } else {
104
-            return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
-        }
106
-    }
107
-
108
-    /**
109
-     * @param  null $options
110
-     * @return string
111
-     */
112
-    public function periodically_call_remote($options = null)
113
-    {
114
-        $frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
-        $code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
-
117
-        return $code;
118
-    }
119
-
120
-    /**
121
-     * @param $options
122
-     * @return string
123
-     */
124
-    public function remote_function($options)
125
-    {
126
-        $javascript_options = $this->_options_for_ajax($options);
127
-
128
-        $update = '';
129
-
130
-        if (isset($options['update']) && is_array($options['update'])) {
131
-            $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
-            $update .= empty($update) ? '' : ',';
133
-            $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
-        } else {
135
-            $update .= isset($options['update']) ? $options['update'] : '';
136
-        }
137
-
138
-        $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
-
140
-        $ajax_function .= "'" . $options['url'] . "'";
141
-        $ajax_function .= ',' . $javascript_options . ')';
142
-
143
-        $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
-        $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
-        $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
-        $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
-
148
-        return $ajax_function;
149
-    }
150
-
151
-    /**
152
-     * @param $name
153
-     * @param $value
154
-     * @param $options
155
-     * @return string
156
-     */
157
-    public function submit_to_remote($name, $value, $options)
158
-    {
159
-        if (isset($options['with'])) {
160
-            $options['with'] = 'Form.serialize(this.form)';
161
-        }
162
-
163
-        return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
-    }
165
-
166
-    /**
167
-     * @param      $element_id
168
-     * @param null $options
169
-     * @param      $block
170
-     */
171
-    public function update_element_function($element_id, $options = null, $block)
172
-    {
173
-        $content = isset($options['content']) ? $options['content'] : '';
174
-        $content = $this->escape($content);
175
-    }
176
-
177
-    /**
178
-     * @param $block
179
-     */
180
-    public function update_page($block)
181
-    {
182
-    }
183
-
184
-    /**
185
-     * @param $block
186
-     * @return string
187
-     */
188
-    public function update_page_tag(& $block)
189
-    {
190
-        return $this->tag($block);
191
-    }
192
-
193
-    /////////////////////////////////////////////////////////////////////////////////////
194
-    //                             Private functions
195
-    /////////////////////////////////////////////////////////////////////////////////////
196
-
197
-    /**
198
-     * @param $options
199
-     * @return array
200
-     */
201
-    public function _build_callbacks($options)
202
-    {
203
-        $callbacks = [];
204
-        foreach ($options as $callback => $code) {
205
-            if (in_array($callback, $this->CALLBACKS)) {
206
-                $name             = 'on' . ucfirst($callback);
207
-                $callbacks[$name] = 'function(request){' . $code . '}';
208
-            }
209
-        }
210
-
211
-        return $callbacks;
212
-    }
213
-
214
-    /**
215
-     * @param         $klass
216
-     * @param         $name
217
-     * @param  null   $options
218
-     * @return string
219
-     */
220
-    public function _build_observer($klass, $name, $options = null)
221
-    {
222
-        if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
-            $options['with'] = '\'' . $options['with'] . '=\' + value';
224
-        } elseif (isset($options['with']) && isset($options['update'])) {
225
-            $options['with'] = 'value';
226
-        }
227
-
228
-        $callback = $options['function'] ?: $this->remote_function($options);
229
-
230
-        $javascript = "new $klass('$name', ";
231
-        $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
-        $javascript .= 'function (element,value) { ';
233
-        $javascript .= $callback;
234
-        $javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
-        $javascript .= '})';
236
-
237
-        return $javascript;
238
-    }
239
-
240
-    /**
241
-     * @param $method
242
-     * @return string
243
-     */
244
-    public function _method_option_to_s($method)
245
-    {
246
-        return strstr($method, "'") ? $method : "'$method'";
247
-    }
248
-
249
-    /**
250
-     * @param $options
251
-     * @return string
252
-     */
253
-    public function _options_for_ajax($options)
254
-    {
255
-        $js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
-
257
-        if (isset($options['type']) && 'synchronous' === $option['type']) {
258
-            $js_options['asynchronous'] = 'false';
259
-        }
260
-
261
-        if (isset($options['method'])) {
262
-            $js_options['method'] = $this->_method_option_to_s($options['method']);
263
-        }
264
-
265
-        if (isset($options['position'])) {
266
-            $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
-        }
268
-
269
-        $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
-
271
-        if (isset($options['form'])) {
272
-            $js_options['parameters'] = 'Form.serialize(this)';
273
-        } elseif (isset($options['parameters'])) {
274
-            $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
-        } elseif (isset($options['with'])) {
276
-            $js_options['parameters'] = $options['with'];
277
-        }
278
-
279
-        return $this->_options_for_javascript($js_options);
280
-    }
281
-
282
-    /////////////////////////////////////////////////////////////////////////////////////
283
-    //                            Mergerd Javascript Generator helpers
284
-    /////////////////////////////////////////////////////////////////////////////////////
285
-
286
-    /**
287
-     * @param $javascript
288
-     */
289
-    public function dump($javascript)
290
-    {
291
-        echo $javascript;
292
-    }
293
-
294
-    /**
295
-     * @param         $id
296
-     * @param  null   $extend
297
-     * @return string
298
-     */
299
-    public function ID($id, $extend = null)
300
-    {
301
-        return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
-    }
303
-
304
-    /**
305
-     * @param $message
306
-     * @return string
307
-     */
308
-    public function alert($message)
309
-    {
310
-        return $this->call('alert', $message);
311
-    }
312
-
313
-    /**
314
-     * @param $variable
315
-     * @param $value
316
-     * @return string
317
-     */
318
-    public function assign($variable, $value)
319
-    {
320
-        return "$variable = $value;";
321
-    }
322
-
323
-    /**
324
-     * @param         $function
325
-     * @param  null   $args
326
-     * @return string
327
-     */
328
-    public function call($function, $args = null)
329
-    {
330
-        $arg_str = '';
331
-        if (is_array($args)) {
332
-            foreach ($args as $arg) {
333
-                if (!empty($arg_str)) {
334
-                    $arg_str .= ', ';
335
-                }
336
-                if (is_string($arg)) {
337
-                    $arg_str .= "'$arg'";
338
-                } else {
339
-                    $arg_str .= $arg;
340
-                }
341
-            }
342
-        } else {
343
-            if (is_string($args)) {
344
-                $arg_str .= "'$args'";
345
-            } else {
346
-                $arg_str .= $args;
347
-            }
348
-        }
349
-
350
-        return "$function($arg_str)";
351
-    }
352
-
353
-    /**
354
-     * @param  int    $seconds
355
-     * @param  string $script
356
-     * @return string
357
-     */
358
-    public function delay($seconds = 1, $script = '')
359
-    {
360
-        return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
-    }
362
-
363
-    /**
364
-     * @param $id
365
-     * @return string
366
-     */
367
-    public function hide($id)
368
-    {
369
-        return $this->call('Element.hide', $id);
370
-    }
371
-
372
-    /**
373
-     * @param         $position
374
-     * @param         $id
375
-     * @param  null   $options_for_render
376
-     * @return string
377
-     */
378
-    public function insert_html($position, $id, $options_for_render = null)
379
-    {
380
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
-
382
-        return $this->call('new Insertion.' . ucfirst($position), $args);
383
-    }
384
-
385
-    /**
386
-     * @param $location
387
-     * @return string
388
-     */
389
-    public function redirect_to($location)
390
-    {
391
-        return $this->assign('window.location.href', $location);
392
-    }
393
-
394
-    /**
395
-     * @param $id
396
-     * @return string
397
-     */
398
-    public function remove($id)
399
-    {
400
-        if (is_array($id)) {
401
-            $arr_str = '';
402
-            foreach ($id as $obj) {
403
-                if (!empty($arg_str)) {
404
-                    $arg_str .= ', ';
405
-                }
406
-                $arg_str .= "'$arg'";
407
-            }
408
-
409
-            return "$A[$arg_str].each(Element.remove)";
410
-        } else {
411
-            return "Element.remove('$id')";
412
-        }
413
-    }
414
-
415
-    /**
416
-     * @param $id
417
-     * @param $options_for_render
418
-     * @return string
419
-     */
420
-    public function replace($id, $options_for_render)
421
-    {
422
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
-
424
-        return $this->call('Element.replace', $args);
425
-    }
426
-
427
-    /**
428
-     * @param $id
429
-     * @param $options_for_render
430
-     * @return string
431
-     */
432
-    public function replace_html($id, $options_for_render)
433
-    {
434
-        $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
-
436
-        return $this->call('Element.update', $args);
437
-    }
438
-
439
-    /**
440
-     * @param         $pattern
441
-     * @param  null   $extend
442
-     * @return string
443
-     */
444
-    public function select($pattern, $extend = null)
445
-    {
446
-        return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
-    }
448
-
449
-    /**
450
-     * @param $id
451
-     * @return string
452
-     */
453
-    public function show($id)
454
-    {
455
-        return $this->call('Element.show', $id);
456
-    }
457
-
458
-    /**
459
-     * @param $id
460
-     * @return string
461
-     */
462
-    public function toggle($id)
463
-    {
464
-        return $this->call('Element.toggle', $id);
465
-    }
18
+	public $CALLBACKS = [
19
+		'uninitialized',
20
+		'loading',
21
+		'loaded',
22
+		'interactive',
23
+		'complete',
24
+		'failure',
25
+		'success'
26
+	];
27
+
28
+	public $AJAX_OPTIONS = [
29
+		'before',
30
+		'after',
31
+		'condition',
32
+		'url',
33
+		'asynchronous',
34
+		'method',
35
+		'insertion',
36
+		'position',
37
+		'form',
38
+		'with',
39
+		'update',
40
+		'script',
41
+		'uninitialized',
42
+		'loading',
43
+		'loaded',
44
+		'interactive',
45
+		'complete',
46
+		'failure',
47
+		'success'
48
+	];
49
+
50
+	/**
51
+	 * @return string
52
+	 */
53
+	public function evaluate_remote_response()
54
+	{
55
+		return 'eval(request.responseText)';
56
+	}
57
+
58
+	/**
59
+	 * @param $options
60
+	 * @return string
61
+	 */
62
+	public function form_remote_tag($options)
63
+	{
64
+		$options['form'] = true;
65
+
66
+		return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
67
+	}
68
+
69
+	/**
70
+	 * @param         $name
71
+	 * @param  null   $options
72
+	 * @param  null   $html_options
73
+	 * @return string
74
+	 */
75
+	public function link_to_remote($name, $options = null, $html_options = null)
76
+	{
77
+		return $this->link_to_function($name, $this->remote_function($options), $html_options);
78
+	}
79
+
80
+	/**
81
+	 * @param         $field_id
82
+	 * @param  null   $options
83
+	 * @return string
84
+	 */
85
+	public function observe_field($field_id, $options = null)
86
+	{
87
+		if (isset($options['frequency']) && $options['frequency'] > 0) {
88
+			return $this->_build_observer('Form.Element.Observer', $field_id, $options);
89
+		} else {
90
+			return $this->_build_observer('Form.Element.EventObserver', $field_id, $options);
91
+		}
92
+	}
93
+
94
+	/**
95
+	 * @param         $form_id
96
+	 * @param  null   $options
97
+	 * @return string
98
+	 */
99
+	public function observe_form($form_id, $options = null)
100
+	{
101
+		if (isset($options['frequency'])) {
102
+			return $this->_build_observer('Form.Observer', $form_id, $options);
103
+		} else {
104
+			return $this->_build_observer('Form.EventObserver', $form_id, $options);
105
+		}
106
+	}
107
+
108
+	/**
109
+	 * @param  null $options
110
+	 * @return string
111
+	 */
112
+	public function periodically_call_remote($options = null)
113
+	{
114
+		$frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
+		$code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
116
+
117
+		return $code;
118
+	}
119
+
120
+	/**
121
+	 * @param $options
122
+	 * @return string
123
+	 */
124
+	public function remote_function($options)
125
+	{
126
+		$javascript_options = $this->_options_for_ajax($options);
127
+
128
+		$update = '';
129
+
130
+		if (isset($options['update']) && is_array($options['update'])) {
131
+			$update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
132
+			$update .= empty($update) ? '' : ',';
133
+			$update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
134
+		} else {
135
+			$update .= isset($options['update']) ? $options['update'] : '';
136
+		}
137
+
138
+		$ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
139
+
140
+		$ajax_function .= "'" . $options['url'] . "'";
141
+		$ajax_function .= ',' . $javascript_options . ')';
142
+
143
+		$ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
+		$ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
+		$ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
+		$ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
147
+
148
+		return $ajax_function;
149
+	}
150
+
151
+	/**
152
+	 * @param $name
153
+	 * @param $value
154
+	 * @param $options
155
+	 * @return string
156
+	 */
157
+	public function submit_to_remote($name, $value, $options)
158
+	{
159
+		if (isset($options['with'])) {
160
+			$options['with'] = 'Form.serialize(this.form)';
161
+		}
162
+
163
+		return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
164
+	}
165
+
166
+	/**
167
+	 * @param      $element_id
168
+	 * @param null $options
169
+	 * @param      $block
170
+	 */
171
+	public function update_element_function($element_id, $options = null, $block)
172
+	{
173
+		$content = isset($options['content']) ? $options['content'] : '';
174
+		$content = $this->escape($content);
175
+	}
176
+
177
+	/**
178
+	 * @param $block
179
+	 */
180
+	public function update_page($block)
181
+	{
182
+	}
183
+
184
+	/**
185
+	 * @param $block
186
+	 * @return string
187
+	 */
188
+	public function update_page_tag(& $block)
189
+	{
190
+		return $this->tag($block);
191
+	}
192
+
193
+	/////////////////////////////////////////////////////////////////////////////////////
194
+	//                             Private functions
195
+	/////////////////////////////////////////////////////////////////////////////////////
196
+
197
+	/**
198
+	 * @param $options
199
+	 * @return array
200
+	 */
201
+	public function _build_callbacks($options)
202
+	{
203
+		$callbacks = [];
204
+		foreach ($options as $callback => $code) {
205
+			if (in_array($callback, $this->CALLBACKS)) {
206
+				$name             = 'on' . ucfirst($callback);
207
+				$callbacks[$name] = 'function(request){' . $code . '}';
208
+			}
209
+		}
210
+
211
+		return $callbacks;
212
+	}
213
+
214
+	/**
215
+	 * @param         $klass
216
+	 * @param         $name
217
+	 * @param  null   $options
218
+	 * @return string
219
+	 */
220
+	public function _build_observer($klass, $name, $options = null)
221
+	{
222
+		if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
+			$options['with'] = '\'' . $options['with'] . '=\' + value';
224
+		} elseif (isset($options['with']) && isset($options['update'])) {
225
+			$options['with'] = 'value';
226
+		}
227
+
228
+		$callback = $options['function'] ?: $this->remote_function($options);
229
+
230
+		$javascript = "new $klass('$name', ";
231
+		$javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
232
+		$javascript .= 'function (element,value) { ';
233
+		$javascript .= $callback;
234
+		$javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
235
+		$javascript .= '})';
236
+
237
+		return $javascript;
238
+	}
239
+
240
+	/**
241
+	 * @param $method
242
+	 * @return string
243
+	 */
244
+	public function _method_option_to_s($method)
245
+	{
246
+		return strstr($method, "'") ? $method : "'$method'";
247
+	}
248
+
249
+	/**
250
+	 * @param $options
251
+	 * @return string
252
+	 */
253
+	public function _options_for_ajax($options)
254
+	{
255
+		$js_options = is_array($options) ? $this->_build_callbacks($options) : [];
256
+
257
+		if (isset($options['type']) && 'synchronous' === $option['type']) {
258
+			$js_options['asynchronous'] = 'false';
259
+		}
260
+
261
+		if (isset($options['method'])) {
262
+			$js_options['method'] = $this->_method_option_to_s($options['method']);
263
+		}
264
+
265
+		if (isset($options['position'])) {
266
+			$js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
267
+		}
268
+
269
+		$js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
270
+
271
+		if (isset($options['form'])) {
272
+			$js_options['parameters'] = 'Form.serialize(this)';
273
+		} elseif (isset($options['parameters'])) {
274
+			$js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
275
+		} elseif (isset($options['with'])) {
276
+			$js_options['parameters'] = $options['with'];
277
+		}
278
+
279
+		return $this->_options_for_javascript($js_options);
280
+	}
281
+
282
+	/////////////////////////////////////////////////////////////////////////////////////
283
+	//                            Mergerd Javascript Generator helpers
284
+	/////////////////////////////////////////////////////////////////////////////////////
285
+
286
+	/**
287
+	 * @param $javascript
288
+	 */
289
+	public function dump($javascript)
290
+	{
291
+		echo $javascript;
292
+	}
293
+
294
+	/**
295
+	 * @param         $id
296
+	 * @param  null   $extend
297
+	 * @return string
298
+	 */
299
+	public function ID($id, $extend = null)
300
+	{
301
+		return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
302
+	}
303
+
304
+	/**
305
+	 * @param $message
306
+	 * @return string
307
+	 */
308
+	public function alert($message)
309
+	{
310
+		return $this->call('alert', $message);
311
+	}
312
+
313
+	/**
314
+	 * @param $variable
315
+	 * @param $value
316
+	 * @return string
317
+	 */
318
+	public function assign($variable, $value)
319
+	{
320
+		return "$variable = $value;";
321
+	}
322
+
323
+	/**
324
+	 * @param         $function
325
+	 * @param  null   $args
326
+	 * @return string
327
+	 */
328
+	public function call($function, $args = null)
329
+	{
330
+		$arg_str = '';
331
+		if (is_array($args)) {
332
+			foreach ($args as $arg) {
333
+				if (!empty($arg_str)) {
334
+					$arg_str .= ', ';
335
+				}
336
+				if (is_string($arg)) {
337
+					$arg_str .= "'$arg'";
338
+				} else {
339
+					$arg_str .= $arg;
340
+				}
341
+			}
342
+		} else {
343
+			if (is_string($args)) {
344
+				$arg_str .= "'$args'";
345
+			} else {
346
+				$arg_str .= $args;
347
+			}
348
+		}
349
+
350
+		return "$function($arg_str)";
351
+	}
352
+
353
+	/**
354
+	 * @param  int    $seconds
355
+	 * @param  string $script
356
+	 * @return string
357
+	 */
358
+	public function delay($seconds = 1, $script = '')
359
+	{
360
+		return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
361
+	}
362
+
363
+	/**
364
+	 * @param $id
365
+	 * @return string
366
+	 */
367
+	public function hide($id)
368
+	{
369
+		return $this->call('Element.hide', $id);
370
+	}
371
+
372
+	/**
373
+	 * @param         $position
374
+	 * @param         $id
375
+	 * @param  null   $options_for_render
376
+	 * @return string
377
+	 */
378
+	public function insert_html($position, $id, $options_for_render = null)
379
+	{
380
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381
+
382
+		return $this->call('new Insertion.' . ucfirst($position), $args);
383
+	}
384
+
385
+	/**
386
+	 * @param $location
387
+	 * @return string
388
+	 */
389
+	public function redirect_to($location)
390
+	{
391
+		return $this->assign('window.location.href', $location);
392
+	}
393
+
394
+	/**
395
+	 * @param $id
396
+	 * @return string
397
+	 */
398
+	public function remove($id)
399
+	{
400
+		if (is_array($id)) {
401
+			$arr_str = '';
402
+			foreach ($id as $obj) {
403
+				if (!empty($arg_str)) {
404
+					$arg_str .= ', ';
405
+				}
406
+				$arg_str .= "'$arg'";
407
+			}
408
+
409
+			return "$A[$arg_str].each(Element.remove)";
410
+		} else {
411
+			return "Element.remove('$id')";
412
+		}
413
+	}
414
+
415
+	/**
416
+	 * @param $id
417
+	 * @param $options_for_render
418
+	 * @return string
419
+	 */
420
+	public function replace($id, $options_for_render)
421
+	{
422
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
423
+
424
+		return $this->call('Element.replace', $args);
425
+	}
426
+
427
+	/**
428
+	 * @param $id
429
+	 * @param $options_for_render
430
+	 * @return string
431
+	 */
432
+	public function replace_html($id, $options_for_render)
433
+	{
434
+		$args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
435
+
436
+		return $this->call('Element.update', $args);
437
+	}
438
+
439
+	/**
440
+	 * @param         $pattern
441
+	 * @param  null   $extend
442
+	 * @return string
443
+	 */
444
+	public function select($pattern, $extend = null)
445
+	{
446
+		return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
447
+	}
448
+
449
+	/**
450
+	 * @param $id
451
+	 * @return string
452
+	 */
453
+	public function show($id)
454
+	{
455
+		return $this->call('Element.show', $id);
456
+	}
457
+
458
+	/**
459
+	 * @param $id
460
+	 * @return string
461
+	 */
462
+	public function toggle($id)
463
+	{
464
+		return $this->call('Element.toggle', $id);
465
+	}
466 466
 }
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     {
64 64
         $options['form'] = true;
65 65
 
66
-        return '<form action="' . $options['url'] . '" onsubmit="' . $this->remote_function($options) . '; return false;" method="' . (isset($options['method']) ? $options['method'] : 'post') . '"  >';
66
+        return '<form action="'.$options['url'].'" onsubmit="'.$this->remote_function($options).'; return false;" method="'.(isset($options['method']) ? $options['method'] : 'post').'"  >';
67 67
     }
68 68
 
69 69
     /**
@@ -112,7 +112,7 @@  discard block
 block discarded – undo
112 112
     public function periodically_call_remote($options = null)
113 113
     {
114 114
         $frequency = isset($options['frequency']) ? $options['frequency'] : 10;
115
-        $code      = 'new PeriodicalExecuter(function() {' . $this->remote_function($options) . '},' . $frequency . ')';
115
+        $code      = 'new PeriodicalExecuter(function() {'.$this->remote_function($options).'},'.$frequency.')';
116 116
 
117 117
         return $code;
118 118
     }
@@ -128,22 +128,22 @@  discard block
 block discarded – undo
128 128
         $update = '';
129 129
 
130 130
         if (isset($options['update']) && is_array($options['update'])) {
131
-            $update = isset($options['update']['success']) ? 'success: ' . $options['update']['success'] : '';
131
+            $update = isset($options['update']['success']) ? 'success: '.$options['update']['success'] : '';
132 132
             $update .= empty($update) ? '' : ',';
133
-            $update .= isset($options['update']['failure']) ? 'failure: ' . $options['update']['failure'] : '';
133
+            $update .= isset($options['update']['failure']) ? 'failure: '.$options['update']['failure'] : '';
134 134
         } else {
135 135
             $update .= isset($options['update']) ? $options['update'] : '';
136 136
         }
137 137
 
138
-        $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\'' . $update . '\',';
138
+        $ajax_function = empty($update) ? 'new Ajax.Request(' : 'new Ajax.Updater(\''.$update.'\',';
139 139
 
140
-        $ajax_function .= "'" . $options['url'] . "'";
141
-        $ajax_function .= ',' . $javascript_options . ')';
140
+        $ajax_function .= "'".$options['url']."'";
141
+        $ajax_function .= ','.$javascript_options.')';
142 142
 
143
-        $ajax_function = isset($options['before']) ? $options['before'] . ';' . $ajax_function : $ajax_function;
144
-        $ajax_function = isset($options['after']) ? $ajax_function . ';' . $options['after'] : $ajax_function;
145
-        $ajax_function = isset($options['condition']) ? 'if (' . $options['condition'] . ') {' . $ajax_function . '}' : $ajax_function;
146
-        $ajax_function = isset($options['confirm']) ? 'if ( confirm(\'' . $options['confirm'] . '\' ) ) { ' . $ajax_function . ' } ' : $ajax_function;
143
+        $ajax_function = isset($options['before']) ? $options['before'].';'.$ajax_function : $ajax_function;
144
+        $ajax_function = isset($options['after']) ? $ajax_function.';'.$options['after'] : $ajax_function;
145
+        $ajax_function = isset($options['condition']) ? 'if ('.$options['condition'].') {'.$ajax_function.'}' : $ajax_function;
146
+        $ajax_function = isset($options['confirm']) ? 'if ( confirm(\''.$options['confirm'].'\' ) ) { '.$ajax_function.' } ' : $ajax_function;
147 147
 
148 148
         return $ajax_function;
149 149
     }
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
             $options['with'] = 'Form.serialize(this.form)';
161 161
         }
162 162
 
163
-        return '<input type="button" onclick="' . $this->remote_function($options) . '" name="' . $name . '" value ="' . $value . '">';
163
+        return '<input type="button" onclick="'.$this->remote_function($options).'" name="'.$name.'" value ="'.$value.'">';
164 164
     }
165 165
 
166 166
     /**
@@ -203,8 +203,8 @@  discard block
 block discarded – undo
203 203
         $callbacks = [];
204 204
         foreach ($options as $callback => $code) {
205 205
             if (in_array($callback, $this->CALLBACKS)) {
206
-                $name             = 'on' . ucfirst($callback);
207
-                $callbacks[$name] = 'function(request){' . $code . '}';
206
+                $name             = 'on'.ucfirst($callback);
207
+                $callbacks[$name] = 'function(request){'.$code.'}';
208 208
             }
209 209
         }
210 210
 
@@ -220,7 +220,7 @@  discard block
 block discarded – undo
220 220
     public function _build_observer($klass, $name, $options = null)
221 221
     {
222 222
         if (isset($options['with']) && false === strpos($options['with'], '=')) {
223
-            $options['with'] = '\'' . $options['with'] . '=\' + value';
223
+            $options['with'] = '\''.$options['with'].'=\' + value';
224 224
         } elseif (isset($options['with']) && isset($options['update'])) {
225 225
             $options['with'] = 'value';
226 226
         }
@@ -228,10 +228,10 @@  discard block
 block discarded – undo
228 228
         $callback = $options['function'] ?: $this->remote_function($options);
229 229
 
230 230
         $javascript = "new $klass('$name', ";
231
-        $javascript .= isset($options['frequency']) ? $options['frequency'] . ', ' : '';
231
+        $javascript .= isset($options['frequency']) ? $options['frequency'].', ' : '';
232 232
         $javascript .= 'function (element,value) { ';
233 233
         $javascript .= $callback;
234
-        $javascript .= isset($options['on']) ? ', ' . $options['on'] : '';
234
+        $javascript .= isset($options['on']) ? ', '.$options['on'] : '';
235 235
         $javascript .= '})';
236 236
 
237 237
         return $javascript;
@@ -263,7 +263,7 @@  discard block
 block discarded – undo
263 263
         }
264 264
 
265 265
         if (isset($options['position'])) {
266
-            $js_options['insertion'] = 'Insertion.' . ucfirst($options['position']);
266
+            $js_options['insertion'] = 'Insertion.'.ucfirst($options['position']);
267 267
         }
268 268
 
269 269
         $js_options['evalScripts'] = isset($options['script']) ? $options['script'] : 'true';
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
         if (isset($options['form'])) {
272 272
             $js_options['parameters'] = 'Form.serialize(this)';
273 273
         } elseif (isset($options['parameters'])) {
274
-            $js_options['parameters'] = 'Form.serialize(\'' . $options['submit'] . '\')';
274
+            $js_options['parameters'] = 'Form.serialize(\''.$options['submit'].'\')';
275 275
         } elseif (isset($options['with'])) {
276 276
             $js_options['parameters'] = $options['with'];
277 277
         }
@@ -298,7 +298,7 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public function ID($id, $extend = null)
300 300
     {
301
-        return "$('$id')" . (!empty($extend)) ? '.' . $extend . '()' : '';
301
+        return "$('$id')".(!empty($extend)) ? '.'.$extend.'()' : '';
302 302
     }
303 303
 
304 304
     /**
@@ -357,7 +357,7 @@  discard block
 block discarded – undo
357 357
      */
358 358
     public function delay($seconds = 1, $script = '')
359 359
     {
360
-        return "setTimeout( function() { $script } , " . ($seconds * 1000) . ' )';
360
+        return "setTimeout( function() { $script } , ".($seconds * 1000).' )';
361 361
     }
362 362
 
363 363
     /**
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
     {
380 380
         $args = array_merge([$id], (is_array($options_for_render) ? $options_for_render : [$options_for_render]));
381 381
 
382
-        return $this->call('new Insertion.' . ucfirst($position), $args);
382
+        return $this->call('new Insertion.'.ucfirst($position), $args);
383 383
     }
384 384
 
385 385
     /**
@@ -443,7 +443,7 @@  discard block
 block discarded – undo
443 443
      */
444 444
     public function select($pattern, $extend = null)
445 445
     {
446
-        return "$$('$pattern')" . (!empty($extend)) ? '.' . $extend : '';
446
+        return "$$('$pattern')".(!empty($extend)) ? '.'.$extend : '';
447 447
     }
448 448
 
449 449
     /**
Please login to merge, or discard this patch.
header.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  * Licence: GNU
7 7
  */
8 8
 
9
-include __DIR__ . '/../../mainfile.php';
10
-require_once XOOPS_ROOT_PATH . '/modules/smartobject/include/common.php';
9
+include __DIR__.'/../../mainfile.php';
10
+require_once XOOPS_ROOT_PATH.'/modules/smartobject/include/common.php';
11 11
 
12 12
 smart_loadCommonLanguageFile();
Please login to merge, or discard this patch.
class/smartobjecttree.php 2 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -9,17 +9,17 @@
 block discarded – undo
9 9
  */
10 10
 class SmartObjectTree extends XoopsObjectTree
11 11
 {
12
-    public function _initialize()
13
-    {
14
-        foreach (array_keys($this->_objects) as $i) {
15
-            $key1                         = $this->_objects[$i]->getVar($this->_myId);
16
-            $this->tree[$key1]['obj']     = $this->_objects[$i];
17
-            $key2                         = $this->_objects[$i]->getVar($this->_parentId, 'e');
18
-            $this->tree[$key1]['parent']  = $key2;
19
-            $this->tree[$key2]['child'][] = $key1;
20
-            if (isset($this->_rootId)) {
21
-                $this->tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId);
22
-            }
23
-        }
24
-    }
12
+	public function _initialize()
13
+	{
14
+		foreach (array_keys($this->_objects) as $i) {
15
+			$key1                         = $this->_objects[$i]->getVar($this->_myId);
16
+			$this->tree[$key1]['obj']     = $this->_objects[$i];
17
+			$key2                         = $this->_objects[$i]->getVar($this->_parentId, 'e');
18
+			$this->tree[$key1]['parent']  = $key2;
19
+			$this->tree[$key2]['child'][] = $key1;
20
+			if (isset($this->_rootId)) {
21
+				$this->tree[$key1]['root'] = $this->_objects[$i]->getVar($this->_rootId);
22
+			}
23
+		}
24
+	}
25 25
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
2 2
 
3 3
 // defined('XOOPS_ROOT_PATH') || exit('Restricted access.');
4 4
 
5
-require_once XOOPS_ROOT_PATH . '/class/tree.php';
5
+require_once XOOPS_ROOT_PATH.'/class/tree.php';
6 6
 
7 7
 /**
8 8
  * Class smartobjecttree
Please login to merge, or discard this patch.
class/form/elements/smartformimageuploadelement.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
  */
17 17
 class SmartFormImageUploadElement extends SmartFormUploadElement
18 18
 {
19
-    /**
20
-     * SmartFormImageUploadElement constructor.
21
-     * @param string $object
22
-     * @param string $key
23
-     */
24
-    public function __construct($object, $key)
25
-    {
26
-        $this->SmartFormFileElement($object, $key);
27
-        // Override name for upload purposes
28
-        $this->setName('upload_' . $key);
29
-    }
19
+	/**
20
+	 * SmartFormImageUploadElement constructor.
21
+	 * @param string $object
22
+	 * @param string $key
23
+	 */
24
+	public function __construct($object, $key)
25
+	{
26
+		$this->SmartFormFileElement($object, $key);
27
+		// Override name for upload purposes
28
+		$this->setName('upload_' . $key);
29
+	}
30 30
 
31
-    /**
32
-     * prepare HTML for output
33
-     *
34
-     * @return string HTML
35
-     */
36
-    public function render()
37
-    {
38
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
31
+	/**
32
+	 * prepare HTML for output
33
+	 *
34
+	 * @return string HTML
35
+	 */
36
+	public function render()
37
+	{
38
+		return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
39 39
         <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . ">
40 40
         <input type='hidden' name='smart_upload_image[]' id='smart_upload_image[]' value='" . $this->getName() . "'>";
41
-    }
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @package    SmartObject
10 10
  * @subpackage SmartObjectForm
11 11
  */
12
-require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformuploadelement.php';
12
+require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformuploadelement.php';
13 13
 
14 14
 /**
15 15
  * Class SmartFormImageUploadElement
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     {
26 26
         $this->SmartFormFileElement($object, $key);
27 27
         // Override name for upload purposes
28
-        $this->setName('upload_' . $key);
28
+        $this->setName('upload_'.$key);
29 29
     }
30 30
 
31 31
     /**
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function render()
37 37
     {
38
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
39
-        <input type='file' name='" . $this->getName() . "' id='" . $this->getName() . "'" . $this->getExtra() . ">
40
-        <input type='hidden' name='smart_upload_image[]' id='smart_upload_image[]' value='" . $this->getName() . "'>";
38
+        return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'>
39
+        <input type='file' name='" . $this->getName()."' id='".$this->getName()."'".$this->getExtra().">
40
+        <input type='hidden' name='smart_upload_image[]' id='smart_upload_image[]' value='" . $this->getName()."'>";
41 41
     }
42 42
 }
Please login to merge, or discard this patch.
class/form/elements/smartformfileuploadelement.php 2 patches
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -16,27 +16,27 @@
 block discarded – undo
16 16
  */
17 17
 class SmartFormFileUploadElement extends SmartFormUploadElement
18 18
 {
19
-    /**
20
-     * SmartFormFileUploadElement constructor.
21
-     * @param string $object
22
-     * @param string $key
23
-     */
24
-    public function __construct($object, $key)
25
-    {
26
-        $this->SmartFormFileElement($object, $key);
27
-        // Override name for upload purposes
28
-        $this->setName('upload_' . $key);
29
-    }
19
+	/**
20
+	 * SmartFormFileUploadElement constructor.
21
+	 * @param string $object
22
+	 * @param string $key
23
+	 */
24
+	public function __construct($object, $key)
25
+	{
26
+		$this->SmartFormFileElement($object, $key);
27
+		// Override name for upload purposes
28
+		$this->setName('upload_' . $key);
29
+	}
30 30
 
31
-    /**
32
-     * prepare HTML for output
33
-     *
34
-     * @return string HTML
35
-     */
36
-    public function render()
37
-    {
38
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
31
+	/**
32
+	 * prepare HTML for output
33
+	 *
34
+	 * @return string HTML
35
+	 */
36
+	public function render()
37
+	{
38
+		return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
39 39
         <input type='file' name='upload_" . $this->getName() . "' id='upload_" . $this->getName() . "'" . $this->getExtra() . ">
40 40
         <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>";
41
-    }
41
+	}
42 42
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  * @package    SmartObject
10 10
  * @subpackage SmartObjectForm
11 11
  */
12
-require_once SMARTOBJECT_ROOT_PATH . 'class/form/elements/smartformuploadelement.php';
12
+require_once SMARTOBJECT_ROOT_PATH.'class/form/elements/smartformuploadelement.php';
13 13
 
14 14
 /**
15 15
  * Class SmartFormFileUploadElement
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
     {
26 26
         $this->SmartFormFileElement($object, $key);
27 27
         // Override name for upload purposes
28
-        $this->setName('upload_' . $key);
28
+        $this->setName('upload_'.$key);
29 29
     }
30 30
 
31 31
     /**
@@ -35,8 +35,8 @@  discard block
 block discarded – undo
35 35
      */
36 36
     public function render()
37 37
     {
38
-        return "<input type='hidden' name='MAX_FILE_SIZE' value='" . $this->getMaxFileSize() . "'>
39
-        <input type='file' name='upload_" . $this->getName() . "' id='upload_" . $this->getName() . "'" . $this->getExtra() . ">
40
-        <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName() . "'>";
38
+        return "<input type='hidden' name='MAX_FILE_SIZE' value='".$this->getMaxFileSize()."'>
39
+        <input type='file' name='upload_" . $this->getName()."' id='upload_".$this->getName()."'".$this->getExtra().">
40
+        <input type='hidden' name='smart_upload_file[]' id='smart_upload_file[]' value='" . $this->getName()."'>";
41 41
     }
42 42
 }
Please login to merge, or discard this patch.
class/form/elements/smartautocompleteelement.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -11,38 +11,38 @@
 block discarded – undo
11 11
  */
12 12
 class SmartAutocompleteElement extends XoopsFormText
13 13
 {
14
-    public $_include_file;
14
+	public $_include_file;
15 15
 
16
-    /**
17
-     * SmartAutocompleteElement constructor.
18
-     * @param string $caption
19
-     * @param string $name
20
-     * @param int    $include_file
21
-     * @param int    $size
22
-     * @param string $maxlength
23
-     * @param string $value
24
-     */
25
-    public function __construct($caption, $name, $include_file, $size, $maxlength, $value = '')
26
-    {
27
-        $this->_include_file = $include_file;
28
-        parent::__construct($caption, $name, $size, $maxlength, $value);
29
-    }
16
+	/**
17
+	 * SmartAutocompleteElement constructor.
18
+	 * @param string $caption
19
+	 * @param string $name
20
+	 * @param int    $include_file
21
+	 * @param int    $size
22
+	 * @param string $maxlength
23
+	 * @param string $value
24
+	 */
25
+	public function __construct($caption, $name, $include_file, $size, $maxlength, $value = '')
26
+	{
27
+		$this->_include_file = $include_file;
28
+		parent::__construct($caption, $name, $size, $maxlength, $value);
29
+	}
30 30
 
31
-    /**
32
-     * Prepare HTML for output
33
-     *
34
-     * @return string HTML
35
-     */
36
-    public function render()
37
-    {
38
-        $ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>';
31
+	/**
32
+	 * Prepare HTML for output
33
+	 *
34
+	 * @return string HTML
35
+	 */
36
+	public function render()
37
+	{
38
+		$ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>';
39 39
 
40
-        $ret .= '   <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div>
40
+		$ret .= '   <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div>
41 41
 
42 42
     <script type="text/javascript">
43 43
         new Ajax.Autocompleter("' . $this->getName() . '","smartobject_autocomplete_hint' . $this->getName() . '","' . $this->_include_file . '?key=' . $this->getName() . '");
44 44
     </script>';
45 45
 
46
-        return $ret;
47
-    }
46
+		return $ret;
47
+	}
48 48
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -35,12 +35,12 @@
 block discarded – undo
35 35
      */
36 36
     public function render()
37 37
     {
38
-        $ret = "<input type='text' name='" . $this->getName() . "' id='" . $this->getName() . "' size='" . $this->getSize() . "' maxlength='" . $this->getMaxlength() . "' value='" . $this->getValue() . "'" . $this->getExtra() . '>';
38
+        $ret = "<input type='text' name='".$this->getName()."' id='".$this->getName()."' size='".$this->getSize()."' maxlength='".$this->getMaxlength()."' value='".$this->getValue()."'".$this->getExtra().'>';
39 39
 
40
-        $ret .= '   <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint' . $this->getName() . '"></div>
40
+        $ret .= '   <div class="smartobject_autocomplete_hint" id="smartobject_autocomplete_hint'.$this->getName().'"></div>
41 41
 
42 42
     <script type="text/javascript">
43
-        new Ajax.Autocompleter("' . $this->getName() . '","smartobject_autocomplete_hint' . $this->getName() . '","' . $this->_include_file . '?key=' . $this->getName() . '");
43
+        new Ajax.Autocompleter("' . $this->getName().'","smartobject_autocomplete_hint'.$this->getName().'","'.$this->_include_file.'?key='.$this->getName().'");
44 44
     </script>';
45 45
 
46 46
         return $ret;
Please login to merge, or discard this patch.