bExtcalRandomEdit()   A
last analyzed

Complexity

Conditions 4
Paths 6

Size

Total Lines 31
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 21
dl 0
loc 31
rs 9.584
c 0
b 0
f 0
cc 4
nc 6
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
 * @copyright    {@link https://xoops.org/ XOOPS Project}
14
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
15
 * @package      extcal
16
 * @since
17
 * @author       XOOPS Development Team,
18
 */
19
20
use XoopsModules\Extcal\{Helper,
21
    CategoryHandler,
22
    EventHandler
23
};
24
25
require_once dirname(__DIR__) . '/include/constantes.php';
26
27
/**
28
 * @param $options
29
 *
30
 * @return array|bool
31
 */
32
function bExtcalRandomShow($options)
33
{
34
    /** @var Helper $helper */
35
    if (!class_exists(Helper::class)) {
36
        return false;
37
    }
38
39
    $helper = Helper::getInstance();
40
    $helper->loadLanguage('main');
41
    /** @var EventHandler $eventHandler */
42
    $eventHandler = $helper->getHandler(_EXTCAL_CLN_EVENT);
43
44
    $nbEvent     = $options[0];
45
    $titleLenght = $options[1];
0 ignored issues
show
Unused Code introduced by
The assignment to $titleLenght is dead and can be removed.
Loading history...
46
    array_shift($options);
47
    array_shift($options);
48
49
    // Checking if no cat is selected
50
    if (isset($options[0]) && 0 == $options[0] && 1 == count($options)) {
51
        $options = 0;
52
    }
53
54
    $events = $eventHandler->objectToArray($eventHandler->getRandomEvent($nbEvent, $options));
55
    $eventHandler->serverTimeToUserTimes($events);
56
    $eventHandler->formatEventsDate($events, $helper->getConfig('event_date_month'));
57
58
    return $events;
59
}
60
61
/**
62
 * @param $options
63
 *
64
 * @return string
65
 */
66
function bExtcalRandomEdit($options)
67
{
68
    global $xoopsUser;
69
70
    $helper = Helper::getInstance();
71
    /** @var CategoryHandler $categoryHandler */
72
    $categoryHandler = $helper->getHandler(_EXTCAL_CLN_CAT);
73
74
    $cats = $categoryHandler->getAllCat($xoopsUser, 'extcal_cat_view');
75
76
    $form = _MB_EXTCAL_DISPLAY . "&nbsp;\n";
77
    $form .= '<input name="options[0]" size="5" maxlength="255" value="' . $options[0] . '" type="text">&nbsp;' . _MB_EXTCAL_EVENT . '<br>';
78
    $form .= _MB_EXTCAL_TITLE_LENGTH . ' : <input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text"><br>';
79
    array_shift($options);
80
    array_shift($options);
81
    $form .= _MB_EXTCAL_CAT_TO_USE . '<br><select name="options[]" multiple="multiple" size="5">';
82
    if (false === array_search(0, $options, true)) {
83
        $form .= '<option value="0">' . _MB_EXTCAL_ALL_CAT . '</option>';
84
    } else {
85
        $form .= '<option value="0" selected="selected">' . _MB_EXTCAL_ALL_CAT . '</option>';
86
    }
87
    foreach ($cats as $cat) {
88
        if (false === array_search($cat->getVar('cat_id'), $options, true)) {
89
            $form .= '<option value="' . $cat->getVar('cat_id') . '">' . $cat->getVar('cat_name') . '</option>';
90
        } else {
91
            $form .= '<option value="' . $cat->getVar('cat_id') . '" selected="selected">' . $cat->getVar('cat_name') . '</option>';
92
        }
93
    }
94
    $form .= '</select>';
95
96
    return $form;
97
}
98