Passed
Pull Request — master (#1301)
by Michael
05:46
created

XoopsBlock::getAllByGroupModule()   F

Complexity

Conditions 15
Paths 566

Size

Total Lines 60
Code Lines 44

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 15
eloc 44
nc 566
nop 6
dl 0
loc 60
rs 2.3527
c 1
b 0
f 0

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
/**
3
 * XOOPS Kernel Class
4
 *
5
 * You may not change or alter any portion of this comment or credits
6
 * of supporting developers from this source code or any supporting source code
7
 * which is considered copyrighted (c) material of the original comment or credit authors.
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 *
12
 * @copyright       (c) 2000-2021 XOOPS Project (www.xoops.org)
13
 * @license             GNU GPL 2 (https://www.gnu.org/licenses/gpl-2.0.html)
14
 * @package             kernel
15
 * @since               2.0.0
16
 * @author              Kazumi Ono (AKA onokazu) http://www.myweb.ne.jp/, http://jp.xoops.org/
17
 */
18
defined('XOOPS_ROOT_PATH') || exit('Restricted access');
19
20
/**
21
 * A block
22
 *
23
 * @author  Kazumi Ono <[email protected]>
24
 *
25
 * @package kernel
26
 *
27
 * @todo reconcile the two XoopsBlock classes.
28
 * @internal This handler appears to only be loaded by system/class/group.php
29
 * @internal The other, in class/xoopsblock.php is loaded all over
30
 */
31
class XoopsBlock extends XoopsObject
32
{
33
    //PHP 8.2 Dynamic properties deprecated
34
    public $bid;
35
    public $mid;
36
    public $func_num;
37
    public $options;
38
    public $name;
39
    //public $position;
40
    public $title;
41
    public $content;
42
    public $side;
43
    public $weight;
44
    public $visible;
45
    public $block_type;
46
    public $c_type;
47
    public $isactive;
48
    public $dirname;
49
    public $func_file;
50
    public $show_func;
51
    public $edit_func;
52
    public $template;
53
    public $bcachetime;
54
    public $last_modified;
55
56
    /**
57
     * constructor
58
     *
59
     * @param mixed $id
60
     **/
61
    public function __construct($id = null)
62
    {
63
        $this->initVar('bid', XOBJ_DTYPE_INT, null, false);
64
        $this->initVar('mid', XOBJ_DTYPE_INT, 0, false);
65
        $this->initVar('func_num', XOBJ_DTYPE_INT, 0, false);
66
        $this->initVar('options', XOBJ_DTYPE_TXTBOX, null, false, 255);
67
        $this->initVar('name', XOBJ_DTYPE_TXTBOX, null, true, 150);
68
        //$this->initVar('position', XOBJ_DTYPE_INT, 0, false);
69
        $this->initVar('title', XOBJ_DTYPE_TXTBOX, null, false, 150);
70
        $this->initVar('content', XOBJ_DTYPE_TXTAREA, null, false);
71
        $this->initVar('side', XOBJ_DTYPE_INT, 0, false);
72
        $this->initVar('weight', XOBJ_DTYPE_INT, 0, false);
73
        $this->initVar('visible', XOBJ_DTYPE_INT, 0, false);
74
        $this->initVar('block_type', XOBJ_DTYPE_OTHER, null, false);
75
        $this->initVar('c_type', XOBJ_DTYPE_OTHER, null, false);
76
        $this->initVar('isactive', XOBJ_DTYPE_INT, null, false);
77
        $this->initVar('dirname', XOBJ_DTYPE_TXTBOX, null, false, 50);
78
        $this->initVar('func_file', XOBJ_DTYPE_TXTBOX, null, false, 50);
79
        $this->initVar('show_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
80
        $this->initVar('edit_func', XOBJ_DTYPE_TXTBOX, null, false, 50);
81
        $this->initVar('template', XOBJ_DTYPE_OTHER, null, false);
82
        $this->initVar('bcachetime', XOBJ_DTYPE_INT, 0, false);
83
        $this->initVar('last_modified', XOBJ_DTYPE_INT, 0, false);
84
85
        parent::__construct();
86
87
        // for backward compatibility
88
        if (isset($id)) {
89
            if (is_array($id)) {
90
                $this->assignVars($id);
91
            } else {
92
                $blkhandler = xoops_getHandler('block');
93
                $obj        = $blkhandler->get($id);
94
                foreach (array_keys($obj->getVars()) as $i) {
95
                    $this->assignVar($i, $obj->getVar($i, 'n'));
96
                }
97
            }
98
        }
99
    }
100
101
    /**
102
     * Returns Class Base Variable bid
103
     * @param string $format
104
     * @return mixed
105
     */
106
    public function id($format = 'n')
107
    {
108
        return $this->getVar('bid', $format);
109
    }
110
111
    /**
112
     * Returns Class Base Variable bid
113
     * @param string $format
114
     * @return mixed
115
     */
116
    public function bid($format = '')
117
    {
118
        return $this->getVar('bid', $format);
119
    }
120
121
    /**
122
     * Returns Class Base Variable mid
123
     * @param string $format
124
     * @return mixed
125
     */
126
    public function mid($format = '')
127
    {
128
        return $this->getVar('mid', $format);
129
    }
130
131
    /**
132
     * Returns Class Base Variable func_num
133
     * @param string $format
134
     * @return mixed
135
     */
136
    public function func_num($format = '')
137
    {
138
        return $this->getVar('func_num', $format);
139
    }
140
141
    /**
142
     * Returns Class Base Variable avatar_id
143
     * @param string $format
144
     * @return mixed
145
     */
146
    public function options($format = '')
147
    {
148
        return $this->getVar('options', $format);
149
    }
150
151
    /**
152
     * Returns Class Base Variable name
153
     * @param string $format
154
     * @return mixed
155
     */
156
    public function name($format = '')
157
    {
158
        return $this->getVar('name', $format);
159
    }
160
161
    /**
162
     * Returns Class Base Variable title
163
     * @param string $format
164
     * @return mixed
165
     */
166
    public function title($format = '')
167
    {
168
        return $this->getVar('title', $format);
169
    }
170
171
    /**
172
     * Returns Class Base Variable content
173
     * @param string $format
174
     * @return mixed
175
     */
176
    public function content($format = '')
177
    {
178
        return $this->getVar('content', $format);
179
    }
180
181
    /**
182
     * Returns Class Base Variable side
183
     * @param string $format
184
     * @return mixed
185
     */
186
    public function side($format = '')
187
    {
188
        return $this->getVar('side', $format);
189
    }
190
191
    /**
192
     * Returns Class Base Variable weight
193
     * @param string $format
194
     * @return mixed
195
     */
196
    public function weight($format = '')
197
    {
198
        return $this->getVar('weight', $format);
199
    }
200
201
    /**
202
     * Returns Class Base Variable visible
203
     * @param string $format
204
     * @return mixed
205
     */
206
    public function visible($format = '')
207
    {
208
        return $this->getVar('visible', $format);
209
    }
210
211
    /**
212
     * Returns Class Base Variable block_type
213
     *
214
     * Vaild block_type values are:
215
     * S - generated by system module
216
     * M - generated by a non-system module
217
     * C - Custom block
218
     * D - cloned system/module block
219
     * E - cloned custom block, DON'T use it
220
     *
221
     * @param string $format
222
     *
223
     * @return mixed
224
     */
225
    public function block_type($format = '')
226
    {
227
        return $this->getVar('block_type', $format);
228
    }
229
230
    /**
231
     * Returns Class Base Variable c_type
232
     * @param string $format
233
     * @return mixed
234
     */
235
    public function c_type($format = '')
236
    {
237
        return $this->getVar('c_type', $format);
238
    }
239
240
    /**
241
     * Returns Class Base Variable isactive
242
     * @param string $format
243
     * @return mixed
244
     */
245
    public function isactive($format = '')
246
    {
247
        return $this->getVar('isactive', $format);
248
    }
249
250
    /**
251
     * Returns Class Base Variable dirname
252
     * @param string $format
253
     * @return mixed
254
     */
255
    public function dirname($format = '')
256
    {
257
        return $this->getVar('dirname', $format);
258
    }
259
260
    /**
261
     * Returns Class Base Variable func_file
262
     * @param string $format
263
     * @return mixed
264
     */
265
    public function func_file($format = '')
266
    {
267
        return $this->getVar('func_file', $format);
268
    }
269
270
    /**
271
     * Returns Class Base Variable show_func
272
     * @param string $format
273
     * @return mixed
274
     */
275
    public function show_func($format = '')
276
    {
277
        return $this->getVar('show_func', $format);
278
    }
279
280
    /**
281
     * Returns Class Base Variable edit_func
282
     * @param string $format
283
     * @return mixed
284
     */
285
    public function edit_func($format = '')
286
    {
287
        return $this->getVar('edit_func', $format);
288
    }
289
290
    /**
291
     * Returns Class Base Variable template
292
     * @param string $format
293
     * @return mixed
294
     */
295
    public function template($format = '')
296
    {
297
        return $this->getVar('template', $format);
298
    }
299
300
    /**
301
     * Returns Class Base Variable avatar_id
302
     * @param string $format
303
     * @return mixed
304
     */
305
    public function bcachetime($format = '')
306
    {
307
        return $this->getVar('bcachetime', $format);
308
    }
309
310
    /**
311
     * Returns Class Base Variable last_modified
312
     * @param string $format
313
     * @return mixed
314
     */
315
    public function last_modified($format = '')
316
    {
317
        return $this->getVar('last_modified', $format);
318
    }
319
320
    /**
321
     * return the content of the block for output
322
     *
323
     * @param  string $format
324
     * @param  string $c_type type of content
325
     *                        Valid values for the type of content:
326
     *                        H : custom HTML block
327
     *                        P : custom PHP block
328
     *                        S : use text sanitizer (smilies enabled)
329
     *                        T : use text sanitizer (smilies disabled)</ul>
330
     * @return string content for output
331
     */
332
    public function getContent($format = 's', $c_type = 'T')
333
    {
334
        $format = strtolower($format);
335
        $c_type = strtoupper($c_type);
336
        switch ($format) {
337
            case 's':
338
                if ($c_type === 'H') {
339
                    return str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n'));
340
                } elseif ($c_type === 'P') {
341
                    ob_start();
342
                    echo eval($this->getVar('content', 'n'));
0 ignored issues
show
introduced by
The use of eval() is discouraged.
Loading history...
343
                    $content = ob_get_contents();
344
                    ob_end_clean();
345
346
                    return str_replace('{X_SITEURL}', XOOPS_URL . '/', $content);
347
                } elseif ($c_type === 'S') {
348
                    $myts    = \MyTextSanitizer::getInstance();
349
                    $content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n'));
350
351
                    return $myts->displayTarea($content, 0, 1);
352
                } else {
353
                    $myts    = \MyTextSanitizer::getInstance();
354
                    $content = str_replace('{X_SITEURL}', XOOPS_URL . '/', $this->getVar('content', 'n'));
355
356
                    return $myts->displayTarea($content, 0, 0);
357
                }
358
                break;
359
            case 'e':
360
                return $this->getVar('content', 'e');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getVar('content', 'e') also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
361
                break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
362
            default:
363
                return $this->getVar('content', 'n');
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->getVar('content', 'n') also could return the type array|boolean which is incompatible with the documented return type string.
Loading history...
364
                break;
365
        }
366
    }
367
368
    /**
369
     * (HTML-) form for setting the options of the block
370
     *
371
     * @return string HTML for the form, FALSE if not defined for this block
372
     */
373
    public function getOptions()
374
    {
375
        if (!$this->isCustom()) {
376
            $edit_func = $this->getVar('edit_func');
377
            if (!$edit_func) {
378
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
379
            }
380
            if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file'))) {
381
                if (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php')) {
382
                    include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/blocks.php';
383
                } elseif (file_exists(XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/english/blocks.php')) {
384
                    include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/language/english/blocks.php';
385
                }
386
                include_once XOOPS_ROOT_PATH . '/modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file');
387
                $options   = explode('|', $this->getVar('options'));
388
                $edit_form = $edit_func($options);
389
                if (!$edit_form) {
390
                    return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
391
                }
392
393
                return $edit_form;
394
            } else {
395
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
396
            }
397
        } else {
398
            return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type string.
Loading history...
399
        }
400
    }
401
402
    /**
403
     * @return bool
404
     */
405
    public function isCustom()
406
    {
407
        return in_array($this->getVar('block_type'), array(
408
            'C',
409
            'E'));
410
    }
411
412
    /**
413
     * These methods are for compatibility with the pre 2.5.11 class/xoopsblock.php
414
     * class/xoopsblock.php defined its own XoopsBlock class, making it impossible
415
     * to use with anything that used the handler provided in kernel/block.php
416
     *
417
     * In addition to the actual data, the old XoopsBlock contained what should be
418
     * considered handler logic.
419
     *
420
     * It appears that class/xoopsblock.php came first, but a conversion to the kernel
421
     * handler was never completed.
422
     *
423
     * These methods should all be considered deprecated.
424
     */
425
426
    /**
427
     * Load $id
428
     *
429
     * @param int $id
430
     *
431
     * @deprecated
432
     */
433
    public function load($id)
434
    {
435
        $id  = (int)$id;
436
        /** @var XoopsBlockHandler $blkhandler */
437
        $blkhandler = xoops_getHandler('block');
438
        $obj        = $blkhandler->get($id);
439
        foreach (array_keys($obj->getVars()) as $i) {
440
            $this->assignVar($i, $obj->getVar($i, 'n'));
441
        }
442
    }
443
444
    /**
445
     * Store Block Data to Database
446
     *
447
     * @return int|false id of inserted block, or false on failure
448
     *
449
     * @deprecated
450
     */
451
    public function store()
452
    {
453
        /** @var XoopsBlockHandler $blkhandler */
454
        $blkhandler = xoops_getHandler('block');
455
        if (false === $blkhandler->insert($this)) {
456
            return false;
457
        }
458
        return (int) $this->bid();
459
    }
460
461
    /**
462
     * Delete an ID from the database
463
     *
464
     * @return bool
465
     *
466
     * @deprecated
467
     */
468
    public function delete()
469
    {
470
        /** @var XoopsBlockHandler $blkhandler */
471
        $blkhandler = xoops_getHandler('block');
472
        return $blkhandler->delete($this);
473
    }
474
475
    /**
476
     * Build Block
477
     *
478
     * @return mixed
479
     *
480
     * @deprecated
481
     */
482
    public function buildBlock()
483
    {
484
        global $xoopsConfig, $xoopsOption, $xoTheme;
485
        $block = array();
486
        if (!$this->isCustom()) {
487
            // get block display function
488
            $show_func = $this->getVar('show_func');
489
            if (!$show_func) {
490
                return false;
491
            }
492
            if (!file_exists($func_file = $GLOBALS['xoops']->path('modules/' . $this->getVar('dirname') . '/blocks/' . $this->getVar('func_file')))) {
493
                return false;
494
            }
495
            // must get lang files b4 including the file
496
            // some modules require it for code that is outside the function
497
            xoops_loadLanguage('blocks', $this->getVar('dirname'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('dirname') can also be of type array and array; however, parameter $domain of xoops_loadLanguage() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

497
            xoops_loadLanguage('blocks', /** @scrutinizer ignore-type */ $this->getVar('dirname'));
Loading history...
498
            include_once $func_file;
499
500
            if (function_exists($show_func)) {
501
                // execute the function
502
                $options = explode('|', $this->getVar('options'));
503
                $block   = $show_func($options);
504
                if (!$block) {
505
                    return false;
506
                }
507
            } else {
508
                return false;
509
            }
510
        } else {
511
            // it is a custom block, so just return the contents
512
            $block['content'] = $this->getContent('s', $this->getVar('c_type'));
0 ignored issues
show
Bug introduced by
It seems like $this->getVar('c_type') can also be of type array and array; however, parameter $c_type of XoopsBlock::getContent() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

512
            $block['content'] = $this->getContent('s', /** @scrutinizer ignore-type */ $this->getVar('c_type'));
Loading history...
513
            if (empty($block['content'])) {
514
                return false;
515
            }
516
        }
517
518
        return $block;
519
    }
520
521
    /*
522
    * Aligns the content of a block
523
    * If position is 0, content in DB is positioned
524
    * before the original content
525
    * If position is 1, content in DB is positioned
526
    * after the original content
527
    */
528
    /**
529
     * @param        $position
530
     * @param string $content
531
     * @param string $contentdb
532
     *
533
     * @return string
534
     *
535
     * @deprecated
536
     */
537
    public function buildContent($position, $content = '', $contentdb = '')
538
    {
539
        $ret = null;
540
        if ($position == 0) {
541
            $ret = $contentdb . $content;
542
        } elseif ($position == 1) {
543
            $ret = $content . $contentdb;
544
        }
545
546
        return $ret;
547
    }
548
549
    /**
550
     * Enter description here...
551
     *
552
     * @param  string $originaltitle
553
     * @param  string $newtitle
554
     * @return string title
555
     *
556
     * @deprecated
557
     */
558
    public function buildTitle($originaltitle, $newtitle = '')
559
    {
560
        $ret = $originaltitle;
561
        if ($newtitle != '') {
562
            $ret = $newtitle;
563
        }
564
565
        return $ret;
566
    }
567
568
    /**
569
     * get all the blocks that match the supplied parameters
570
     * @param int|array $groupid  groupid (can be an array)
571
     * @param bool   $asobject
572
     * @param null|string $side     0: sideblock - left
573
     *                         1: sideblock - right
574
     *                         2: sideblock - left and right
575
     *                         3: centerblock - left
576
     *                         4: centerblock - right
577
     *                         5: centerblock - center
578
     *                         6: centerblock - left, right, center
579
     * @param        $visible  0: not visible 1: visible
0 ignored issues
show
Documentation Bug introduced by
The doc comment 0: not at position 0 could not be parsed: Unknown type name '0' at position 0 in 0: not.
Loading history...
580
     * @param string $orderby  order of the blocks
581
     * @param int    $isactive
582
     * @returns array of block objects
583
     *
584
     * @deprecated
585
     */
586
    public static function getAllBlocksByGroup($groupid, $asobject = true, $side = null, $visible = null, $orderby = 'b.weight,b.bid', $isactive = 1)
587
    {
588
        $db  = XoopsDatabaseFactory::getDatabaseConnection();
589
        $ret = array();
590
        $sql = 'SELECT b.* ';
591
        if (!$asobject) {
592
            $sql = 'SELECT b.bid ';
593
        }
594
        $sql .= 'FROM ' . $db->prefix('newblocks') . ' b LEFT JOIN ' . $db->prefix('group_permission') . " l ON l.gperm_itemid=b.bid WHERE gperm_name = 'block_read' AND gperm_modid = 1";
595
        if (is_array($groupid)) {
596
            $sql .= ' AND (l.gperm_groupid=' . $groupid[0] . '';
597
            $size = count($groupid);
598
            if ($size > 1) {
599
                for ($i = 1; $i < $size; ++$i) {
600
                    $sql .= ' OR l.gperm_groupid=' . $groupid[$i] . '';
601
                }
602
            }
603
            $sql .= ')';
604
        } else {
605
            $sql .= ' AND l.gperm_groupid=' . $groupid . '';
606
        }
607
        $sql .= ' AND b.isactive=' . $isactive;
608
        if (isset($side)) {
609
            // get both sides in sidebox? (some themes need this)
610
            if ($side == XOOPS_SIDEBLOCK_BOTH) {
611
                $side = '(b.side=0 OR b.side=1)';
612
            } elseif ($side == XOOPS_CENTERBLOCK_ALL) {
613
                $side = '(b.side=3 OR b.side=4 OR b.side=5 OR b.side=7 OR b.side=8 OR b.side=9 )';
614
            } elseif ($side == XOOPS_FOOTERBLOCK_ALL) {
615
                $side = '(b.side=10 OR b.side=11 OR b.side=12 )';
616
            } else {
617
                $side = 'b.side=' . $side;
618
            }
619
            $sql .= ' AND ' . $side;
620
        }
621
        if (isset($visible)) {
622
            $sql .= " AND b.visible=$visible";
623
        }
624
        $sql .= " ORDER BY $orderby";
625
        $result = $db->query($sql);
0 ignored issues
show
Bug introduced by
The method query() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

625
        /** @scrutinizer ignore-call */ 
626
        $result = $db->query($sql);
Loading history...
626
        if (!$db->isResultSet($result)) {
627
            \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
0 ignored issues
show
Bug introduced by
The method error() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

627
            \trigger_error("Query Failed! SQL: $sql- Error: " . $db->/** @scrutinizer ignore-call */ error(), E_USER_ERROR);
Loading history...
628
        }
629
        $added  = array();
630
        while (false !== ($myrow = $db->fetchArray($result))) {
0 ignored issues
show
Bug introduced by
The method fetchArray() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

630
        while (false !== ($myrow = $db->/** @scrutinizer ignore-call */ fetchArray($result))) {
Loading history...
631
            if (!in_array($myrow['bid'], $added)) {
632
                if (!$asobject) {
633
                    $ret[] = $myrow['bid'];
634
                } else {
635
                    $ret[] = new XoopsBlock($myrow);
636
                }
637
                $added[] = $myrow['bid'];
638
            }
639
        }
640
641
        return $ret;
642
    }
643
644
    /**
645
     * XoopsBlock::getAllBlocks()
646
     *
647
     * @param  string  $rettype
648
     * @param  mixed   $side
649
     * @param  mixed   $visible
650
     * @param  string  $orderby
651
     * @param  integer $isactive
652
     * @return array
653
     *
654
     * @deprecated
655
     */
656
    public function getAllBlocks($rettype = 'object', $side = null, $visible = null, $orderby = 'side,weight,bid', $isactive = 1)
657
    {
658
        $db          = XoopsDatabaseFactory::getDatabaseConnection();
659
        $ret         = array();
660
        $where_query = ' WHERE isactive=' . $isactive;
661
        if (isset($side)) {
662
            // get both sides in sidebox? (some themes need this)
663
            if ($side == XOOPS_SIDEBLOCK_BOTH) {
664
                $side = '(side=0 OR side=1)';
665
            } elseif ($side == XOOPS_CENTERBLOCK_ALL) {
666
                $side = '(side=3 OR side=4 OR side=5 OR side=7 OR side=8 OR side=9)';
667
            } elseif ($side == XOOPS_FOOTERBLOCK_ALL) {
668
                $side = '(side=10 OR side=11 OR side=12)';
669
            } else {
670
                $side = 'side=' . $side;
671
            }
672
            $where_query .= ' AND ' . $side;
673
        }
674
        if (isset($visible)) {
675
            $where_query .= ' AND visible=.' . $visible;
676
        }
677
        $where_query .= ' ORDER BY ' . $orderby;
678
        switch ($rettype) {
679
            case 'object':
680
                $sql    = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query;
681
                $result = $db->query($sql);
682
                if (!$db->isResultSet($result)) {
683
                    \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
684
                }
685
                while (false !== ($myrow = $db->fetchArray($result))) {
686
                    $ret[] = new XoopsBlock($myrow);
687
                }
688
                break;
689
            case 'list':
690
                $sql    = 'SELECT * FROM ' . $db->prefix('newblocks') . '' . $where_query;
691
                $result = $db->query($sql);
692
                if (!$db->isResultSet($result)) {
693
                    \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
694
                }
695
                while (false !== ($myrow = $db->fetchArray($result))) {
696
                    $block                      = new XoopsBlock($myrow);
697
                    $title                      = $block->getVar('title');
698
                    $title                      = empty($title) ? $block->getVar('name') : $title;
699
                    $ret[$block->getVar('bid')] = $title;
700
                }
701
                break;
702
            case 'id':
703
                $sql    = 'SELECT bid FROM ' . $db->prefix('newblocks') . '' . $where_query;
704
                $result = $db->query($sql);
705
                if (!$db->isResultSet($result)) {
706
                    \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
707
                }
708
                while (false !== ($myrow = $db->fetchArray($result))) {
709
                    $ret[] = $myrow['bid'];
710
                }
711
                break;
712
        }
713
714
        return $ret;
715
    }
716
717
    /**
718
     * XoopsBlock::getByModule()
719
     *
720
     * @param  mixed $moduleid
721
     * @param  mixed $asobject
722
     * @return array
723
     *
724
     * @deprecated (This also appears, dead, in XoopsBlockHandler)
725
     */
726
    public static function getByModule($moduleid, $asobject = true)
727
    {
728
        $moduleid = (int)$moduleid;
729
        $db       = XoopsDatabaseFactory::getDatabaseConnection();
730
        if ($asobject == true) {
731
            $sql = $sql = 'SELECT * FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid;
0 ignored issues
show
Unused Code introduced by
The assignment to $sql is dead and can be removed.
Loading history...
732
        } else {
733
            $sql = 'SELECT bid FROM ' . $db->prefix('newblocks') . ' WHERE mid=' . $moduleid;
734
        }
735
        $result = $db->query($sql);
736
        if (!$db->isResultSet($result)) {
737
            \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
738
        }
739
        $ret    = array();
740
        while (false !== ($myrow = $db->fetchArray($result))) {
741
            if ($asobject) {
742
                $ret[] = new XoopsBlock($myrow);
743
            } else {
744
                $ret[] = $myrow['bid'];
745
            }
746
        }
747
748
        return $ret;
749
    }
750
751
    /**
752
     * XoopsBlock::getAllByGroupModule()
753
     *
754
     * @param  mixed   $groupid
755
     * @param  integer $module_id
756
     * @param  mixed   $toponlyblock
757
     * @param  mixed   $visible
758
     * @param  string  $orderby
759
     * @param  integer $isactive
760
     * @return array
761
     *
762
     * @deprecated (This also appears, dead, in XoopsBlockHandler)
763
     */
764
    public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1)
765
    {
766
        $isactive = (int)$isactive;
767
        $db       = XoopsDatabaseFactory::getDatabaseConnection();
768
        $ret      = array();
769
        if (isset($groupid)) {
770
            $sql = 'SELECT DISTINCT gperm_itemid FROM ' . $db->prefix('group_permission') . " WHERE gperm_name = 'block_read' AND gperm_modid = 1";
771
            if (is_array($groupid)) {
772
                $sql .= ' AND gperm_groupid IN (' . implode(',', $groupid) . ')';
773
            } else {
774
                if ((int)$groupid > 0) {
775
                    $sql .= ' AND gperm_groupid=' . (int)$groupid;
776
                }
777
            }
778
            $result   = $db->query($sql);
779
            if (!$db->isResultSet($result)) {
780
                \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
781
            }
782
            $blockids = array();
783
            while (false !== ($myrow = $db->fetchArray($result))) {
784
                $blockids[] = $myrow['gperm_itemid'];
785
            }
786
            if (empty($blockids)) {
787
                return $blockids;
788
            }
789
        }
790
        $sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid';
791
        $sql .= ' AND b.isactive=' . $isactive;
792
        if (isset($visible)) {
793
            $sql .= ' AND b.visible=' . (int)$visible;
794
        }
795
        if (!isset($module_id)) {
796
        } elseif (!empty($module_id)) {
797
            $sql .= ' AND m.module_id IN (0,' . (int)$module_id;
798
            if ($toponlyblock) {
799
                $sql .= ',-1';
800
            }
801
            $sql .= ')';
802
        } else {
803
            if ($toponlyblock) {
804
                $sql .= ' AND m.module_id IN (0,-1)';
805
            } else {
806
                $sql .= ' AND m.module_id=0';
807
            }
808
        }
809
        if (!empty($blockids)) {
810
            $sql .= ' AND b.bid IN (' . implode(',', $blockids) . ')';
811
        }
812
        $sql .= ' ORDER BY ' . $orderby;
813
        $result = $db->query($sql);
814
        if (!$db->isResultSet($result)) {
815
            \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
816
        }
817
        while (false !== ($myrow = $db->fetchArray($result))) {
818
            $block              = new XoopsBlock($myrow);
819
            $ret[$myrow['bid']] = &$block;
820
            unset($block);
821
        }
822
823
        return $ret;
824
    }
825
826
    /**
827
     * XoopsBlock::getNonGroupedBlocks()
828
     *
829
     * @param  integer $module_id
830
     * @param  mixed   $toponlyblock
831
     * @param  mixed   $visible
832
     * @param  string  $orderby
833
     * @param  integer $isactive
834
     * @return array
835
     *
836
     * @deprecated
837
     */
838
    public function getNonGroupedBlocks($module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'b.weight, m.block_id', $isactive = 1)
839
    {
840
        $db   = XoopsDatabaseFactory::getDatabaseConnection();
841
        $ret  = array();
842
        $bids = array();
843
        $sql  = 'SELECT DISTINCT(bid) from ' . $db->prefix('newblocks');
844
        $result = $db->query($sql);
845
        if ($db->isResultSet($result)) {
846
            // \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
847
            while (false !== ($myrow = $db->fetchArray($result))) {
848
                $bids[] = $myrow['bid'];
849
            }
850
        }
851
852
        $sql     = 'SELECT DISTINCT(p.gperm_itemid) from ' . $db->prefix('group_permission') . ' p, ' . $db->prefix('groups') . " g WHERE g.groupid=p.gperm_groupid AND p.gperm_name='block_read'";
853
        $grouped = array();
854
        $result  = $db->query($sql);
855
        if ($db->isResultSet($result)) {
856
            //  \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
857
            while (false !== ($myrow = $db->fetchArray($result))) {
858
                $grouped[] = $myrow['gperm_itemid'];
859
            }
860
        }
861
862
863
        $non_grouped = array_diff($bids, $grouped);
864
        if (!empty($non_grouped)) {
865
            $sql = 'SELECT b.* FROM ' . $db->prefix('newblocks') . ' b, ' . $db->prefix('block_module_link') . ' m WHERE m.block_id=b.bid';
866
            $sql .= ' AND b.isactive=' . (int)$isactive;
867
            if (isset($visible)) {
868
                $sql .= ' AND b.visible=' . (int)$visible;
869
            }
870
            if (!isset($module_id)) {
871
            } elseif (!empty($module_id)) {
872
                $sql .= ' AND m.module_id IN (0,' . (int)$module_id;
873
                if ($toponlyblock) {
874
                    $sql .= ',-1';
875
                }
876
                $sql .= ')';
877
            } else {
878
                if ($toponlyblock) {
879
                    $sql .= ' AND m.module_id IN (0,-1)';
880
                } else {
881
                    $sql .= ' AND m.module_id=0';
882
                }
883
            }
884
            $sql .= ' AND b.bid IN (' . implode(',', $non_grouped) . ')';
885
            $sql .= ' ORDER BY ' . $orderby;
886
            $result = $db->query($sql);
887
            if (!$db->isResultSet($result)) {
888
                \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
889
            }
890
            while (false !== ($myrow = $db->fetchArray($result))) {
891
                $block              = new XoopsBlock($myrow);
892
                $ret[$myrow['bid']] =& $block;
893
                unset($block);
894
            }
895
        }
896
897
        return $ret;
898
    }
899
900
    /**
901
     * XoopsBlock::countSimilarBlocks()
902
     *
903
     * @param  mixed $moduleId
904
     * @param  mixed $funcNum
905
     * @param  mixed $showFunc
906
     * @return int
907
     *
908
     * @deprecated
909
     */
910
    public function countSimilarBlocks($moduleId, $funcNum, $showFunc = null)
911
    {
912
        $funcNum  = (int)$funcNum;
913
        $moduleId = (int)$moduleId;
914
        if ($funcNum < 1 || $moduleId < 1) {
915
            // invalid query
916
            return 0;
917
        }
918
        $db = XoopsDatabaseFactory::getDatabaseConnection();
919
        if (isset($showFunc)) {
920
            // showFunc is set for more strict comparison
921
            $sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d AND show_func = %s', $db->prefix('newblocks'), $moduleId, $funcNum, $db->quoteString(trim($showFunc)));
0 ignored issues
show
Bug introduced by
The method quoteString() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

921
            $sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d AND show_func = %s', $db->prefix('newblocks'), $moduleId, $funcNum, $db->/** @scrutinizer ignore-call */ quoteString(trim($showFunc)));
Loading history...
922
        } else {
923
            $sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d', $db->prefix('newblocks'), $moduleId, $funcNum);
924
        }
925
        $result = $db->query($sql);
926
        if (!$db->isResultSet($result)) {
927
            //            \trigger_error("Query Failed! SQL: $sql- Error: " . $db->error(), E_USER_ERROR);
928
            return 0;
929
        }
930
        list($count) = $db->fetchRow($result);
0 ignored issues
show
Bug introduced by
The method fetchRow() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

930
        /** @scrutinizer ignore-call */ 
931
        list($count) = $db->fetchRow($result);
Loading history...
931
932
        return (int)$count;
933
    }
934
}
935
936
/**
937
 * XOOPS block handler class. (Singelton)
938
 *
939
 * This class is responsible for providing data access mechanisms to the data source
940
 * of XOOPS block class objects.
941
 *
942
 * @author              Kazumi Ono <[email protected]>
943
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
944
 * @package             kernel
945
 * @subpackage          block
946
 *
947
 * @todo Why is this not a XoopsPersistableObjectHandler?
948
 */
949
class XoopsBlockHandler extends XoopsObjectHandler
950
{
951
    /**
952
     * create a new block
953
     *
954
     * @see XoopsBlock
955
     * @param  bool $isNew is the new block new??
956
     * @return XoopsBlock XoopsBlock reference to the new block
957
     **/
958
    public function create($isNew = true)
959
    {
960
        $block = new XoopsBlock();
961
        if ($isNew) {
962
            $block->setNew();
963
        }
964
965
        return $block;
966
    }
967
968
    /**
969
     * retrieve a specific {@link XoopsBlock}
970
     *
971
     * @see XoopsBlock
972
     * @param  int $id bid of the block to retrieve
973
     * @return XoopsBlock reference to the block
974
     **/
975
    public function get($id)
976
    {
977
        $block = false;
978
        $id    = (int)$id;
979
        if ($id > 0) {
980
            $sql    = 'SELECT * FROM ' . $this->db->prefix('newblocks') . ' WHERE bid=' . $id;
981
            $result = $this->db->query($sql);
982
            if ($this->db->isResultSet($result)) {
983
                // \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
984
                $numrows = $this->db->getRowsNum($result);
0 ignored issues
show
Bug introduced by
The method getRowsNum() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

984
                /** @scrutinizer ignore-call */ 
985
                $numrows = $this->db->getRowsNum($result);
Loading history...
985
                if ($numrows == 1) {
986
                    $block = new XoopsBlock();
987
                    $block->assignVars($this->db->fetchArray($result));
988
                }
989
            }
990
        }
991
992
        return $block;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $block could also return false which is incompatible with the documented return type XoopsBlock. Did you maybe forget to handle an error condition?

If the returned type also contains false, it is an indicator that maybe an error condition leading to the specific return statement remains unhandled.

Loading history...
993
    }
994
995
    /**
996
     * write a new block into the database
997
     *
998
     * @param XoopsObject|XoopsBlock $block a XoopsBlock object
999
     *
1000
     * @return bool true on success, otherwise false
1001
     */
1002
    public function insert(XoopsObject $block)
1003
    {
1004
        $className = 'XoopsBlock';
1005
        if (!($block instanceof $className)) {
1006
            return false;
1007
        }
1008
        if (!$block->isDirty()) {
1009
            return true;
1010
        }
1011
        if (!$block->cleanVars()) {
1012
            return false;
1013
        }
1014
1015
        $bid = $block->getVar('bid', 'n');
1016
        $mid = $block->getVar('mid', 'n');
1017
        $func_num = $block->getVar('func_num', 'n');
1018
        $options = $block->getVar('options', 'n');
1019
        $name = $block->getVar('name', 'n');
1020
        $title = $block->getVar('title', 'n');
1021
        $content = $block->getVar('content', 'n');
1022
        $side = $block->getVar('side', 'n');
1023
        $weight = $block->getVar('weight', 'n');
1024
        $visible = $block->getVar('visible', 'n');
1025
        $c_type = $block->getVar('c_type', 'n');
1026
        $isactive = $block->getVar('isactive', 'n');
1027
        $func_file = $block->getVar('func_file', 'n');
1028
        $show_func = $block->getVar('show_func', 'n');
1029
        $edit_func = $block->getVar('edit_func', 'n');
1030
        $template = $block->getVar('template', 'n');
1031
        $bcachetime = $block->getVar('bcachetime', 'n');
1032
        $block_type = $block->getVar('block_type', 'n');
1033
        $dirname = $block->getVar('dirname', 'n');
1034
1035
        if ($block->isNew()) {
1036
            $bid = $this->db->genId('newblocks_bid_seq');
0 ignored issues
show
Bug introduced by
The method genId() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1036
            /** @scrutinizer ignore-call */ 
1037
            $bid = $this->db->genId('newblocks_bid_seq');
Loading history...
1037
            $sql = sprintf(
1038
                'INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type,'
1039
                . ' c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified)'
1040
                . " VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %u, %u, %u, '%s', '%s', %u, '%s', '%s', '%s', '%s',"
1041
                . " '%s', %u, %u)",
1042
                $this->db->prefix('newblocks'),
1043
                $bid,
1044
                $mid,
0 ignored issues
show
Bug introduced by
It seems like $mid can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1044
                /** @scrutinizer ignore-type */ $mid,
Loading history...
1045
                $func_num,
1046
                $options,
1047
                $name,
1048
                $title,
1049
                $content,
1050
                $side,
1051
                $weight,
1052
                $visible,
1053
                $block_type,
1054
                $c_type,
1055
                1,
1056
                $dirname,
1057
                $func_file,
1058
                $show_func,
1059
                $edit_func,
1060
                $template,
1061
                $bcachetime,
1062
                time()
1063
            );
1064
        } else {
1065
            $sql = sprintf(
1066
                "UPDATE %s SET func_num = %u, options = '%s', name = '%s', title = '%s', content = '%s', side = %u,"
1067
                . " weight = %u, visible = %u, c_type = '%s', isactive = %u, func_file = '%s', show_func = '%s',"
1068
                . " edit_func = '%s', template = '%s', bcachetime = %u, last_modified = %u WHERE bid = %u",
1069
                $this->db->prefix('newblocks'),
1070
                $func_num,
1071
                $options,
1072
                $name,
1073
                $title,
1074
                $content,
1075
                $side,
1076
                $weight,
1077
                $visible,
1078
                $c_type,
1079
                $isactive,
1080
                $func_file,
1081
                $show_func,
1082
                $edit_func,
1083
                $template,
1084
                $bcachetime,
1085
                time(),
1086
                $bid
1087
            );
1088
        }
1089
        if (!$result = $this->db->query($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
1090
            return false;
1091
        }
1092
        if (empty($bid)) {
1093
            $bid = $this->db->getInsertId();
0 ignored issues
show
Bug introduced by
The method getInsertId() does not exist on XoopsDatabase. Since it exists in all sub-types, consider adding an abstract or default implementation to XoopsDatabase. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1093
            /** @scrutinizer ignore-call */ 
1094
            $bid = $this->db->getInsertId();
Loading history...
1094
        }
1095
        $block->assignVar('bid', $bid);
1096
1097
        return true;
1098
    }
1099
1100
    /**
1101
     * delete a block from the database
1102
     *
1103
     * @param XoopsObject|XoopsBlock $block a XoopsBlock object
1104
     *
1105
     * @return bool true on success, otherwise false
1106
     */
1107
    public function delete(XoopsObject $block)
1108
    {
1109
        $className = 'XoopsBlock';
1110
        if (!($block instanceof $className)) {
1111
            return false;
1112
        }
1113
        $id  = $block->getVar('bid');
1114
        $sql = sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), $id);
0 ignored issues
show
Bug introduced by
It seems like $id can also be of type array and array; however, parameter $values of sprintf() does only seem to accept double|integer|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1114
        $sql = sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), /** @scrutinizer ignore-type */ $id);
Loading history...
1115
        if (!$result = $this->db->query($sql)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $result is dead and can be removed.
Loading history...
1116
            return false;
1117
        }
1118
        $sql = sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $id);
1119
        $this->db->query($sql);
1120
1121
        return true;
1122
    }
