Completed
Pull Request — master (#568)
by Michael
06:11
created

banners_blocks_show()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 20
nc 3
nop 1
dl 0
loc 24
rs 8.9713
c 0
b 0
f 0
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * banners module
14
 *
15
 * @copyright       XOOPS Project (http://xoops.org)
16
 * @license         GNU GPL 2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
17
 * @package         banners
18
 * @since           2.6.0
19
 * @author          Mage Gregory (AKA Mage)
20
 * @version         $Id$
21
 */
22
function banners_blocks_show($options)
23
{
24
    $block = array();
25
    $xoops = Xoops::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $xoops is dead and can be removed.
Loading history...
26
    require_once dirname(__DIR__) . '/class/bannerrender.php';
27
    $render = new BannerRender();
28
    switch ($options[0]) {
29
        case 'random':
30
            $nb_display = $options[1];
31
            $align = $options[2];
32
            array_shift($options);
33
            array_shift($options);
34
            array_shift($options);
35
            $client = $options;
36
            $block['banners'] = $render->displayBanner($nb_display, $align, $client);
37
            break;
38
39
        case 'id':
40
            $ids = $options[1];
41
            $align = $options[2];
42
            $block['banners'] = $render->displayBanner(1, $align, 0, $ids);
0 ignored issues
show
Bug introduced by
0 of type integer is incompatible with the type array expected by parameter $client of BannerRender::displayBanner(). ( Ignorable by Annotation )

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

42
            $block['banners'] = $render->displayBanner(1, $align, /** @scrutinizer ignore-type */ 0, $ids);
Loading history...
43
            break;
44
    }
45
    return $block;
46
}
47
48
function banners_blocks_edit($options)
49
{
50
    $form = '';
51
    switch ($options[0]) {
52
53
        case 'random':
54
            $form .= _MB_BANNERS_DISP . "&nbsp;\n";
55
            $form .= "<input type=\"hidden\" name=\"options[0]\" value=\"" . $options[0] . "\" />\n";
56
            $form .= "<input name=\"options[1]\" size=\"5\" maxlength=\"255\" value=\"" . $options[1] . "\" type=\"text\" />&nbsp;" . _MB_BANNERS . "<br>\n";
57
            switch ($options[2]) {
58
                case 'H':
59
                    $checked_H = 'checked="checked"';
60
                    $checked_V = '';
61
                    break;
62
63
                case 'V':
64
                    $checked_H = '';
65
                    $checked_V = 'checked="checked"';
66
                    break;
67
            }
68
            $form .= _MB_BANNERS_ALIGNEMENT . " : <input name=\"options[2]\" value=\"H\" type=\"radio\" " . $checked_H . "/>" . _MB_BANNERS_ALIGNEMENT_H . "&nbsp;\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $checked_H does not seem to be defined for all execution paths leading up to this point.
Loading history...
69
            $form .= "<input name=\"options[2]\" value=\"V\" type=\"radio\" " . $checked_V . "/>" . _MB_BANNERS_ALIGNEMENT_V . "<br>\n";
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $checked_V does not seem to be defined for all execution paths leading up to this point.
Loading history...
70
            array_shift($options);
71
            array_shift($options);
72
            array_shift($options);
73
            $form .= _MB_BANNERS_CLIENTSTODISPLAY . "<br><select name=\"options[]\" multiple=\"multiple\" size=\"5\">\n";
74
            $xoops = Xoops::getInstance();
75
            $client_Handler = $xoops->getModuleHandler('bannerclient', 'banners');
76
            $criteria = new CriteriaCompo();
77
            $criteria->setSort('bannerclient_name');
78
            $criteria->setOrder('ASC');
79
            $client_arr = $client_Handler->getAll($criteria);
0 ignored issues
show
Bug introduced by
The method getAll() does not exist on XoopsObjectHandler. ( Ignorable by Annotation )

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

79
            /** @scrutinizer ignore-call */ 
80
            $client_arr = $client_Handler->getAll($criteria);

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...
80
            $form .= "<option value=\"0\" " . (array_search(0, $options) === false ? '' : 'selected="selected"') . ">" . _MB_BANNERS_ALLCLIENTS . "</option>\n";
81
            foreach (array_keys($client_arr) as $i) {
82
                $form .= "<option value=\"" . $client_arr[$i]->getVar('cid') . "\" " . (array_search($client_arr[$i]->getVar('cid'), $options) === false ? '' : 'selected="selected"') . ">" . $client_arr[$i]->getVar('name')."</option>\n";
83
            }
84
            $form .= "</select>\n";
85
            break;
86
87
        case 'id':
88
            $form .= _MB_BANNERS_IDDISPLAY . "&nbsp;\n";
89
            $form .= "<input type=\"hidden\" name=\"options[0]\" value=\"" . $options[0] . "\" />\n";
90
            $form .= "<input name=\"options[1]\" size=\"20\" maxlength=\"255\" value=\"" . $options[1] . "\" type=\"text\" />&nbsp;" . _MB_BANNERS_SEP . "<br>\n";
91
            switch ($options[2]) {
92
                case 'H':
93
                    $checked_H = 'checked="checked"';
94
                    $checked_V = '';
95
                    break;
96
97
                case 'V':
98
                    $checked_H = '';
99
                    $checked_V = 'checked="checked"';
100
                    break;
101
            }
102
            $form .= _MB_BANNERS_ALIGNEMENT . " : <input name=\"options[2]\" value=\"H\" type=\"radio\" " . $checked_H . "/>" . _MB_BANNERS_ALIGNEMENT_H . "&nbsp;\n";
103
            $form .= "<input name=\"options[2]\" value=\"V\" type=\"radio\" " . $checked_V . "/>" . _MB_BANNERS_ALIGNEMENT_V . "<br>\n";
104
            break;
105
    }
106
    return $form;
107
}
108