b_oledrion_bestsales_show()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 23
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 meilleures ventes
24
 * @param $options
25
 * @return array|bool
26
 */
27
function b_oledrion_bestsales_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
    $categoryId = $options[1];
33
    $start      = 0;
34
    $limit      = $options[0];
35
    $shelfParameters->resetDefaultValues()->setProductsType('mostsold')->setStart($start)->setLimit($limit)->setSort('product_submitted DESC, product_title')->setCategory($categoryId);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelfParameters seems to be never defined.
Loading history...
36
    $products = $shelf->getProducts($shelfParameters);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelf seems to be never defined.
Loading history...
37
    if (isset($products['lastTitle'])) {
38
        unset($products['lastTitle']);
39
    }
40
    if (count($products) > 0) {
41
        $block                   = [];
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
    return false;
50
}
51
52
/**
53
 * Paramètres du bloc
54
 * @param $options
55
 * @return string
56
 */
57
function b_oledrion_bestsales_edit($options)
58
{
59
    // '10|0';  // Voir 10 produits, pour toutes les catégories
60
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
61
    // require_once OLEDRION_PATH . 'class/tree.php';
62
    $categories            = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $categories is dead and can be removed.
Loading history...
63
    $categories            = $categoryHandler->getAllCategories(new Oledrion\Parameters());
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $categoryHandler seems to be never defined.
Loading history...
64
    $mytree                = new Oledrion\XoopsObjectTree($categories, 'cat_cid', 'cat_pid');
65
    $form                  = '';
66
    $checkeds              = ['', ''];
67
    $checkeds[$options[1]] = 'checked';
68
    $form                  .= "<table border='0'>";
69
    $form                  .= '<tr><td>' . _MB_OLEDRION_PRODUCTS_CNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "'></td></tr>";
70
71
    $select0 = $mytree->makeSelectElement('options[]', 'cat_title', '-', $options[1], true, 0, '', _MB_OLEDRION_CATEGORY);
72
    $select  = $select0->render();
73
74
    $form .= '<tr><td>' . _MB_OLEDRION_CATEGORY . '</td><td>' . $select . '</td></tr>';
75
    $form .= '</table>';
76
77
    return $form;
78
}
79
80
/**
81
 * Bloc à la volée
82
 * @param $options
83
 */
84
function b_oledrion_bestsales_duplicatable($options)
85
{
86
    $options = explode('|', $options);
87
    $block   = b_oledrion_bestsales_show($options);
88
89
    $tpl = new \XoopsTpl();
90
    $tpl->assign('block', $block);
91
    $tpl->display('db:oledrion_block_bestsales.tpl');
92
}
93