b_oledrion__mostviewed_lists_edit()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 12
rs 9.9666
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
use XoopsModules\Oledrion\Constants;
22
23
/**
24
 * Affichage des listes les plus vues
25
 *
26
 * @param  array $options [0] = Nombre maximum de listes à voir, [1] = Type de listes (0 = les 2, 1 = liste cadeaux, 2 = produits recommandés)
27
 * @return array
28
 */
29
function b_oledrion_mostviewed_lists_show($options)
30
{
31
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
32
    /** @var \XoopsModules\Oledrion\Helper $helper */
33
    $helper = \XoopsModules\Oledrion\Helper::getInstance();
34
    $helper->loadLanguage('main');
35
    $start    = 0;
36
    $limit    = (int)$options[0];
37
    $listType = (int)$options[1];
0 ignored issues
show
Unused Code introduced by
The assignment to $listType is dead and can be removed.
Loading history...
38
    $block    = [];
39
    //    $handlers = HandlerManager::getInstance();
40
    $db           = \XoopsDatabaseFactory::getDatabaseConnection();
41
    $listsHandler = new Oledrion\ListsHandler($db);
42
    $items        = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $items is dead and can be removed.
Loading history...
43
    //$items = $handlers->h_oledrion_lists->getRecentLists(new Oledrion\Parameters(array('start' => $start, 'limit' => $limit, 'sort' => 'list_views', 'order' => 'DESC', 'idAsKey' => true, 'listType' => $listType)));
44
    $items = $listsHandler->getRecentLists(new Oledrion\Parameters([
45
                                                                       'start'    => $start,
46
                                                                       'limit'    => $limit,
47
                                                                       'sort'     => 'list_views',
48
                                                                       'order'    => 'DESC',
49
                                                                       'idAsKey'  => true,
50
                                                                       'listType' => Constants::OLEDRION_LISTS_ALL_PUBLIC,
51
                                                                   ]));
52
    if (count($items) > 0) {
53
        foreach ($items as $item) {
54
            $block['mostviewd_lists'][] = $item->toArray();
55
        }
56
    }
57
58
    return $block;
59
}
60
61
/**
62
 * Edition des paramètres du bloc
63
 *
64
 * @param  array $options [0] = Nombre maximum de listes à voir, [1] = Type de listes (0 = les 2, 1 = liste cadeaux, 2 = produits recommandés)
65
 * @return string
66
 */
67
function b_oledrion__mostviewed_lists_edit($options)
68
{
69
    require_once XOOPS_ROOT_PATH . '/modules/oledrion/include/common.php';
70
    $form           = '';
71
    $form           .= "<table border='0'>";
72
    $form           .= '<tr><td>' . _MB_OLEDRION_LISTS_COUNT . "</td><td><input type='text' name='options[]' id='options' value='" . (int)$options[0] . "'></td></tr>";
73
    $listTypes      = Oledrion\Lists::getTypesArray();
74
    $listTypeSelect = Oledrion\Utility::htmlSelect('options[]', $listTypes, (int)$options[1], false);
75
    $form           .= '<tr><td>' . _MB_OLEDRION_LISTS_TYPE . '</td><td>' . $listTypeSelect . '</td></tr>';
76
    $form           .= '</table>';
77
78
    return $form;
79
}
80
81
/**
82
 * Bloc à la volée
83
 * @param $options
84
 */
85
function b_oledrion_mostviewed_lists_duplicatable($options)
86
{
87
    $options = explode('|', $options);
88
    $block   = b_oledrion_mostviewed_lists_show($options);
89
90
    $tpl = new \XoopsTpl();
91
    $tpl->assign('block', $block);
92
    $tpl->display('oledrion_block_mostviewed_lists.tpl');
93
}
94