b_oledrion_category_edit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 25
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 25
rs 9.584
c 0
b 0
f 0
cc 1
nc 1
nop 1
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
 * oledrion
14
 *
15
 * @copyright   {@link https://xoops.org/ XOOPS Project}
16
 * @license     {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @author      Hervé Thouzard (http://www.herve-thouzard.com/)
18
 */
19
20
use XoopsModules\Oledrion;
21
22
/**
23
 * Affiche le bloc des catégories en fonction de la catégorie en cours (fonctionne de paire avec les pages du module)
24
 * @param $options
25
 * @return array|bool
26
 */
27
function b_oledrion_category_show($options)
28
{
29
    global $xoTheme;
30
    $block = [];
31
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
32
    $xoTheme->addStylesheet(OLEDRION_URL . 'assets/css/oledrion.css');
33
34
    $block['nostock_msg'] = Oledrion\Utility::getModuleOption('nostock_msg');
35
36
    if (0 == (int)$options[0]) {
37
        // Catégories selon la page en cours
38
        $block['block_option'] = 0;
39
        if (!isset($GLOBALS['current_category']) || -1 == $GLOBALS['current_category']) {
40
            return false;
41
        }
42
        $cat_cid = (int)$GLOBALS['current_category'];
43
        require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
44
45
        if ($cat_cid > 0) {
46
            require_once XOOPS_ROOT_PATH . '/class/tree.php';
47
            $tbl_categories = $tblChilds = $tbl_tmp = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblChilds is dead and can be removed.
Loading history...
Unused Code introduced by
The assignment to $tbl_categories is dead and can be removed.
Loading history...
48
            $tbl_categories = $categoryHandler->getAllCategories(new Oledrion\Parameters());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $categoryHandler does not exist. Did you maybe mean $category?
Loading history...
49
            $mytree         = new Oledrion\XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid');
50
            $tblChilds      = $mytree->getAllChild($cat_cid);
51
            //$tblChilds = array_reverse($tblChilds);
52
            foreach ($tblChilds as $item) {
53
                $tbl_tmp[] = "<a href='" . $item->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>';
54
            }
55
            $block['block_categories'] = $tbl_tmp;
56
57
            $category = null;
0 ignored issues
show
Unused Code introduced by
The assignment to $category is dead and can be removed.
Loading history...
58
            if ($cat_cid > 0) {
59
                $category = $categoryHandler->get($cat_cid);
60
                if (is_object($category)) {
61
                    $block['block_current_category'] = $category->toArray();
62
                }
63
            }
64
        } else {
65
            // On est à la racine, on n'affiche donc que les catégories mères
66
            $tbl_categories = [];
67
            $criteria       = new \Criteria('cat_pid', 0, '=');
68
            $criteria->setSort('cat_title');
69
            $tbl_categories = $categoryHandler->getObjects($criteria, true);
70
            foreach ($tbl_categories as $item) {
71
                $tbl_tmp[] = "<a href='" . $item->getLink() . "' title='" . Oledrion\Utility::makeHrefTitle($item->getVar('cat_title')) . "'>" . $item->getVar('cat_title') . '</a>';
72
            }
73
            $block['block_categories'] = $tbl_tmp;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $tbl_tmp seems to be defined by a foreach iteration on line 70. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
74
        }
75
    } elseif (1 == (int)$options[0]) {
76
        // Affichage classique
77
        $block['block_option'] = 1;
78
        require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
79
        // require_once OLEDRION_PATH . 'class/tree.php';
80
        $tbl_categories = $categoryHandler->getAllCategories(new Oledrion\Parameters());
81
        $mytree         = new Oledrion\XoopsObjectTree($tbl_categories, 'cat_cid', 'cat_pid');
82
        $jump           = OLEDRION_URL . 'category.php?cat_cid=';
83
        $additional     = "onchange='location=\"" . $jump . "\"+this.options[this.selectedIndex].value'";
84
        $cat_cid        = 0;
85
        if (isset($GLOBALS['current_category']) && -1 != $GLOBALS['current_category']) {
86
            $cat_cid = (int)$GLOBALS['current_category'];
87
        }
88
89
        $select0    = $mytree->makeSelectElement('cat_cid', 'cat_title', '-', $cat_cid, false, 0, '', $additional);
90
        $htmlSelect = $select0->render();
91
92
        $block['htmlSelect'] = $htmlSelect;
93
    } else {
94
        // Affichage de toute l'arborescence, dépliée
95
        $block['block_option'] = 2;
96
        $block['liMenu']       = $categoryHandler->getUlMenu('category_title');
97
    }
98
99
    return $block;
100
}
101
102
/**
103
 * @param $options
104
 * @return string
105
 */
106
function b_oledrion_category_edit($options)
107
{
108
    global $xoopsConfig;
109
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
110
111
    $checkeds              = ['', '', ''];
112
    $checkeds[$options[0]] = 'checked';
113
    $form                  = '';
114
    $form                  .= '<b>'
115
                              . _MB_OLEDRION_TYPE_BLOCK
116
                              . "</b><br><input type='radio' name='options[]' id='options[]' value='0' "
117
                              . $checkeds[0]
118
                              . '>'
119
                              . _MB_OLEDRION_TYPE_BLOCK2
120
                              . "<br><input type='radio' name='options[]' id='options[]' value='1' "
121
                              . $checkeds[1]
122
                              . '>'
123
                              . _MB_OLEDRION_TYPE_BLOCK1
124
                              . "<br><input type='radio' name='options[]' id='options[]' value='2' "
125
                              . $checkeds[2]
126
                              . '>'
127
                              . _MB_OLEDRION_TYPE_BLOCK3
128
                              . '</td></tr>';
129
130
    return $form;
131
}
132
133
/**
134
 * Block on the fly
135
 * @param $options
136
 */
137
function b_oledrion_category_duplicatable($options)
138
{
139
    $options = explode('|', $options);
140
    $block   = b_oledrion_category($options);
0 ignored issues
show
Bug introduced by
The function b_oledrion_category was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

140
    $block   = /** @scrutinizer ignore-call */ b_oledrion_category($options);
Loading history...
141
142
    $tpl = new \XoopsTpl();
143
    $tpl->assign('block', $block);
144
    $tpl->display('db:oledrion_block_categories.tpl');
145
}
146