b_oledrion_random_show_duplicatable()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
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 x produit(s) au hasard
24
 * @param $options
25
 * @return array|bool
26
 */
27
function b_oledrion_random_show($options)
28
{
29
    // '10|0|0';    // Voir 10 produits, pour toutes les catégories ou une catégorie particulière, et pour ce mois-ci ou pour tout le temps ?
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
    $categoryId    = $options[1];
36
    $thisMonthOnly = (int)$options[2];
37
38
    $shelfParameters->resetDefaultValues()->setProductsType('random')->setStart($start)->setLimit($limit)->setSort('RAND()')->setCategory($categoryId)->setThisMonthOnly($thisMonthOnly);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelfParameters seems to be never defined.
Loading history...
39
    $products = $shelf->getProducts($shelfParameters);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $shelf seems to be never defined.
Loading history...
40
41
    if (isset($products['lastTitle'])) {
42
        unset($products['lastTitle']);
43
    }
44
    if (count($products) > 0) {
45
        $block['nostock_msg']    = Oledrion\Utility::getModuleOption('nostock_msg');
46
        $block['block_products'] = $products;
47
        $xoTheme->addStylesheet(OLEDRION_URL . 'assets/css/oledrion.css');
48
49
        return $block;
50
    }
51
52
    return false;
53
}
54
55
/**
56
 * Paramètres du bloc
57
 * @param $options
58
 * @return string
59
 */
60
function b_oledrion_random_edit($options)
61
{
62
    // '10|0|0';    // Voir 10 produits, pour toutes les catégories, pour ce mois-ci ou pour toute la période
63
    global $xoopsConfig;
64
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
65
    // require_once OLEDRION_PATH . 'class/tree.php';
66
    $tblCategories         = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $tblCategories is dead and can be removed.
Loading history...
67
    $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...
68
    $mytree                = new Oledrion\XoopsObjectTree($tblCategories, 'cat_cid', 'cat_pid');
69
    $form                  = '';
70
    $checkeds              = ['', ''];
71
    $checkeds[$options[1]] = 'checked';
72
    $form                  .= "<table border='0'>";
73
    $form                  .= '<tr><td>' . _MB_OLEDRION_PRODUCTS_CNT . "</td><td><input type='text' name='options[]' id='options' value='" . $options[0] . "'></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
80
    $checked              = ['', ''];
81
    $checked[$options[2]] = 'checked';
82
    $form                 .= '<tr><td>' . _MB_OLEDRION_THIS_MONTH . "</td><td><input type='radio' name='options[]' id='options' value='1'" . $checked[1] . '>' . _YES . " <input type='radio' name='options[]' id='options' value='0'" . $checked[0] . '>' . _NO . '</td></tr>';
83
    $form                 .= '</table>';
84
85
    return $form;
86
}
87
88
/**
89
 * Bloc à la volée
90
 * @param $options
91
 */
92
function b_oledrion_random_show_duplicatable($options)
93
{
94
    $options = explode('|', $options);
95
    $block   = b_oledrion_random_show($options);
96
97
    $tpl = new \XoopsTpl();
98
    $tpl->assign('block', $block);
99
    $tpl->display('db:oledrion_block_random.tpl');
100
}
101