b_oledrion_promotion_show()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 24
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 24
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 x produit(s) en promotion
24
 * @param $options
25
 * @return array|bool
26
 */
27
function b_oledrion_promotion_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
    $block      = $products = [];
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
    $categoryId = $options[1];
36
37
    $shelfParameters->resetDefaultValues()->setProductsType('promotional')->setStart($start)->setLimit($limit)->setSort('product_submitted DESC, product_title')->setOrder('ASC')->setCategory($categoryId);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelfParameters seems to be never defined.
Loading history...
38
    $products = $shelf->getProducts($shelfParameters);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelf seems to be never defined.
Loading history...
39
    if (isset($products['lastTitle'])) {
40
        unset($products['lastTitle']);
41
    }
42
    if (count($products) > 0) {
43
        $block['nostock_msg']    = Oledrion\Utility::getModuleOption('nostock_msg');
44
        $block['block_products'] = $products;
45
        $xoTheme->addStylesheet(OLEDRION_URL . 'assets/css/oledrion.css');
46
47
        return $block;
48
    }
49
50
    return false;
51
}
52
53
/**
54
 * Paramètres du bloc
55
 * @param $options
56
 * @return string
57
 */
58
function b_oledrion_promotion_edit($options)
59
{
60
    // '10|0';  // Voir 10 produits, pour toutes les catégories
61
    global $xoopsConfig;
62
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
63
    // require_once OLEDRION_PATH . 'class/tree.php';
64
    $tblCategories         = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblCategories is dead and can be removed.
Loading history...
65
    $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...
66
    $mytree                = new Oledrion\XoopsObjectTree($tblCategories, 'cat_cid', 'cat_pid');
67
    $form                  = '';
68
    $checkeds              = ['', ''];
69
    $checkeds[$options[1]] = 'checked';
70
    $form                  .= "<table border='0'>";
71
    $form                  .= '<tr><td>' . _MB_OLEDRION_PRODUCTS_CNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "'></td></tr>";
72
    //$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>';
73
    $select0 = $mytree->makeSelectElement('options[]', 'cat_title', '-', $options[1], true, 0, '', _MB_OLEDRION_ALL_CATEGORIES);
74
    $select  = $select0->render();
75
76
    $form .= '<tr><td>' . _MB_OLEDRION_CATEGORY . '</td><td>' . $select . '</td></tr>';
77
    $form .= '</table>';
78
79
    return $form;
80
}
81
82
/**
83
 * Bloc à la volée
84
 * @param $options
85
 */
86
function b_oledrion_promotion_show_duplicatable($options)
87
{
88
    $options = explode('|', $options);
89
    $block   = b_oledrion_promotion_show($options);
90
91
    $tpl = new \XoopsTpl();
92
    $tpl->assign('block', $block);
93
    $tpl->display('db:oledrion_block_promotion.tpl');
94
}
95