b_oledrion_top_show()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 25
rs 9.7333
c 0
b 0
f 0
cc 3
nc 4
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 les produits les plus vus
24
 * @param $options
25
 * @return array|bool
26
 */
27
function b_oledrion_top_show($options)
28
{
29
    // '10|0';  // Voir 10 produits, pour toutes les catégories ou une catégorie particulière
30
    global $xoopsConfig, $xoTheme;
31
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
32
    $products   = $block = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $products is dead and can be removed.
Loading history...
33
    $start      = 0;
34
    $limit      = $options[0];
35
    $categoyrId = $options[1];
36
    $shelfParameters->resetDefaultValues()->setProductsType('mostviewed')->setStart($start)->setLimit($limit)->setSort('product_hits')->setOrder('DESC')->setCategory($categoyrId);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelfParameters seems to be never defined.
Loading history...
37
    $products = $shelf->getProducts($shelfParameters);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelf seems to be never defined.
Loading history...
38
    if (isset($products['lastTitle'])) {
39
        unset($products['lastTitle']);
40
    }
41
    if (count($products) > 0) {
42
        $block['nostock_msg']    = Oledrion\Utility::getModuleOption('nostock_msg');
43
        $block['block_products'] = $products;
44
        $xoTheme->addStylesheet(OLEDRION_URL . 'assets/css/oledrion.css');
45
46
        return $block;
47
    }
48
49
    // La liste des produits est introuvable (on ne trouve pas les produits vendus dans le stock des produits)
50
51
    return false;
52
}
53
54
/**
55
 * Paramètres du bloc
56
 * @param $options
57
 * @return string
58
 */
59
function b_oledrion_top_edit($options)
60
{
61
    // '10|0';  // Voir 10 produits, pour toutes les catégories
62
    global $xoopsConfig;
63
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
64
    // require_once OLEDRION_PATH . 'class/tree.php';
65
    $tblCategories         = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblCategories is dead and can be removed.
Loading history...
66
    $tblCategories         = $categoryHandler->getAllCategories(new Oledrion\Parameters());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $categoryHandler seems to be never defined.
Loading history...
67
    $mytree                = new Oledrion\XoopsObjectTree($tblCategories, 'cat_cid', 'cat_pid');
68
    $form                  = '';
69
    $checkeds              = ['', ''];
70
    $checkeds[$options[1]] = 'checked';
71
    $form                  .= "<table border='0'>";
72
    $form                  .= '<tr><td>' . _MB_OLEDRION_PRODUCTS_CNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "'></td></tr>";
73
    //$form .= '<tr><td>'._MB_OLEDRION_SORT_ORDER."</td><td><input type='radio' name='options[]' id='options[]' value='0' ".$checkeds[0].">"._MB_OLEDRION_SORT_1." <input type='radio' name='options[]' id='options[]' value='1' ".$checkeds[1].">"._MB_OLEDRION_SORT_2.'</td></tr>';
74
75
    $select0 = $mytree->makeSelectElement('options[]', 'cat_title', '-', $options[1], true, 0, '', _MB_OLEDRION_ALL_CATEGORIES);
76
    $select  = $select0->render();
77
78
    $form .= '<tr><td>' . _MB_OLEDRION_CATEGORY . '</td><td>' . $select . '</td></tr>';
79
    $form .= '</table>';
80
81
    return $form;
82
}
83
84
/**
85
 * Bloc à la volée
86
 * @param $options
87
 */
88
function b_oledrion_top_show_duplicatable($options)
89
{
90
    $options = explode('|', $options);
91
    $block   = b_oledrion_top_show($options);
92
93
    $tpl = new \XoopsTpl();
94
    $tpl->assign('block', $block);
95
    $tpl->display('db:oledrion_block_top.tpl');
96
}
97