Passed
Push — master ( 05faca...9c86bf )
by Richard
08:39 queued 13s
created

XoopsBlock::getAllByGroupModule()   D

Complexity

Conditions 15
Paths 246

Size

Total Lines 64
Code Lines 46

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 15
eloc 46
nc 246
nop 6
dl 0
loc 64
rs 4.5083
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
            throw new \RuntimeException(
628
                \sprintf(_DB_QUERY_ERROR, $sql) . $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

628
                \sprintf(_DB_QUERY_ERROR, $sql) . $db->/** @scrutinizer ignore-call */ error(), E_USER_ERROR
Loading history...
629
            );
630
        }
631
        $added  = array();
632
        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

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

935
            $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...
936
        } else {
937
            $sql = sprintf('SELECT COUNT(*) FROM %s WHERE mid = %d AND func_num = %d', $db->prefix('newblocks'), $moduleId, $funcNum);
938
        }
939
        $result = $db->query($sql);
940
        if (!$db->isResultSet($result)) {
941
            return 0;
942
        }
943
        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

943
        /** @scrutinizer ignore-call */ 
944
        list($count) = $db->fetchRow($result);
Loading history...
944
945
        return (int)$count;
946
    }
947
}
948
949
/**
950
 * XOOPS block handler class. (Singelton)
951
 *
952
 * This class is responsible for providing data access mechanisms to the data source
953
 * of XOOPS block class objects.
954
 *
955
 * @author              Kazumi Ono <[email protected]>
956
 * @copyright       (c) 2000-2016 XOOPS Project (www.xoops.org)
957
 * @package             kernel
958
 * @subpackage          block
959
 *
960
 * @todo Why is this not a XoopsPersistableObjectHandler?
961
 */