1123
1124
    /**
1125
     * retrieve array of {@link XoopsBlock}s meeting certain conditions
1126
     * @param  CriteriaElement|CriteriaCompo $criteria  {@link CriteriaElement} with conditions for the blocks
1127
     * @param  bool   $id_as_key should the blocks' bid be the key for the returned array?
1128
     * @return array  {@link XoopsBlock}s matching the conditions
1129
     **/
1130
    public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
1131
    {
1132
        $ret   = array();
1133
        $limit = $start = 0;
1134
        $sql   = 'SELECT DISTINCT(b.bid), b.* FROM ' . $this->db->prefix('newblocks') . ' b LEFT JOIN '
1135
            . $this->db->prefix('block_module_link') . ' l ON b.bid=l.block_id';
1136
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
1137
            $sql .= ' ' . $criteria->renderWhere();
0 ignored issues
show
Bug introduced by
The method renderWhere() does not exist on CriteriaElement. Did you maybe mean render()? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1137
            $sql .= ' ' . $criteria->/** @scrutinizer ignore-call */ renderWhere();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
1138
            $limit = $criteria->getLimit();
1139
            $start = $criteria->getStart();
1140
        }
1141
        $result = $this->db->query($sql, $limit, $start);
1142
        if (!$this->db->isResultSet($result)) {
1143
            // \trigger_error("Query Failed! SQL: $sql- Error: " . $this->db->error(), E_USER_ERROR);
1144
            return $ret;
1145
        }
