bExtcalNewShow()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 28
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 28
rs 9.4555
c 0
b 0
f 0
cc 5
nc 3
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 bExtcalNewShow($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
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
    /** @var EventHandler $eventHandler */
55
    $events = $eventHandler->objectToArray($eventHandler->getNewEvent(0, $nbEvent, $options));
56
    $eventHandler->serverTimeToUserTimes($events);
57
    $eventHandler->formatEventsDate($events, $helper->getConfig('event_date_month'));
58
59
    return $events;
60
}
61
62
/**
63
 * @param $options
64
 *
65
 * @return string
66
 */
67
function bExtcalNewEdit($options)
68
{
69
    global $xoopsUser;
70
71
    $helper = Helper::getInstance();
72
    $helper->loadLanguage('main');
73
    $helper->loadLanguage('blocks');
74
    /** @var CategoryHandler $categoryHandler */
75
    $categoryHandler = $helper->getHandler(_EXTCAL_CLN_CAT);
76
77
    $cats = $categoryHandler->getAllCat($xoopsUser, 'extcal_cat_view');
78
79
    $form = _MB_EXTCAL_DISPLAY . "&nbsp;\n";
80
    $form .= '<input name="options[0]" size="5" maxlength="255" value="' . $options[0] . '" type="text">&nbsp;' . _MB_EXTCAL_EVENT . '<br>';
81
    $form .= _MB_EXTCAL_TITLE_LENGTH . ' : <input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text"><br>';
82
    array_shift($options);
83
    array_shift($options);
84
    $form .= _MB_EXTCAL_CAT_TO_USE . '<br><select name="options[]" multiple="multiple" size="5">';
85
    if (false === array_search(0, $options, true)) {
86
        $form .= '<option value="0">' . _MB_EXTCAL_ALL_CAT . '</option>';
87
    } else {
88
        $form .= '<option value="0" selected="selected">' . _MB_EXTCAL_ALL_CAT . '</option>';
89
    }
90
    foreach ($cats as $cat) {
91
        if (false === array_search($cat->getVar('cat_id'), $options, true)) {
92
            $form .= '<option value="' . $cat->getVar('cat_id') . '">' . $cat->getVar('cat_name') . '</option>';
93
        } else {
94
            $form .= '<option value="' . $cat->getVar('cat_id') . '" selected="selected">' . $cat->getVar('cat_name') . '</option>';
95
        }
96
    }
97
    $form .= '</select>';
98
99
    return $form;
100
}
101