962
class XoopsBlockHandler extends XoopsObjectHandler
963
{
964
    /**
965
     * create a new block
966
     *
967
     * @see XoopsBlock
968
     * @param  bool $isNew is the new block new??
969
     * @return XoopsBlock XoopsBlock reference to the new block
970
     **/
971
    public function create($isNew = true)
972
    {
973
        $block = new XoopsBlock();
974
        if ($isNew) {
975
            $block->setNew();
976
        }
977
978
        return $block;
979
    }
980
981
    /**
982
     * retrieve a specific {@link XoopsBlock}
983
     *
984
     * @see XoopsBlock
985
     * @param  int $id bid of the block to retrieve
986
     * @return XoopsBlock reference to the block
987
     **/
988
    public function get($id)
989
    {
990
        $block = false;
991
        $id    = (int)$id;
992
        if ($id > 0) {
993
            $sql    = 'SELECT * FROM ' . $this->db->prefix('newblocks') . ' WHERE bid=' . $id;
994
            $result = $this->db->query($sql);
995
            if ($this->db->isResultSet($result)) {
996
                $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

996
                /** @scrutinizer ignore-call */ 
997
                $numrows = $this->db->getRowsNum($result);
Loading history...
997
                if ($numrows == 1) {
998
                    $block = new XoopsBlock();
999
                    $block->assignVars($this->db->fetchArray($result));
1000
                }
1001
            }
1002
        }
1003
1004
        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...
1005
    }
1006
1007
    /**
1008
     * write a new block into the database
1009
     *
1010
     * @param XoopsObject|XoopsBlock $block a XoopsBlock object
1011
     *
1012
     * @return bool true on success, otherwise false
1013
     */
1014
    public function insert(XoopsObject $block)
1015
    {
1016
        $className = 'XoopsBlock';
1017
        if (!($block instanceof $className)) {
1018
            return false;
1019
        }
1020
        if (!$block->isDirty()) {
1021
            return true;
1022
        }
1023
        if (!$block->cleanVars()) {
1024
            return false;
1025
        }
1026
1027
        $bid = $block->getVar('bid', 'n');
1028
        $mid = $block->getVar('mid', 'n');
1029
        $func_num = $block->getVar('func_num', 'n');
1030
        $options = $block->getVar('options', 'n');
1031
        $name = $block->getVar('name', 'n');
1032
        $title = $block->getVar('title', 'n');
1033
        $content = $block->getVar('content', 'n');
1034
        $side = $block->getVar('side', 'n');
1035
        $weight = $block->getVar('weight', 'n');
1036
        $visible = $block->getVar('visible', 'n');
1037
        $c_type = $block->getVar('c_type', 'n');
1038
        $isactive = $block->getVar('isactive', 'n');
1039
        $func_file = $block->getVar('func_file', 'n');
1040
        $show_func = $block->getVar('show_func', 'n');
1041
        $edit_func = $block->getVar('edit_func', 'n');
1042
        $template = $block->getVar('template', 'n');
1043
        $bcachetime = $block->getVar('bcachetime', 'n');
1044
        $block_type = $block->getVar('block_type', 'n');
1045
        $dirname = $block->getVar('dirname', 'n');
1046
1047
        if ($block->isNew()) {
1048
            $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

1048
            /** @scrutinizer ignore-call */ 
1049
            $bid = $this->db->genId('newblocks_bid_seq');
Loading history...
1049
            $sql = sprintf(
1050
                'INSERT INTO %s (bid, mid, func_num, options, name, title, content, side, weight, visible, block_type,'
1051
                . ' c_type, isactive, dirname, func_file, show_func, edit_func, template, bcachetime, last_modified)'
1052
                . " VALUES (%u, %u, %u, '%s', '%s', '%s', '%s', %u, %u, %u, '%s', '%s', %u, '%s', '%s', '%s', '%s',"
1053
                . " '%s', %u, %u)",
1054
                $this->db->prefix('newblocks'),
1055
                $bid,
1056
                $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

1056
                /** @scrutinizer ignore-type */ $mid,
Loading history...
1057
                $func_num,
1058
                $options,
1059
                $name,
1060
                $title,
1061
                $content,
1062
                $side,
1063
                $weight,
1064
                $visible,
1065
                $block_type,
1066
                $c_type,
1067
                1,
1068
                $dirname,
1069
                $func_file,
1070
                $show_func,
1071
                $edit_func,
1072
                $template,
1073
                $bcachetime,
1074
                time()
1075
            );
1076
        } else {
1077
            $sql = sprintf(
1078
                "UPDATE %s SET func_num = %u, options = '%s', name = '%s', title = '%s', content = '%s', side = %u,"
1079
                . " weight = %u, visible = %u, c_type = '%s', isactive = %u, func_file = '%s', show_func = '%s',"
1080
                . " edit_func = '%s', template = '%s', bcachetime = %u, last_modified = %u WHERE bid = %u",
1081
                $this->db->prefix('newblocks'),
1082
                $func_num,
1083
                $options,
1084
                $name,
1085
                $title,
1086
                $content,
1087
                $side,
1088
                $weight,
1089
                $visible,
1090
                $c_type,
1091
                $isactive,
1092
                $func_file,
1093
                $show_func,
1094
                $edit_func,
1095
                $template,
1096
                $bcachetime,
1097
                time(),
1098
                $bid
1099
            );
1100
        }
1101
        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...
1102
            return false;
1103
        }
1104
        if (empty($bid)) {
1105
            $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

1105
            /** @scrutinizer ignore-call */ 
1106
            $bid = $this->db->getInsertId();
Loading history...
1106
        }
1107
        $block->assignVar('bid', $bid);
1108
1109
        return true;
1110
    }
1111
1112
    /**
1113
     * delete a block from the database
1114
     *
1115
     * @param XoopsObject|XoopsBlock $block a XoopsBlock object
1116
     *
1117
     * @return bool true on success, otherwise false
1118
     */
1119
    public function delete(XoopsObject $block)
1120
    {
1121
        $className = 'XoopsBlock';
1122
        if (!($block instanceof $className)) {
1123
            return false;
1124
        }
1125
        $id  = $block->getVar('bid');
1126
        $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

1126
        $sql = sprintf('DELETE FROM %s WHERE bid = %u', $this->db->prefix('newblocks'), /** @scrutinizer ignore-type */ $id);
Loading history...
1127
        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...
1128
            return false;
1129
        }