1146
        while (false !== ($myrow = $this->db->fetchArray($result))) {
1147
            $block = new XoopsBlock();
1148
            $block->assignVars($myrow);
1149
            if (!$id_as_key) {
1150
                $ret[] =& $block;
1151
            } else {
1152
                $ret[$myrow['bid']] = &$block;
1153
            }
1154
            unset($block);
1155
        }
1156
1157
        return $ret;
1158
    }
1159
1160
    /**
1161
     * get a list of blocks matchich certain conditions
1162
     *
1163
     * @param  CriteriaElement $criteria conditions to match
1164
     * @return array  array of blocks matching the conditions
1165
     **/
1166
    public function getList(CriteriaElement $criteria = null)
1167
    {
1168
        $blocks = $this->getObjects($criteria, true);
1169
        $ret    = array();
1170
        foreach (array_keys($blocks) as $i) {
1171
            $name    = (!$blocks[$i]->isCustom()) ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title');
1172
            $ret[$i] = $name;
1173
        }
1174
1175
        return $ret;
1176
    }
1177
1178
    ##################### Deprecated Methods ######################
1179
    /* These are not deprecated, they are dead and should be removed */
1180
    /**
1181
     * @deprecated
1182
     * @param      $moduleid
1183
     * @param bool $asobject
1184
     * @param bool $id_as_key
1185
     * @return bool
1186
     */
