bExtcalUpcomingByCategoryShow()   B
last analyzed

Complexity

Conditions 8
Paths 13

Size

Total Lines 48
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
c 0
b 0
f 0
dl 0
loc 48
rs 8.4444
cc 8
nc 13
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
    EventHandler,
22
    CategoryHandler
23
};
24
25
require_once dirname(__DIR__) . '/include/constantes.php';
26
27
/******************************************************/
28
/* Ajour JJD - Evenements par categries               */
29
/******************************************************/
30
/**
31
 * @param $options
32
 *
33
 * @return array|bool
34
 */
35
function bExtcalUpcomingByCategoryShow($options)
36
{
37
    global $xoopsUser;
38
39
    /** @var Helper $helper */
40
    if (!class_exists(Helper::class)) {
41
        return false;
42
    }
43
44
    $helper = Helper::getInstance();
45
    $helper->loadLanguage('main');
46
47
    $eventHandler = $helper->getHandler(_EXTCAL_CLN_EVENT);
48
49
    $nbEvent     = $options[0];
50
    $titleLenght = $options[1];
0 ignored issues
show
Unused Code introduced by
The assignment to $titleLenght is dead and can be removed.
Loading history...
51
    array_shift($options);
52
    array_shift($options);
53
54
    // Checking if no cat is selected
55
    if (isset($options[0]) && 0 == $options[0] && 1 == count($options)) {
56
        $options = 0;
57
    }
58
59
    $events = $eventHandler->objectToArray($eventHandler->getUpcommingEvent($nbEvent, $options));
0 ignored issues
show
Bug introduced by
The method objectToArray() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
    /** @scrutinizer ignore-call */ 
60
    $events = $eventHandler->objectToArray($eventHandler->getUpcommingEvent($nbEvent, $options));
Loading history...
Bug introduced by
The method getUpcommingEvent() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

59
    $events = $eventHandler->objectToArray($eventHandler->/** @scrutinizer ignore-call */ getUpcommingEvent($nbEvent, $options));
Loading history...
60
    $eventHandler->serverTimeToUserTimes($events);
0 ignored issues
show
Bug introduced by
The method serverTimeToUserTimes() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
    $eventHandler->/** @scrutinizer ignore-call */ 
61
                   serverTimeToUserTimes($events);
Loading history...
61
    $eventHandler->formatEventsDate($events, $helper->getConfig('event_date_month'));
0 ignored issues
show
Bug introduced by
The method formatEventsDate() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

61
    $eventHandler->/** @scrutinizer ignore-call */ 
62
                   formatEventsDate($events, $helper->getConfig('event_date_month'));
Loading history...
62
63
    /***********************************************************/
64
    $categoryHandler = $helper->getHandler(_EXTCAL_CLN_CAT);
65
    $t               = $categoryHandler->objectToArray($categoryHandler->getAllCat($xoopsUser, 'all'));
0 ignored issues
show
Bug introduced by
The method getAllCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

65
    $t               = $categoryHandler->objectToArray($categoryHandler->/** @scrutinizer ignore-call */ getAllCat($xoopsUser, 'all'));
Loading history...
66
    $tCats           = [];
67
    foreach ($t as $h => $hValue) {
68
        $tCats[$t[$h]['cat_id']] = $hValue;
69
    }
70
71
    $te = [];
72
73
    foreach ($events as $h => $hValue) {
74
        $catId = $events[$h]['cat_id'];
75
        if (!isset($te[$catId])) {
76
            $te[$catId]           = $tCats[$catId];
77
            $te[$catId]['events'] = [];
78
        }
79
        $te[$catId]['events'][] = $hValue;
80
    }
81
82
    return $te;
83
}
84
85
/**
86
 * @param $options
87
 *
88
 * @return string
89
 */
90
function bExtcalUpcomingByCategoryEdit($options)
91
{
92
    global $xoopsUser;
93
94
    $helper          = Helper::getInstance();
95
    $categoryHandler = $helper->getHandler(_EXTCAL_CLN_CAT);
96
97
    $cats = $categoryHandler->getAllCat($xoopsUser, 'extcal_cat_view');
98
99
    $form = _MB_EXTCAL_DISPLAY . "&nbsp;\n";
100
    $form .= '<input name="options[0]" size="5" maxlength="255" value="' . $options[0] . '" type="text">&nbsp;' . _MB_EXTCAL_EVENT . '<br>';
101
    $form .= _MB_EXTCAL_TITLE_LENGTH . ' : <input name="options[1]" size="5" maxlength="255" value="' . $options[1] . '" type="text"><br>';
102
    array_shift($options);
103
    array_shift($options);
104
    $form .= _MB_EXTCAL_CAT_TO_USE . '<br><select name="options[]" multiple="multiple" size="5">';
105
    if (false === array_search(0, $options, true)) {
106
        $form .= '<option value="0">' . _MB_EXTCAL_ALL_CAT . '</option>';
107
    } else {
108
        $form .= '<option value="0" selected="selected">' . _MB_EXTCAL_ALL_CAT . '</option>';
109
    }
110
    foreach ($cats as $cat) {
111
        if (false === array_search($cat->getVar('cat_id'), $options, true)) {
112
            $form .= '<option value="' . $cat->getVar('cat_id') . '">' . $cat->getVar('cat_name') . '</option>';
113
        } else {
114
            $form .= '<option value="' . $cat->getVar('cat_id') . '" selected="selected">' . $cat->getVar('cat_name') . '</option>';
115
        }
116
    }
117
    $form .= '</select>';
118
119
    return $form;
120
}
121