1130
        $sql = sprintf('DELETE FROM %s WHERE block_id = %u', $this->db->prefix('block_module_link'), $id);
1131
        $this->db->query($sql);
1132
1133
        return true;
1134
    }
1135
1136
    /**
1137
     * retrieve array of {@link XoopsBlock}s meeting certain conditions
1138
     * @param  CriteriaElement|CriteriaCompo $criteria  {@link CriteriaElement} with conditions for the blocks
1139
     * @param  bool   $id_as_key should the blocks' bid be the key for the returned array?
1140
     * @return array  {@link XoopsBlock}s matching the conditions
1141
     **/
1142
    public function getObjects(CriteriaElement $criteria = null, $id_as_key = false)
1143
    {
1144
        $ret   = array();
1145
        $limit = $start = 0;
1146
        $sql   = 'SELECT DISTINCT(b.bid), b.* FROM ' . $this->db->prefix('newblocks') . ' b LEFT JOIN '
1147
            . $this->db->prefix('block_module_link') . ' l ON b.bid=l.block_id';
1148
        if (isset($criteria) && is_subclass_of($criteria, 'CriteriaElement')) {
1149
            $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

1149
            $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...
1150
            $limit = $criteria->getLimit();
1151
            $start = $criteria->getStart();
1152
        }
1153
        $result = $this->db->query($sql, $limit, $start);
1154
        if (!$this->db->isResultSet($result)) {
1155
            return $ret;
1156
        }
1157
        while (false !== ($myrow = $this->db->fetchArray($result))) {
1158
            $block = new XoopsBlock();
1159
            $block->assignVars($myrow);
1160
            if (!$id_as_key) {
1161
                $ret[] =& $block;
1162
            } else {
1163
                $ret[$myrow['bid']] = &$block;
1164
            }
1165
            unset($block);
1166
        }
1167
1168
        return $ret;
1169
    }
1170
1171
    /**
1172
     * get a list of blocks matchich certain conditions
1173
     *
1174
     * @param  CriteriaElement $criteria conditions to match
1175
     * @return array  array of blocks matching the conditions
1176
     **/
1177
    public function getList(CriteriaElement $criteria = null)
1178
    {
1179
        $blocks = $this->getObjects($criteria, true);
1180
        $ret    = array();
1181
        foreach (array_keys($blocks) as $i) {
1182
            $name    = (!$blocks[$i]->isCustom()) ? $blocks[$i]->getVar('name') : $blocks[$i]->getVar('title');
1183
            $ret[$i] = $name;
1184
        }
1185
1186
        return $ret;
1187
    }
1188
1189
    ##################### Deprecated Methods ######################
1190
    /* These are not deprecated, they are dead and should be removed */
1191
    /**
1192
     * @deprecated
1193
     * @param      $moduleid
1194
     * @param bool $asobject
1195
     * @param bool $id_as_key
1196
     * @return bool
1197
     */
1198
    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

1198
    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 $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

1198
    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...
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

1198
    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...
1199
    {
1200
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1201
1202
        return false;
1203
    }
1204
1205
    /**
1206
     * @param        $groupid
1207
     * @param int    $module_id
1208
     * @param bool   $toponlyblock
1209
     * @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...
1210
     * @param string $orderby
1211
     * @param int    $isactive
1212
     *
1213
     * @return bool
1214
     * @deprecated
1215
     */
1216
    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

1216
    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

1216
    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

1216
    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

1216
    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

1216
    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

1216
    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...
1217
    {
1218
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1219
1220
        return false;
1221
    }
1222
1223
    /**
1224
     * @param        $groupid
1225
     * @param string $orderby
1226
     *
1227
     * @return bool
1228
     * @deprecated
1229
     */
1230
    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

1230
    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

1230
    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...
1231
    {
1232
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1233
1234
        return false;
1235
    }
1236
1237
    /**
1238
     * @return bool
1239
     * @deprecated
1240
     */
1241
    public function assignBlocks()
1242
    {
1243
        trigger_error(__CLASS__ . '::' . __FUNCTION__ . ' is deprecated', E_USER_WARNING);
1244
1245
        return false;
1246
    }
1247
}
1248