1187
    public function getByModule($moduleid, $asobject = true, $id_as_key = false)
0 ignored issues
show
Unused Code introduced by
The parameter $asobject is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1187
    public function getByModule($moduleid, /** @scrutinizer ignore-unused */ $asobject = true, $id_as_key = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $moduleid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1187
    public function getByModule(/** @scrutinizer ignore-unused */ $moduleid, $asobject = true, $id_as_key = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $id_as_key is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1187
    public function getByModule($moduleid, $asobject = true, /** @scrutinizer ignore-unused */ $id_as_key = false)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1188
    {
1189
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1190
1191
        return false;
1192
    }
1193
1194
    /**
1195
     * @param        $groupid
1196
     * @param int    $module_id
1197
     * @param bool   $toponlyblock
1198
     * @param null   $visible
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $visible is correct as it would always require null to be passed?
Loading history...
1199
     * @param string $orderby
1200
     * @param int    $isactive
1201
     *
1202
     * @return bool
1203
     * @deprecated
1204
     */
1205
    public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'i.weight,i.instanceid', $isactive = 1)
0 ignored issues
show
Unused Code introduced by
The parameter $isactive is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1205
    public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'i.weight,i.instanceid', /** @scrutinizer ignore-unused */ $isactive = 1)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $toponlyblock is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1205
    public function getAllByGroupModule($groupid, $module_id = 0, /** @scrutinizer ignore-unused */ $toponlyblock = false, $visible = null, $orderby = 'i.weight,i.instanceid', $isactive = 1)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groupid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1205
    public function getAllByGroupModule(/** @scrutinizer ignore-unused */ $groupid, $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'i.weight,i.instanceid', $isactive = 1)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $visible is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1205
    public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, /** @scrutinizer ignore-unused */ $visible = null, $orderby = 'i.weight,i.instanceid', $isactive = 1)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $orderby is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1205
    public function getAllByGroupModule($groupid, $module_id = 0, $toponlyblock = false, $visible = null, /** @scrutinizer ignore-unused */ $orderby = 'i.weight,i.instanceid', $isactive = 1)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $module_id is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1205
    public function getAllByGroupModule($groupid, /** @scrutinizer ignore-unused */ $module_id = 0, $toponlyblock = false, $visible = null, $orderby = 'i.weight,i.instanceid', $isactive = 1)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1206
    {
1207
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1208
1209
        return false;
1210
    }
1211
1212
    /**
1213
     * @param        $groupid
1214
     * @param string $orderby
1215
     *
1216
     * @return bool
1217
     * @deprecated
1218
     */
1219
    public function getAdminBlocks($groupid, $orderby = 'i.weight,i.instanceid')
0 ignored issues
show
Unused Code introduced by
The parameter $orderby is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1219
    public function getAdminBlocks($groupid, /** @scrutinizer ignore-unused */ $orderby = 'i.weight,i.instanceid')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
Unused Code introduced by
The parameter $groupid is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

1219
    public function getAdminBlocks(/** @scrutinizer ignore-unused */ $groupid, $orderby = 'i.weight,i.instanceid')

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
1220
    {
1221
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1222
1223
        return false;
1224
    }
1225
1226
    /**
1227
     * @return bool
1228
     * @deprecated
1229
     */
1230
    public function assignBlocks()
1231
    {
1232
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1233
1234
        return false;
1235
    }
1236
}
1237