Passed
Push — master ( d2520f...3f8ec2 )
by Michael
02:50
created

EventHandler::getSearchEvent()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 11
nc 2
nop 6
1
<?php namespace XoopsModules\Extcal;
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 31 and the first side effect is on line 26.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
/*
4
 * You may not change or alter any portion of this comment or credits
5
 * of supporting developers from this source code or any supporting source code
6
 * which is considered copyrighted (c) material of the original comment or credit authors.
7
 *
8
 * This program is distributed in the hope that it will be useful,
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * @copyright    {@link https://xoops.org/ XOOPS Project}
15
 * @license      {@link http://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
16
 * @package      extcal
17
 * @since
18
 * @author       XOOPS Development Team,
19
 */
20
21
//use Punic\Exception;
22
use XoopsModules\Extcal;
23
24
// defined('XOOPS_ROOT_PATH') || die('Restricted access');
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
25
26
require_once __DIR__ . '/../include/constantes.php';
27
28
/**
29
 * Class EventHandler.
30
 */
31
class EventHandler extends ExtcalPersistableObjectHandler
32
{
33
    private $extcalPerm;
34
    private $extcalTime;
35
//    private $extcalConfig;
36
37
    /**
38
     * @param $db
39
     */
40
    public function __construct(\XoopsDatabase $db)
0 ignored issues
show
Bug introduced by
The type XoopsDatabase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
41
    {
42
        $this->extcalPerm = Extcal\Perm::getHandler();
43
        $this->extcalTime = Extcal\Time::getHandler();
44
//        $this->extcalConfig = Extcal\Config::getHandler();
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
45
        parent::__construct($db, 'extcal_event', Event::class, 'event_id');
46
    }
47
48
    /**
49
     * @param $data
50
     *
51
     * @return bool
52
     */
53
    public function createEvent($data)
54
    {
55
        $event = $this->create();
56
        $this->checkDate($data);
57
        $this->userTimeToServerTime($data);
58
        $this->addRecurValue($data);
59
        $event->setVars($data);
60
61
        return $this->insert($event, true);
62
    }
63
64
    /**
65
     * @param $data
66
     *
67
     * @return \XoopsObject
0 ignored issues
show
Bug introduced by
The type XoopsObject was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
68
     */
69
    public function createEventForPreview($data)
70
    {
71
        $event = $this->create();
72
        $this->checkDate($data);
73
        $this->addRecurValue($data);
74
        $event->setVars($data);
75
76
        return $event;
77
    }
78
79
    /**
80
     * @param $eventId
81
     * @param $data
82
     *
83
     * @return bool
84
     */
85
    public function modifyEvent($eventId, $data)
86
    {
87
        $event = $this->get($eventId);
88
        $this->checkDate($data);
89
        $this->userTimeToServerTime($data);
90
        $this->addRecurValue($data);
91
        $event->setVars($data);
92
93
        return $this->insert($event);
94
    }
95
96
    /**
97
     * @param $eventId
98
     */
99
    public function deleteEvent($eventId)
100
    {
101
        /* TODO :
102
           - Delete who's going
103
           - Delete who's not going
104
           - Delete comment
105
           - Delete notifications
106
          */
107
        $this->deleteById($eventId, true);
108
    }
109
110
    /**
111
     * @param null $criteria
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $criteria is correct as it would always require null to be passed?
Loading history...
112
     * @param bool $force
113
     * @param bool $asObject
114
     */
115
    public function deleteAllEvents($criteria = null, $force = true, $asObject = false)
116
    {
117
        /* TODO :
118
           - Delete who's going
119
           - Delete who's not going
120
           - Delete comment
121
           - Delete notifications
122
          */
123
        $this->deleteAll($criteria, $force, $asObject);
124
    }
125
126
    /**
127
     * @param null $criteria
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $criteria is correct as it would always require null to be passed?
Loading history...
128
     * @param bool $asObject
129
     *
130
     * @return array
131
     */
132
    public function getAllEvents($criteria = null, $asObject = false)
133
    {
134
        $rst =& $this->getObjects($criteria, $asObject);
135
        if ($asObject) {
136
            return $rst;
137
        } else {
138
            return $this->objectToArray($rst);
139
        }
140
    }
141
142
    // Return one approved event selected by his id
143
144
    /**
145
     * @param      $eventId
146
     * @param bool $skipPerm
147
     *
148
     * @return bool
149
     */
150
    public function getEvent($eventId, $skipPerm = false)
151
    {
152
        $user = $GLOBALS['xoopsUser'];
153
154
        $criteriaCompo = new \CriteriaCompo();
0 ignored issues
show
Bug introduced by
The type CriteriaCompo was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
155
        $criteriaCompo->add(new \Criteria('event_id', $eventId));
0 ignored issues
show
Bug introduced by
The type Criteria was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
156
        $criteriaCompo->add(new \Criteria('event_approved', 1));
157
        if (!$skipPerm) {
158
            $this->addCatPermCriteria($criteriaCompo, $user);
159
        }
160
        $ret =& $this->getObjects($criteriaCompo);
161
        if (isset($ret[0])) {
162
            return $ret[0];
163
        } else {
164
            return false;
165
        }
166
    }
167
168
    // Return one event selected by his id (approve or not)
169
170
    /**
171
     * @param      $eventId
172
     * @param bool $skipPerm
173
     *
174
     * @return bool
175
     */
176
    public function getEventWithNotApprove($eventId, $skipPerm = false)
177
    {
178
        $user = $GLOBALS['xoopsUser'];
179
180
        $criteriaCompo = new \CriteriaCompo();
181
        $criteriaCompo->add(new \Criteria('event_id', $eventId));
182
        if (!$skipPerm) {
183
            $this->addCatPermCriteria($criteriaCompo, $user);
184
        }
185
        $ret =& $this->getObjects($criteriaCompo);
186
        if (isset($ret[0])) {
187
            return $ret[0];
188
        } else {
189
            return false;
190
        }
191
    }
192
193
    /**
194
     * @param $events
195
     * @param $pattern
196
     */
197
    public function formatEventsDate(&$events, $pattern)
198
    {
199
        //        $max = count($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
200
        //        for ($i = 0; $i < $max; ++$i) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
201
        //            $this->formatEventDate($events[$i], $pattern);
0 ignored issues
show
Unused Code Comprehensibility introduced by
79% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
202
        //        }
203
        foreach ($events as $i => $iValue) {
204
            $this->formatEventDate($events[$i], $pattern);
205
        }
206
    }
207
208
    //  function getPicture1(&$event) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
209
    //      return $event['event_picture1'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
210
    //  }
211
    //  function getPicture2(&$event) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
212
    //      return $event['event_picture2'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
213
    //  }
214
    //  function getDesc(&$event) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
215
    //      return $event['event_desc'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
216
    //  }
217
218
    /**
219
     * @param $event
220
     * @param $pattern
221
     */
222
    public function formatEventDate(&$event, $pattern)
223
    {
224
        if (!$event['event_isrecur']) {
225
            $event['formated_event_start'] = $this->extcalTime->getFormatedDate($pattern, $event['event_start']);
226
            $event['formated_event_end']   = $this->extcalTime->getFormatedDate($pattern, $event['event_end']);
227
        } else {
228
            $event['formated_event_start'] = $this->extcalTime->getFormatedDate($pattern, $event['event_start']);
229
            $event['formated_event_end']   = $this->extcalTime->getFormatedDate($pattern, $event['event_end']);
230
            $event['formated_reccur_rule'] = $this->extcalTime->getFormatedReccurRule($event['event_recur_rules']);
231
        }
232
        $event['formated_event_submitdate'] = $this->extcalTime->getFormatedDate($pattern, $event['event_submitdate']);
233
    }
234
235
    //JJD - to valid modif
236
    //     function checkDate(&$data)
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
237
    //     {
238
    //
239
    //         list($year, $month, $day) = explode("-", $data['event_start']['date']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
240
    //         $data['event_start']
241
    //             =
242
    //             mktime(0, 0, 0, $month, $day, $year) + $data['event_start']['time'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
68% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
243
    //         list($year, $month, $day) = explode("-", $data['event_end']['date']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
244
    //         $data['event_end']
245
    //             = mktime(0, 0, 0, $month, $day, $year) + $data['event_end']['time'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
246
    //
247
    //         if ($data['have_end'] == 0 || $data['event_start'] > $data['event_end']
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
248
    //) {
249
    //             $data['event_end'] = $data['event_start'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
70% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
250
    //         }
251
    //
252
    //     }
253
254
    /**
255
     * @param $data
256
     */
257
    public function checkDate(&$data)
258
    {
259
        $data['event_start'] = strtotime($data['event_start']['date']) + $data['event_start']['time'];
260
        $data['event_end']   = strtotime($data['event_end']['date']) + $data['event_end']['time'];
261
262
        if (0 == $data['have_end'] || $data['event_start'] > $data['event_end']) {
263
            $data['event_end'] = $data['event_start'];
264
        }
265
    }
266
267
    /**
268
     * @param $data
269
     */
270
    private function userTimeToServerTime(&$data)
271
    {
272
        $user = $GLOBALS['xoopsUser'];
273
274
        $data['event_start'] = userTimeToServerTime($data['event_start'], $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function userTimeToServerTime was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

274
        $data['event_start'] = /** @scrutinizer ignore-call */ userTimeToServerTime($data['event_start'], $this->extcalTime->getUserTimeZone($user));
Loading history...
275
        $data['event_end']   = userTimeToServerTime($data['event_end'], $this->extcalTime->getUserTimeZone($user));
276
    }
277
278
    /**
279
     * @param $data
280
     */
281
    public function serverTimeToUserTime(&$data)
282
    {
283
        $user = $GLOBALS['xoopsUser'];
284
285
        $data['event_start']      = xoops_getUserTimestamp($data['event_start'], $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function xoops_getUserTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

285
        $data['event_start']      = /** @scrutinizer ignore-call */ xoops_getUserTimestamp($data['event_start'], $this->extcalTime->getUserTimeZone($user));
Loading history...
286
        $data['event_end']        = xoops_getUserTimestamp($data['event_end'], $this->extcalTime->getUserTimeZone($user));
287
        $data['event_submitdate'] = xoops_getUserTimestamp($data['event_submitdate'], $this->extcalTime->getUserTimeZone($user));
288
    }
289
290
    /**
291
     * @param $events
292
     */
293
    public function serverTimeToUserTimes(&$events)
294
    {
295
        foreach ($events as $i => $iValue) {
296
            $this->serverTimeToUserTime($events[$i]);
297
        }
298
    }
299
300
    /**
301
     * @param $data
302
     */
303
    public function addRecurValue(&$data)
304
    {
305
        $data['event_isrecur']     = $this->getIsRecur($_POST);
306
        $data['event_recur_rules'] = $this->getRecurRules($_POST);
307
        $data['event_recur_start'] = $this->getRecurStart($data, $_POST);
308
        $data['event_recur_end']   = $this->getRecurEnd($data, $_POST);
309
    }
310
311
    /***************************************************************
312
     * Return events on perioe
313
     **************************************************************
314
     *
315
     * @param $criteres
316
     *
317
     * @return array
318
     */
319
    public function getEventsOnPeriode($criteres)
320
    {
321
        //Extcal\Utility::echoArray($criteres);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
322
        $myts = \MyTextSanitizer::getInstance(); // MyTextSanitizer object
0 ignored issues
show
Bug introduced by
The type MyTextSanitizer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
323
324
        $eventsU = $this->getEventsUniques($criteres);
325
        $eventsR = $this->getEventsRecurents($criteres);
326
        $events  = array_merge($eventsU, $eventsR);
327
328
        //      $events = $eventsU;
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
329
330
        //Extcal\Utility::echoArray($events);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
331
332
        //Tri des evennement par date ascendante
333
        $ordre      = [];
334
        $eventArray = [];
335
336
        //        while (list($k, $v) = each($events)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
337
        foreach ($events as $k => $v) {
338
            $ordre[] = (int)$v['event_start'];
339
            $this->formatEventDate($v, Extcal\Helper::getInstance()->getConfig('event_date_week'));
340
            //$v['cat']['cat_light_color'] = $v['cat']['cat_color'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
341
            $v['cat']['cat_light_color'] = Extcal\Utility::getLighterColor($v['cat']['cat_color'], _EXTCAL_INFOBULLE_RGB_MIN, _EXTCAL_INFOBULLE_RGB_MAX);
342
            if ('' == $v['event_icone']) {
343
                $v['event_icone'] = $v['cat']['cat_icone'];
344
            }
345
            $v['event_desc'] = html_entity_decode($v['event_desc']);
346
            $eventArray[]    = $v;
347
        }
348
        array_multisort($eventArray, SORT_ASC, SORT_NUMERIC, $ordre, SORT_ASC, SORT_NUMERIC);
349
350
        return $eventArray;
351
    }
352
353
    /*****************************************************************
354
     *
355
     ****************************************************************
356
     * @param $criteres
357
     * @return array
358
     */
359
    public function getEventsUniques($criteres)
360
    {
361
        $cat = 0;
362
        //        while (list($k, $v) = each($criteres)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
363
        foreach ($criteres as $k => $v) {
364
            $$k = $v;
365
        }
366
        if (!isset($nbDays)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $nbDays seems to never exist and therefore isset should always be false.
Loading history...
367
            $nbDays = 7;
368
        }
369
        if (!isset($sens)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $sens seems to never exist and therefore isset should always be false.
Loading history...
370
            $sens = 'ASC';
371
        }
372
        if (!isset($externalKeys)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $externalKeys seems to never exist and therefore isset should always be false.
Loading history...
373
            $externalKeys = ['cat_id'];
374
        }
375
        //------------------------------------------------------
376
        switch ($periode) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $periode seems to be never defined.
Loading history...
377
378
            case _EXTCAL_EVENTS_CALENDAR_WEEK:
379
                $criteriaCompo = $this->getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $year seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $day seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $month seems to be never defined.
Loading history...
380
                if (!Extcal\Helper::getInstance()->getConfig('diplay_past_event_cal')) {
381
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
382
                }
383
                break;
384
385
            case _EXTCAL_EVENTS_WEEK:
386
            case _EXTCAL_EVENTS_AGENDA_WEEK:
387
                $criteriaCompo = $this->getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
388
                if (!Extcal\Helper::getInstance()->getConfig('diplay_past_event_list')) {
389
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
390
                }
391
                break;
392
393
            case _EXTCAL_EVENTS_CALENDAR_MONTH:
394
                $criteriaCompo = $this->getEventMonthCriteria($month, $year, $cat);
395
396
                if (!Extcal\Helper::getInstance()->getConfig('diplay_past_event_cal')) {
397
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
398
                }
399
                break;
400
401
            case _EXTCAL_EVENTS_MONTH:
402
                $criteriaCompo = $this->getEventMonthCriteria($month, $year, $cat);
403
404
                if (!Extcal\Helper::getInstance()->getConfig('diplay_past_event_list')) {
405
                    $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
406
                }
407
                break;
408
409
            case _EXTCAL_EVENTS_DAY:
410
                $criteriaCompo = $this->getEventDayCriteria($day, $month, $year, $cat);
411
412
                break;
413
414
            case _EXTCAL_EVENTS_YEAR:
415
                $criteriaCompo = $this->getEventYearCriteria($year, $cat);
416
                break;
417
418
            case _EXTCAL_EVENTS_UPCOMING:
419
                $criteriaCompo = $this->getEventWeekCriteria($day, $month, $year, $cat, $nbDays);
420
                break;
421
422
        }
423
        //--------------------------------------------------------------------------
424
        $criteriaCompo->add(new \Criteria('event_isrecur', 0, '='));
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $criteriaCompo does not seem to be defined for all execution paths leading up to this point.
Loading history...
425
        $criteriaCompo->setOrder($sens);
426
427
        $result =& $this->getObjects($criteriaCompo);
428
        $events = $this->objectToArray($result, $externalKeys);
429
        $this->serverTimeToUserTimes($events);
430
431
        return $events;
432
    }
433
434
    /*****************************************************************
435
     * evennement récurents
436
     ****************************************************************
437
     * @param $criteres
438
     * @return array
439
     */
440
441
    public function getEventsRecurents($criteres)
442
    {
443
        //        while (list($k, $v) = each($criteres)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
444
        foreach ($criteres as $k => $v) {
445
            $$k = $v;
446
        }
447
        if (!isset($nbDays)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $nbDays seems to never exist and therefore isset should always be false.
Loading history...
448
            $nbDays = 7;
449
        }
450
        if (!isset($sens)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $sens seems to never exist and therefore isset should always be false.
Loading history...
451
            $sens = 'ASC';
452
        }
453
        if (!isset($externalKeys)) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $externalKeys seems to never exist and therefore isset should always be false.
Loading history...
454
            $externalKeys = ['cat_id'];
455
        }
456
        $user = $GLOBALS['xoopsUser'];
457
        //------------------------------------------------------
458
459
        $criteriaCompo = new \CriteriaCompo();
460
461
        switch ($periode) {
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $periode seems to be never defined.
Loading history...
462
            case _EXTCAL_EVENTS_WEEK:
463
            case _EXTCAL_EVENTS_CALENDAR_WEEK:
464
            case _EXTCAL_EVENTS_AGENDA_WEEK:
465
            case _EXTCAL_EVENTS_UPCOMING:
466
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function userTimeToServerTime was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

466
                $start = /** @scrutinizer ignore-call */ userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->extcalTime->getUserTimeZone($user));
Loading history...
Comprehensibility Best Practice introduced by
The variable $day seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $year seems to be never defined.
Loading history...
Comprehensibility Best Practice introduced by
The variable $month seems to be never defined.
Loading history...
467
                $end   = userTimeToServerTime(mktime(0, 0, 0, $month, $day + $nbDays + 1, $year), $this->extcalTime->getUserTimeZone($user));
468
                //$end = $start + (($nbDays + 1 )* _EXTCAL_TS_DAY);
0 ignored issues
show
Unused Code Comprehensibility introduced by
41% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
469
                //$end = userTimeToServerTime(mktime(0, 0, 0, $month, $day+(($nbJours)+1 * _EXTCAL_TS_DAY), $year), $this->extcalTime->getUserTimeZone($user));;
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
470
                break;
471
472
            case _EXTCAL_EVENTS_MONTH:
473
            case _EXTCAL_EVENTS_CALENDAR_MONTH:
474
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, 1, $year), $this->extcalTime->getUserTimeZone($user));
475
                $end   = userTimeToServerTime(mktime(23, 59, 59, $month + 1, 1, $year) - _EXTCAL_TS_DAY, $this->extcalTime->getUserTimeZone($user));
476
477
                $criteriaCompo->add(new \Criteria('event_start', $end, '<='));
478
                //$criteriaCompo->add( new \Criteria('event_end', $start, '>='));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
479
480
                break;
481
482
            case _EXTCAL_EVENTS_DAY:
483
                $start = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->extcalTime->getUserTimeZone($user));
484
                $end   = userTimeToServerTime(mktime(0, 0, 0, $month, $day + 1, $year), $this->extcalTime->getUserTimeZone($user));
485
                //$criteriaCompo->add( new \Criteria('event_start', $end, '<='));
0 ignored issues
show
Unused Code Comprehensibility introduced by
69% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
486
487
                break;
488
489
            case _EXTCAL_EVENTS_YEAR:
490
                $start = userTimeToServerTime(mktime(0, 0, 0, 1, 1, $year), $this->extcalTime->getUserTimeZone($user));
491
                $end   = userTimeToServerTime(mktime(0, 0, 0, 12, 31, $year), $this->extcalTime->getUserTimeZone($user));
492
                break;
493
494
        }
495
        $formatDate = Extcal\Helper::getInstance()->getConfig('event_date_week');
0 ignored issues
show
Unused Code introduced by
The assignment to $formatDate is dead and can be removed.
Loading history...
496
        //--------------------------------------------------------------------------
497
        $criteriaCompo->add(new \Criteria('event_isrecur', 1, '='));
498
        $criteriaCompo->setOrder($sens);
499
500
        $result =& $this->getObjects($criteriaCompo);
501
        $events = $this->objectToArray($result, $externalKeys);
502
        $this->serverTimeToUserTimes($events);
503
504
        //Balyage de tous les evennements récurrents et creation de toutes le events
505
        $eventsR = [];
506
        //        while (list($k, $event) = each($events)) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
62% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
507
        foreach ($events as $k => $event) {
508
            //$te = $this->GetInterval($event, $start, $end);
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
509
            //$eventsR = array_merge($eventsR, $te);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
510
            //echo 'event : ' . $event['event_id'] . '<br>';
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
511
            //Extcal\Utility::echoArray($event);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
512
            $recurEvents = $this->getRecurEventToDisplay($event, $start, $end);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $start does not seem to be defined for all execution paths leading up to this point.
Loading history...
Comprehensibility Best Practice introduced by
The variable $end does not seem to be defined for all execution paths leading up to this point.
Loading history...
513
            if (count($recurEvents) > 0) {
514
                $eventsR = array_merge($eventsR, $recurEvents);
515
            }
516
517
            // Formating date
518
            //$eventsR = array_merge($eventsArray, $recurEvents);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
519
        }
520
521
        return $eventsR;
522
    }
523
524
    /*****************************************************************
525
     *
526
     ****************************************************************
527
     * @param        $period
528
     * @param string $caption
529
     */
530
    public function echoDateArray($period, $caption = '')
531
    {
532
        if ('' != $caption) {
533
            echo "<hr>echoDateArray -> {$caption}<br>";
534
        } else {
535
            echo '<hr>echoDateArray<br>';
536
        }
537
538
        reset($period);
539
        foreach ($period as $dt) {
540
            echo $dt->format("l d-m-Y H:i:s\n") . '<br>';
541
        }
542
    }
543
544
    /*****************************************************************
545
     * Criteria
546
     ****************************************************************
547
     * @param     $day
548
     * @param     $month
549
     * @param     $year
550
     * @param int $cat
551
     * @return \CriteriaCompo
552
     */
553
    // Return the criteria compo object for a day
554
    public function getEventDayCriteria($day, $month, $year, $cat = 0)
555
    {
556
        $user = $GLOBALS['xoopsUser'];
557
558
        $dayStart      = userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function userTimeToServerTime was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

558
        $dayStart      = /** @scrutinizer ignore-call */ userTimeToServerTime(mktime(0, 0, 0, $month, $day, $year), $this->extcalTime->getUserTimeZone($user));
Loading history...
559
        $dayEnd        = userTimeToServerTime(mktime(23, 59, 59, $month, $day, $year), $this->extcalTime->getUserTimeZone($user));
560
        $criteriaCompo = $this->getListCriteriaCompo($dayStart, $dayEnd, $cat, $user);
561
562
        return $criteriaCompo;
563
    }
564
565
    // Return the criteria compo object for a week
566
567
    /**
568
     * @param     $day
569
     * @param     $month
570
     * @param     $year
571
     * @param int $cat
572
     * @param int $nbDays
573
     *
574
     * @return \CriteriaCompo
575
     */
576
    public function getEventWeekCriteria($day, $month, $year, $cat = 0, $nbDays = 7)
577
    {
578
        $user = $GLOBALS['xoopsUser'];
579
580
        $userStartTime = mktime(0, 0, 0, $month, $day, $year);
581
        $userEndTime   = $userStartTime + (_EXTCAL_TS_DAY * $nbDays);
582
        $weekStart     = userTimeToServerTime($userStartTime, $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function userTimeToServerTime was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

582
        $weekStart     = /** @scrutinizer ignore-call */ userTimeToServerTime($userStartTime, $this->extcalTime->getUserTimeZone($user));
Loading history...
583
        $weekEnd       = userTimeToServerTime($userEndTime, $this->extcalTime->getUserTimeZone($user));
584
        $criteriaCompo = $this->getCriteriaCompo($weekStart, $weekEnd, $cat, $user);
585
586
        return $criteriaCompo;
587
    }
588
589
    // Return the criteria compo object for a month
590
591
    /**
592
     * @param     $month
593
     * @param     $year
594
     * @param int $cat
595
     *
596
     * @return \CriteriaCompo
597
     */
598
    public function getEventMonthCriteria($month, $year, $cat = 0)
599
    {
600
        $user = $GLOBALS['xoopsUser'];
601
602
        $userStartTime = mktime(0, 0, 0, $month, 1, $year);
603
        $userEndTime   = mktime(23, 59, 59, $month + 1, 0, $year);
604
        $monthStart    = userTimeToServerTime($userStartTime, $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function userTimeToServerTime was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

604
        $monthStart    = /** @scrutinizer ignore-call */ userTimeToServerTime($userStartTime, $this->extcalTime->getUserTimeZone($user));
Loading history...
605
        $monthEnd      = userTimeToServerTime($userEndTime, $this->extcalTime->getUserTimeZone($user));
606
        $criteriaCompo = $this->getCriteriaCompo($monthStart, $monthEnd, $cat, $user);
607
608
        return $criteriaCompo;
609
    }
610
611
    // Return the criteria compo object for event occuring on a given year
612
613
    /**
614
     * @param     $year
615
     * @param int $cat
616
     *
617
     * @return \CriteriaCompo
618
     */
619
    public function getEventYearCriteria($year, $cat = 0)
620
    {
621
        $user = $GLOBALS['xoopsUser'];
622
623
        $userStartTime = mktime(0, 0, 0, 1, 1, $year);
624
        $userEndTime   = mktime(23, 59, 59, 12, 31, $year);
625
        $yearStart     = userTimeToServerTime($userStartTime, $this->extcalTime->getUserTimeZone($user));
0 ignored issues
show
Bug introduced by
The function userTimeToServerTime was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

625
        $yearStart     = /** @scrutinizer ignore-call */ userTimeToServerTime($userStartTime, $this->extcalTime->getUserTimeZone($user));
Loading history...
626
        $yearEnd       = userTimeToServerTime($userEndTime, $this->extcalTime->getUserTimeZone($user));
627
        $criteriaCompo = $this->getListCriteriaCompo($yearStart, $yearEnd, $cat, $user);
628
629
        return $criteriaCompo;
630
    }
631
632
    /**********************************************************************
633
     * Debut de - A virer in fine
634
     **********************************************************************/
635
636
    /**********************************************************************
637
     * FIN de  - A virer in fine
638
     **********************************************************************/
639
640
    /**********************************************************************
641
     * Construction des criteres en fonction de la période
642
     *********************************************************************
643
     * @param $start
644
     * @param $end
645
     * @param $cat
646
     * @param $user
647
     * @return \CriteriaCompo
648
     */
649
650
    public function getCriteriaCompo($start, $end, $cat = 0, $user)
651
    {
652
        $criteriaNoRecur = new \CriteriaCompo();
653
        $criteriaNoRecur->add(new \Criteria('event_start', $end, '<='));
654
        $criteriaNoRecur->add(new \Criteria('event_end', $start, '>='));
655
        $criteriaNoRecur->add(new \Criteria('event_isrecur', 0));
656
657
        $criteriaRecur = new \CriteriaCompo();
658
        $criteriaRecur->add(new \Criteria('event_recur_start', $end, '<='));
659
        $criteriaRecur->add(new \Criteria('event_recur_end', $start, '>='));
660
        $criteriaRecur->add(new \Criteria('event_isrecur', 1));
661
662
        $criteriaCompoDate = new \CriteriaCompo();
663
        $criteriaCompoDate->add($criteriaNoRecur, 'OR');
664
        $criteriaCompoDate->add($criteriaRecur, 'OR');
665
666
        $criteriaCompo = new \CriteriaCompo();
667
        $criteriaCompo->add($criteriaCompoDate);
668
669
        $criteriaCompo->add(new \Criteria('event_approved', 1));
670
        $this->addCatSelectCriteria($criteriaCompo, $cat);
671
        $this->addCatPermCriteria($criteriaCompo, $user);
672
        $criteriaCompo->setSort('event_start');
673
674
        return $criteriaCompo;
675
    }
676
677
    /**
678
     * @param     $start
679
     * @param     $end
680
     * @param int $cat
681
     * @param     $user
682
     *
683
     * @return \CriteriaCompo
684
     */
685
    public function getCalendarCriteriaCompo($start, $end, $cat = 0, $user)
686
    {
687
        $criteriaCompo = $this->getCriteriaCompo($start, $end, $cat, $user);
688
        if (!Extcal\Helper::getInstance()->getConfig('diplay_past_event_cal')) {
689
            $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
690
        }
691
692
        return $criteriaCompo;
693
    }
694
695
    /**
696
     * @param     $start
697
     * @param     $end
698
     * @param int $cat
699
     * @param     $user
700
     *
701
     * @return \CriteriaCompo
702
     */
703
    public function getListCriteriaCompo($start, $end, $cat = 0, $user)
704
    {
705
        $criteriaCompo = $this->getCriteriaCompo($start, $end, $cat, $user);
706
        if (!Extcal\Helper::getInstance()->getConfig('diplay_past_event_list')) {
707
            $criteriaCompo->add(new \Criteria('event_end', time(), '>'));
708
        }
709
710
        return $criteriaCompo;
711
    }
712
713
    // Return upcomming event
714
715
    /**
716
     * @param     $nbEvent
717
     * @param int $cat
718
     *
719
     * @return array
720
     */
721
    public function getUpcommingEvent($nbEvent, $cat = 0)
722
    {
723
        $now = time();
724
725
        $criteriaNoRecur = new \CriteriaCompo();
726
        $criteriaNoRecur->add(new \Criteria('event_start', $now, '>='));
727
        $criteriaNoRecur->add(new \Criteria('event_isrecur', 0));
728
729
        $criteriaRecur = new \CriteriaCompo();
730
        $criteriaRecur->add(new \Criteria('event_recur_start', $now, '>='));
731
        $criteriaRecur->add(new \Criteria('event_isrecur', 1));
732
733
        $criteriaCompoDate = new \CriteriaCompo();
734
        $criteriaCompoDate->add($criteriaNoRecur, 'OR');
735
        $criteriaCompoDate->add($criteriaRecur, 'OR');
736
737
        $criteriaCompo = new \CriteriaCompo();
738
        $criteriaCompo->add($criteriaCompoDate);
739
740
        $criteriaCompo->add(new \Criteria('event_approved', 1));
741
        $this->addCatSelectCriteria($criteriaCompo, $cat);
742
        $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
743
744
        //mb ---------- TESTING ---------------------------
745
        //        $eventsU = $this->getEventsUniques($criteriaNoRecur);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
746
        //        $eventsR = $this->getEventsRecurents($criteriaRecur);
0 ignored issues
show
Unused Code Comprehensibility introduced by
59% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
747
        //        $events  = array_merge($eventsU, $eventsR);
0 ignored issues
show
Unused Code Comprehensibility introduced by
54% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
748
749
        //var_dump($events);
750
751
        $criteriaCompo->setSort('event_start');
752
        $criteriaCompo->setLimit($nbEvent);
753
754
        //var_dump($this->getObjects($criteriaCompo));
0 ignored issues
show
Unused Code Comprehensibility introduced by
80% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
755
        //mb -------------------------------------
756
        return $this->getObjects($criteriaCompo);
757
    }
758
759
    // Return event occuring this day
760
761
    /**
762
     * @param     $nbEvent
763
     * @param int $cat
764
     *
765
     * @return array
766
     */
767
    public function getThisDayEvent($nbEvent, $cat = 0)
768
    {
769
        $day   = date('j');
770
        $month = date('n');
771
        $year  = date('Y');
772
773
        $dayStart = mktime(0, 0, 0, $month, $day, $year);
0 ignored issues
show
Bug introduced by
$month of type string is incompatible with the type integer expected by parameter $month of mktime(). ( Ignorable by Annotation )

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

773
        $dayStart = mktime(0, 0, 0, /** @scrutinizer ignore-type */ $month, $day, $year);
Loading history...
Bug introduced by
$day of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

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

773
        $dayStart = mktime(0, 0, 0, $month, /** @scrutinizer ignore-type */ $day, $year);
Loading history...
Bug introduced by
$year of type string is incompatible with the type integer expected by parameter $year of mktime(). ( Ignorable by Annotation )

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

773
        $dayStart = mktime(0, 0, 0, $month, $day, /** @scrutinizer ignore-type */ $year);
Loading history...
774
        $dayEnd   = mktime(0, 0, 0, $month, $day + 1, $year);
775
776
        $criteriaCompo = new \CriteriaCompo();
777
        $this->addCatSelectCriteria($criteriaCompo, $cat);
778
        $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
779
        $criteriaCompo->add(new \Criteria('event_end', $dayStart, '>='));
780
        $criteriaCompo->add(new \Criteria('event_start', $dayEnd, '<'));
781
        $criteriaCompo->add(new \Criteria('event_approved', 1));
782
        $criteriaCompo->setSort('event_start');
783
        $criteriaCompo->setLimit($nbEvent);
784
785
        return $this->getObjects($criteriaCompo);
786
    }
787
788
    // Return last added event
789
790
    /**
791
     * @param      $start
792
     * @param      $limit
793
     * @param int  $cat
794
     * @param bool $skipPerm
795
     *
796
     * @return array
797
     */
798
    public function getNewEvent($start, $limit, $cat = 0, $skipPerm = false)
799
    {
800
        $criteriaCompo = new \CriteriaCompo();
801
        $this->addCatSelectCriteria($criteriaCompo, $cat);
802
        if (!$skipPerm) {
803
            $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
804
        }
805
        $criteriaCompo->add(new \Criteria('event_approved', 1));
806
        $criteriaCompo->setSort('event_id');
807
        $criteriaCompo->setOrder('DESC');
808
        $criteriaCompo->setStart($start);
809
        $criteriaCompo->setLimit($limit);
810
811
        return $this->getObjects($criteriaCompo);
812
    }
813
814
    /**
815
     * @return int
816
     */
817
    public function getCountNewEvent()
818
    {
819
        $criteriaCompo = new \CriteriaCompo();
820
        $this->addCatSelectCriteria($criteriaCompo, 0);
821
        $criteriaCompo->add(new \Criteria('event_approved', 1));
822
        $criteriaCompo->setSort('event_id');
823
824
        return $this->getCount($criteriaCompo);
825
    }
826
827
    // Return random upcomming event
828
829
    /**
830
     * @param     $nbEvent
831
     * @param int $cat
832
     *
833
     * @return array
834
     */
835
    public function getRandomEvent($nbEvent, $cat = 0)
836
    {
837
        $criteriaCompo = new \CriteriaCompo();
838
        $this->addCatSelectCriteria($criteriaCompo, $cat);
839
        $this->addCatPermCriteria($criteriaCompo, $GLOBALS['xoopsUser']);
840
        $criteriaCompo->add(new \Criteria('event_start', time(), '>='));
841
        $criteriaCompo->add(new \Criteria('event_approved', 1));
842
        $criteriaCompo->setSort('RAND()');
843
        $criteriaCompo->setLimit($nbEvent);
844
845
        return $this->getObjects($criteriaCompo);
846
    }
847
848
    /**
849
     * @return array
850
     */
851
    public function getPendingEvent()
852
    {
853
        $criteriaCompo = new \CriteriaCompo();
854
        $criteriaCompo->add(new \Criteria('event_approved', 0));
855
        $criteriaCompo->setSort('event_start');
856
857
        return $this->getObjects($criteriaCompo);
858
    }
859
860
    /**
861
     * @param \CriteriaElement $criteria
862
     * @param $user
863
     */
864
    public function addCatPermCriteria(\CriteriaElement $criteria, $user)
0 ignored issues
show
Bug introduced by
The type CriteriaElement was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
865
    {
866
        $authorizedAccessCats = $this->extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
867
        $count                = count($authorizedAccessCats);
0 ignored issues
show
Bug introduced by
$authorizedAccessCats of type boolean is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

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

867
        $count                = count(/** @scrutinizer ignore-type */ $authorizedAccessCats);
Loading history...
868
        if ($count > 0) {
869
            $in = '(' . $authorizedAccessCats[0];
870
            array_shift($authorizedAccessCats);
0 ignored issues
show
Bug introduced by
$authorizedAccessCats of type boolean is incompatible with the type array expected by parameter $array of array_shift(). ( Ignorable by Annotation )

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

870
            array_shift(/** @scrutinizer ignore-type */ $authorizedAccessCats);
Loading history...
871
            foreach ($authorizedAccessCats as $authorizedAccessCat) {
0 ignored issues
show
Bug introduced by
The expression $authorizedAccessCats of type boolean is not traversable.
Loading history...
872
                $in .= ',' . $authorizedAccessCat;
873
            }
874
            $in .= ')';
875
            $criteria->add(new \Criteria('cat_id', $in, 'IN'));
876
        } else {
877
            $criteria->add(new \Criteria('cat_id', '(0)', 'IN'));
878
        }
879
    }
880
881
    /**
882
     * @param $criteria
883
     * @param $cats
884
     */
885
    public function addCatSelectCriteria(&$criteria, $cats = null)
886
    {
887
        if (!is_array($cats) && $cats > 0) {
888
            $criteria->add(new \Criteria('cat_id', $cats));
889
        }
890
        if (is_array($cats)) {
891
            if (false === array_search(0, $cats)) {
892
                $in = '(' . current($cats);
893
                array_shift($cats);
894
                foreach ($cats as $cat) {
895
                    $in .= ',' . $cat;
896
                }
897
                $in .= ')';
898
                $criteria->add(new \Criteria('cat_id', $in, 'IN'));
899
            }
900
        }
901
    }
902
903
    /**********************************************************************
904
     * formulaire d'edition des evennements*
905
     *********************************************************************
906
     * @param string $siteSide
907
     * @param string $mode
908
     * @param null   $data
0 ignored issues
show
Documentation Bug introduced by
Are you sure the doc-type for parameter $data is correct as it would always require null to be passed?
Loading history...
909
     * @return \XoopsModules\Extcal\Form\ThemeForm
910
     */
911
    public function getEventForm($siteSide = 'user', $mode = 'new', $data = null)
912
    {
913
        global $xoopsModuleConfig;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
914
        $catHandler  = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_CAT);
915
        $fileHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_FILE);
916
917
        /***************************************************/
918
        //        require_once __DIR__ . '/etablissement.php';
0 ignored issues
show
Unused Code Comprehensibility introduced by
45% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
919
        if ('admin' === $siteSide) {
920
            $action = 'event.php?op=enreg';
921
            $cats   = $catHandler->getAllCat($GLOBALS['xoopsUser'], 'all');
922
        } else {
923
            $action = 'post.php';
924
            $cats   = $catHandler->getAllCat($GLOBALS['xoopsUser']);
925
        }
926
        /***************************************************/
927
        $reccurOptions = [];
928
929
        if ('edit' === $mode || 'clone' === $mode) {
930
            if (!$event = $this->getEventWithNotApprove($data['event_id'])) {
931
                return false;
0 ignored issues
show
Bug Best Practice introduced by
The expression return false returns the type false which is incompatible with the documented return type XoopsModules\Extcal\Form\ThemeForm.
Loading history...
932
            }
933
            if ('clone' === $mode) {
934
                $data['event_id'] = 0;
935
                $event->setVar('event_id', 0);
936
                $newTitle = $event->getVar('event_title') . ' (' . _MD_EXTCAL_CLONE_OF . $data['event_id'] . ')';
937
                $event->setVar('event_title', $newTitle);
938
            }
939
940
            $formTitle           = _MD_EXTCAL_EDIT_EVENT;
941
            $formName            = 'modify_event';
0 ignored issues
show
Unused Code introduced by
The assignment to $formName is dead and can be removed.
Loading history...
942
            $title               = $event->getVar('event_title', 'e');
943
            $cat                 = $event->getVar('cat_id');
944
            $desc                = $event->getVar('event_desc', 'e');
945
            $nbMember            = $event->getVar('event_nbmember', 'e');
946
            $organisateur        = $event->getVar('event_organisateur');
947
            $contact             = $event->getVar('event_contact', 'e');
948
            $url                 = $event->getVar('event_url', 'e');
949
            $email               = $event->getVar('event_email', 'e');
950
            $event_address       = $event->getVar('event_address', 'e');
951
            $startDateValue      = xoops_getUserTimestamp($event->getVar('event_start'), $this->extcalTime->getUserTimeZone($GLOBALS['xoopsUser']));
0 ignored issues
show
Bug introduced by
The function xoops_getUserTimestamp was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

951
            $startDateValue      = /** @scrutinizer ignore-call */ xoops_getUserTimestamp($event->getVar('event_start'), $this->extcalTime->getUserTimeZone($GLOBALS['xoopsUser']));
Loading history...
952
            $endDateValue        = xoops_getUserTimestamp($event->getVar('event_end'), $this->extcalTime->getUserTimeZone($GLOBALS['xoopsUser']));
953
            $event_picture1      = $event->getVar('event_picture1');
954
            $event_picture2      = $event->getVar('event_picture2');
955
            $event_price         = $event->getVar('event_price');
956
            $event_etablissement = $event->getVar('event_etablissement');
957
            $event_icone         = $event->getVar('event_icone');
958
959
            // Configuring recurring form
960
            $eventOptions = explode('|', $event->getVar('event_recur_rules'));
961
            $reccurMode   = $eventOptions[0];
962
            array_shift($eventOptions);
963
            switch ($reccurMode) {
964
965
                case 'daily':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
966
967
                    $reccurOptions['rrule_freq']           = 'daily';
968
                    $reccurOptions['rrule_daily_interval'] = $eventOptions[0];
969
970
                    break;
971
972
                case 'weekly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
973
974
                    $reccurOptions['rrule_freq']            = 'weekly';
975
                    $reccurOptions['rrule_weekly_interval'] = $eventOptions[0];
976
                    array_shift($eventOptions);
977
                    $reccurOptions['rrule_weekly_bydays'] = $eventOptions;
978
979
                    break;
980
981
                case 'monthly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
982
983
                    $reccurOptions['rrule_freq']             = 'monthly';
984
                    $reccurOptions['rrule_monthly_interval'] = $eventOptions[0];
985
                    array_shift($eventOptions);
986
                    if (0 !== strpos($eventOptions[0], 'MD')) {
987
                        $reccurOptions['rrule_monthly_byday'] = $eventOptions[0];
988
                    } else {
989
                        $reccurOptions['rrule_bymonthday'] = substr($eventOptions[0], 2);
990
                    }
991
992
                    break;
993
994
                case 'yearly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
995
996
                    $reccurOptions['rrule_freq']            = 'yearly';
997
                    $reccurOptions['rrule_yearly_interval'] = $eventOptions[0];
998
                    array_shift($eventOptions);
999
                    $reccurOptions['rrule_yearly_byday'] = $eventOptions[0];
1000
                    array_shift($eventOptions);
1001
                    $reccurOptions['rrule_yearly_bymonths'] = $eventOptions;
1002
1003
                    break;
1004
1005
            }
1006
1007
            $files = $fileHandler->objectToArray($fileHandler->getEventFiles($data['event_id']));
1008
            $fileHandler->formatFilesSize($files);
1009
        } elseif ('preview' === $mode) {
1010
            $formTitle           = _MD_EXTCAL_SUBMIT_EVENT;
1011
            $formName            = 'submit_event';
1012
            $title               = $data['event_title'];
1013
            $cat                 = $data['cat_id'];
1014
            $desc                = $data['event_desc'];
1015
            $nbMember            = $data['event_nbmember'];
1016
            $organisateur        = $data['event_organisateur'];
1017
            $contact             = $data['event_contact'];
1018
            $url                 = $data['event_url'];
1019
            $email               = $data['event_email'];
1020
            $event_address       = $data['event_address'];
1021
            $startDateValue      = $data['event_start'];
1022
            $endDateValue        = $data['event_end'];
1023
            $eventEndOk          = $data['have_end'];
0 ignored issues
show
Unused Code introduced by
The assignment to $eventEndOk is dead and can be removed.
Loading history...
1024
            $event_picture1      = $data['event_picture1'];
1025
            $event_picture2      = $data['event_picture2'];
1026
            $event_price         = $data['event_price'];
1027
            $event_etablissement = $data['event_etablissement'];
1028
            $event_icone         = $data['event_icone'];
1029
1030
            // Configuring recurring form
1031
            $eventOptions = explode('|', $this->getRecurRules($_POST));
1032
            $reccurMode   = $eventOptions[0];
1033
            array_shift($eventOptions);
1034
            switch ($reccurMode) {
1035
1036
                case 'daily':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1037
1038
                    $reccurOptions['rrule_freq']           = 'daily';
1039
                    $reccurOptions['rrule_daily_interval'] = $eventOptions[0];
1040
1041
                    break;
1042
1043
                case 'weekly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1044
1045
                    $reccurOptions['rrule_freq']            = 'weekly';
1046
                    $reccurOptions['rrule_weekly_interval'] = $eventOptions[0];
1047
                    array_shift($eventOptions);
1048
                    $reccurOptions['rrule_weekly_bydays'] = $eventOptions;
1049
1050
                    break;
1051
1052
                case 'monthly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1053
1054
                    $reccurOptions['rrule_freq']             = 'monthly';
1055
                    $reccurOptions['rrule_monthly_interval'] = $eventOptions[0];
1056
                    array_shift($eventOptions);
1057
                    if (0 !== strpos($eventOptions[0], 'MD')) {
1058
                        $reccurOptions['rrule_monthly_byday'] = $eventOptions[0];
1059
                    } else {
1060
                        $reccurOptions['rrule_bymonthday'] = substr($eventOptions[0], 2);
1061
                    }
1062
1063
                    break;
1064
1065
                case 'yearly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1066
1067
                    $reccurOptions['rrule_freq']            = 'yearly';
1068
                    $reccurOptions['rrule_yearly_interval'] = $eventOptions[0];
1069
                    array_shift($eventOptions);
1070
                    $reccurOptions['rrule_yearly_byday'] = $eventOptions[0];
1071
                    array_shift($eventOptions);
1072
                    $reccurOptions['rrule_yearly_bymonths'] = $eventOptions;
1073
1074
                    break;
1075
1076
            }
1077
1078
            $files = $fileHandler->objectToArray($fileHandler->getEventFiles($data['event_id']));
1079
            $fileHandler->formatFilesSize($files);
1080
        } else {
1081
            $formTitle           = _MD_EXTCAL_SUBMIT_EVENT;
1082
            $formName            = 'submit_event';
1083
            $title               = '';
1084
            $cat                 = '';
1085
            $desc                = '';
1086
            $nbMember            = 0;
1087
            $organisateur        = '';
1088
            $contact             = '';
1089
            $url                 = '';
1090
            $email               = '';
1091
            $event_address       = '';
1092
            $startDateValue      = 0;
1093
            $endDateValue        = 0;
1094
            $eventEndOk          = 0;
1095
            $event_picture1      = '';
1096
            $event_picture2      = '';
1097
            $event_price         = '';
1098
            $event_etablissement = '';
1099
            $files               = [];
1100
            $event_icone         = '';
1101
        }
1102
1103
        // Create XoopsForm Object
1104
        $form = new Extcal\Form\ThemeForm($formTitle, 'event_form', $action, 'post', true);
1105
        // Add this extra to allow file upload
1106
        $form->setExtra('enctype="multipart/form-data"');
1107
1108
        //-----------------------------------------------
1109
        // Title
1110
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_TITLE, 'event_title', 80, 255, $title), true);
0 ignored issues
show
Bug introduced by
The type XoopsFormText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1111
        //-----------------------------------------------
1112
        // Category select
1113
        $catSelect = new \XoopsFormSelect(_MD_EXTCAL_CATEGORY, 'cat_id', $cat);
0 ignored issues
show
Bug introduced by
The type XoopsFormSelect was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1114
        foreach ($cats as $cat) {
1115
            $catSelect->addOption($cat->getVar('cat_id'), $cat->getVar('cat_name'));
1116
        }
1117
        $form->addElement($catSelect, true);
1118
        //-----------------------------------------------------------
1119
1120
        $file_path = __DIR__ . '/../assets/css/images';
1121
        $tf        = \XoopsLists::getImgListAsArray($file_path);
0 ignored issues
show
Bug introduced by
The type XoopsLists was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1122
        array_unshift($tf, _MD_EXTCAL_NONE);
1123
        $xfIcones = new \XoopsFormSelect(_MD_EXTCAL_ICONE, 'event_icone', $event_icone, '');
1124
        $xfIcones->addOptionArray($tf);
1125
        $form->addElement($xfIcones, false);
1126
        //-----------------------------------------------------------
1127
        //etablissement
1128
        $etablissementHandler = Extcal\Helper::getInstance()->getHandler(_EXTCAL_CLN_ETABLISSEMENT);
1129
        $etablissement_select = new \XoopsFormSelect(_MD_EXTCAL_ETABLISSEMENT, 'event_etablissement', $event_etablissement);
1130
        $criteria             = new \CriteriaCompo();
1131
        $criteria->setSort('nom');
1132
        $criteria->setOrder('ASC');
1133
1134
        //$lstEtablissement = $etablissementHandler->getList($criteria);
0 ignored issues
show
Unused Code Comprehensibility introduced by
64% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1135
        $etablissement_arr = $etablissementHandler->getAll($criteria);
1136
        $tEts              = [];
1137
        $tEts[0]           = _MD_EXTCAL_NONE;
1138
        foreach (array_keys($etablissement_arr) as $i) {
1139
            $tEts[$etablissement_arr[$i]->getVar('id')] = $etablissement_arr[$i]->getVar('nom');
1140
            //            $tEts[$etablissement_arr[$i]['id']] = $etablissement_arr[$i]['nom'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
82% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1141
        }
1142
        //array_unshift($tEts, _MD_EXTCAL_NONE);
0 ignored issues
show
Unused Code Comprehensibility introduced by
63% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1143
1144
        $etablissement_select->addOptionArray($tEts);
1145
        $form->addElement($etablissement_select, true);
1146
1147
        //-----------------------------------------------------------
1148
1149
        // Start and end
1150
        new Extcal\Form\FormDateTime($form, $startDateValue, $endDateValue); //mb
1151
1152
        global $xoopsUser, $xoopsModule;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
1153
        $isAdmin = false;
1154
        if (is_object($xoopsUser)) {
1155
            $isAdmin = $xoopsUser->isAdmin($xoopsModule->getVar('mid'));
1156
        }
1157
1158
        // Description
1159
        if (class_exists('XoopsFormEditor')) {
1160
            $options['name']   = 'event_desc';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$options was never initialized. Although not strictly required by PHP, it is generally a good practice to add $options = array(); before regardless.
Loading history...
1161
            $options['value']  = $desc;
1162
            $options['rows']   = 5;
1163
            $options['cols']   = '100%';
1164
            $options['width']  = '100%';
1165
            $options['height'] = '200px';
1166
            if ($isAdmin) {
1167
                $descEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
0 ignored issues
show
Bug introduced by
The type XoopsFormEditor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1168
            } else {
1169
                $descEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
1170
            }
1171
        } else {
1172
            $descEditor = new \XoopsFormDhtmlTextArea(_MD_EXTCAL_DESCRIPTION, 'event_desc', $desc, '100%', '100%');
0 ignored issues
show
Bug introduced by
The type XoopsFormDhtmlTextArea was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1173
        }
1174
        $form->addElement($descEditor);
1175
1176
        // Max registered member for this event
1177
        $nbMemberElement = new \XoopsFormText(_MD_EXTCAL_NBMEMBER, 'event_nbmember', 4, 4, $nbMember);
1178
        $nbMemberElement->setDescription(_MD_EXTCAL_NBMEMBER_DESC);
1179
        $form->addElement($nbMemberElement, false);
1180
1181
        //Price and monnaie
1182
        $monnaie_price = new \XoopsFormElementTray(_MD_EXTCAL_PRICE, '');
0 ignored issues
show
Bug introduced by
The type XoopsFormElementTray was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1183
        //price
1184
        $monnaie_price->addElement(new \XoopsFormText('', 'event_price', 20, 255, $event_price));
1185
        //monnaie
1186
        $monnaie = new \XoopsFormLabel(_MD_EXTCAL_DEVISE2, '');
0 ignored issues
show
Bug introduced by
The type XoopsFormLabel was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1187
        $monnaie_price->addElement($monnaie);
1188
        $form->addElement($monnaie_price);
1189
        //----------------------------------------------------------------
1190
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_ORGANISATEUR, 'event_organisateur', 80, 255, $organisateur), false);
1191
        // Contact
1192
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_CONTACT, 'event_contact', 80, 255, $contact), false);
1193
        // Url
1194
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_URL, 'event_url', 80, 255, $url), false);
1195
        // Email
1196
        $form->addElement(new \XoopsFormText(_MD_EXTCAL_EMAIL, 'event_email', 80, 255, $email), false);
1197
1198
        // Address
1199
        if (class_exists('XoopsFormEditor')) {
1200
            $options['name']   = 'event_address';
1201
            $options['value']  = $event_address;
1202
            $options['rows']   = 5;
1203
            $options['cols']   = '100%';
1204
            $options['width']  = '100%';
1205
            $options['height'] = '200px';
1206
            if ($isAdmin) {
1207
                $addressEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorAdmin'], $options, $nohtml = false, $onfailure = 'textarea');
1208
            } else {
1209
                $addressEditor = new \XoopsFormEditor(_MD_EXTCAL_DESCRIPTION, $xoopsModuleConfig['editorUser'], $options, $nohtml = false, $onfailure = 'textarea');
1210
            }
1211
        } else {
1212
            $addressEditor = new \XoopsFormDhtmlTextArea(_MD_EXTCAL_DESCRIPTION, 'event_address', $event_address, '100%', '100%');
1213
        }
1214
        $form->addElement($addressEditor);
1215
1216
        // Recurence form
1217
        $form->addElement(new Extcal\Form\FormRecurRules($reccurOptions));
1218
        // File attachement
1219
        $fileElmtTray = new \XoopsFormElementTray(_MD_EXTCAL_FILE_ATTACHEMENT, '<br>');
1220
1221
        // If they are attached file to this event
1222
        if (count($files) > 0) {
1223
            $eventFiles = new Extcal\Form\FormFileCheckBox('', 'filetokeep');
1224
            foreach ($files as $file) {
1225
                $name = $file['file_nicename'] . ' (<i>' . $file['file_mimetype'] . '</i>) ' . $file['formated_file_size'];
1226
                $eventFiles->addOption($file['file_id'], $name);
1227
            }
1228
            $fileElmtTray->addElement($eventFiles);
1229
        }
1230
        $fileElmtTray->addElement(new \XoopsFormFile(_MD_EXTCAL_FILE_ATTACHEMENT, 'event_file', 3145728));
0 ignored issues
show
Bug introduced by
The type XoopsFormFile was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1231
        $form->addElement($fileElmtTray);
1232
1233
        if (isset($data['event_id'])) {
1234
            $form->addElement(new \XoopsFormHidden('event_id', $data['event_id']), false);
0 ignored issues
show
Bug introduced by
The type XoopsFormHidden was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1235
        }
1236
        //Hack Kraven0
1237
        ///////////////////////////////////////////////////////////////////////////////
1238
        //Picture1
1239
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 1), '');
1240
        if (!empty($event_picture1)) {
1241
            $file_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/' . $event_picture1 . "' name='image' id='image' alt=''><br><br>"));
0 ignored issues
show
Bug introduced by
The constant XoopsModules\Extcal\XOOPS_URL was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1242
            $check_del_img = new \XoopsFormCheckBox('', 'delimg_1');
0 ignored issues
show
Bug introduced by
The type XoopsFormCheckBox was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
1243
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
1244
            $file_tray->addElement($check_del_img);
1245
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage1', 2145728);
1246
            unset($check_del_img);
1247
        } else {
1248
            $file_img = new \XoopsFormFile('', 'attachedimage1', 2145728);
1249
        }
1250
        $file_img->setExtra("size ='40'");
1251
        $file_tray->addElement($file_img);
1252
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(400728 / 1000), 500, 500);
1253
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
1254
        $file_tray->addElement($file_label);
1255
        $form->addElement($file_tray);
1256
        $form->addElement(new \XoopsFormHidden('file1', $event_picture1));
1257
        unset($file_img, $file_tray);
1258
        //Picture2
1259
        $file_tray = new \XoopsFormElementTray(sprintf(_MD_EXTCAL_FORM_IMG, 2), '');
1260
        if (!empty($event_picture2)) {
1261
            $file_tray->addElement(new \XoopsFormLabel('', "<img src='" . XOOPS_URL . '/uploads/extcal/' . $event_picture2 . "' name='image' id='image' alt=''><br><br>"));
1262
            $check_del_img = new \XoopsFormCheckBox('', 'delimg_2');
1263
            $check_del_img->addOption(1, _MD_EXTCAL_DEL_IMG);
1264
            $file_tray->addElement($check_del_img);
1265
            $file_img = new \XoopsFormFile(_MD_EXTCAL_IMG, 'attachedimage2', 2145728);
1266
            unset($check_del_img);
1267
        } else {
1268
            $file_img = new \XoopsFormFile('', 'attachedimage2', 2145728);
1269
        }
1270
        $file_img->setExtra("size ='40'");
1271
        $file_tray->addElement($file_img);
1272
        $msg        = sprintf(_MD_EXTCAL_IMG_CONFIG, (int)(400728 / 1000), 500, 500);
1273
        $file_label = new \XoopsFormLabel('', '<br>' . $msg);
1274
        $file_tray->addElement($file_label);
1275
        $form->addElement($file_tray);
1276
        $form->addElement(new \XoopsFormHidden('file2', $event_picture2));
1277
        unset($file_img, $file_tray);
1278
        ///////////////////////////////////////////////////////////////////////////////
1279
1280
        $buttonElmtTray = new \XoopsFormElementTray('', '&nbsp;');
1281
        $buttonElmtTray->addElement(new \XoopsFormButton('', 'form_submit', _SUBMIT, 'submit'), false);
0 ignored issues
show
Bug introduced by
The type XoopsFormButton was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
Bug introduced by
The constant XoopsModules\Extcal\_SUBMIT was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
1282
        if ('user' === $siteSide) {
1283
            $buttonElmtTray->addElement(new \XoopsFormButton('', 'form_preview', _MD_EXTCAL_PREVIEW, 'submit'), false);
1284
        }
1285
        $form->addElement($buttonElmtTray);
1286
1287
        return $form;
1288
    }
1289
1290
    /********************************************************************/
1291
1292
    /**
1293
     * @param $parm
1294
     *
1295
     * @return bool
1296
     */
1297
    public function getIsRecur($parm)
1298
    {
1299
        $recurFreq = ['daily', 'weekly', 'monthly', 'yearly'];
1300
1301
        return in_array($parm['rrule_freq'], $recurFreq);
1302
    }
1303
1304
    /**
1305
     * @param $parm
1306
     *
1307
     * @return string
1308
     */
1309
    public function getRecurRules($parm)
1310
    {
1311
        //Extcal\Utility::echoArray($parm);exit;
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1312
1313
        // If this isn't a reccuring event
1314
        if (!$this->getIsRecur($parm)) {
1315
            return '';
1316
        }
1317
1318
        $recurRules = '';
1319
1320
        $recurFreq = $parm['rrule_freq'];
1321
1322
        switch ($recurFreq) {
1323
1324
            case 'daily':
1325
                if (!isset($parm['rrule_daily_interval'])) {
1326
                    $parm['rrule_daily_interval'] = 0;
1327
                }
1328
                $recurRules = 'daily|';
1329
                $recurRules .= $parm['rrule_daily_interval'];
1330
1331
                break;
1332
1333
            case 'weekly':
1334
                if (!isset($parm['rrule_weekly_interval'])) {
1335
                    $parm['rrule_weekly_interval'] = 0;
1336
                }
1337
                $recurRules = 'weekly|';
1338
                $recurRules .= $parm['rrule_weekly_interval'];
1339
                foreach ($parm['rrule_weekly_bydays'] as $day) {
1340
                    $recurRules .= '|' . $day;
1341
                }
1342
1343
                break;
1344
1345
            case 'monthly':
1346
                if (!isset($parm['rrule_monthly_interval'])) {
1347
                    $parm['rrule_monthly_interval'] = 0;
1348
                }
1349
                $recurRules = 'monthly|';
1350
                $recurRules .= $parm['rrule_monthly_interval'] . '|';
1351
                if ('' != $parm['rrule_monthly_byday']) {
1352
                    $recurRules .= $parm['rrule_monthly_byday'];
1353
                } else {
1354
                    $recurRules .= 'MD' . $parm['rrule_bymonthday'];
1355
                }
1356
1357
                break;
1358
1359
            case 'yearly':
1360
                //JJD - to valid modif
1361
                //
1362
                //                 if ($parm['rrule_yearly_byday'] == "") {
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1363
                //                     list($year, $month, $day) = explode("-", $parm['event_start']['date']);
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1364
                //                     $parm['rrule_yearly_byday'] = date("j", mktime(0, 0, 0, $month, $day, $year));
0 ignored issues
show
Unused Code Comprehensibility introduced by
65% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1365
                //                 }
1366
                //
1367
                //                 $recurRules = 'yearly|';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1368
                //                 $recurRules .= $parm['rrule_yearly_interval'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
55% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1369
                //                 $recurRules .= '|' . $parm['rrule_yearly_byday'];
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1370
                //                 foreach (
1371
                //                     $parm['rrule_yearly_bymonths'] as $month
0 ignored issues
show
Unused Code Comprehensibility introduced by
67% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
1372
                //) {
1373
                //                     $recurRules .= '|' . $month;
1374
                //                 }
1375
                //
1376
                //                 break;
1377
1378
                if (!isset($parm['rrule_yearly_interval'])) {
1379
                    $parm['rrule_yearly_interval'] = 0;
1380
                }
1381
                if ('' == $parm['rrule_yearly_byday']) {
1382
                    $time                       = strtotime($parm['event_start']['date']);
1383
                    $parm['rrule_yearly_byday'] = date('j', mktime(0, 0, 0, date('m', $time), date('d', $time), date('Y', $time)));
0 ignored issues
show
Bug introduced by
date('Y', $time) of type string is incompatible with the type integer expected by parameter $year of mktime(). ( Ignorable by Annotation )

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

1383
                    $parm['rrule_yearly_byday'] = date('j', mktime(0, 0, 0, date('m', $time), date('d', $time), /** @scrutinizer ignore-type */ date('Y', $time)));
Loading history...
Bug introduced by
date('d', $time) of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

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

1383
                    $parm['rrule_yearly_byday'] = date('j', mktime(0, 0, 0, date('m', $time), /** @scrutinizer ignore-type */ date('d', $time), date('Y', $time)));
Loading history...
Bug introduced by
date('m', $time) of type string is incompatible with the type integer expected by parameter $month of mktime(). ( Ignorable by Annotation )

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

1383
                    $parm['rrule_yearly_byday'] = date('j', mktime(0, 0, 0, /** @scrutinizer ignore-type */ date('m', $time), date('d', $time), date('Y', $time)));
Loading history...
1384
                }
1385
1386
                $recurRules = 'yearly|';
1387
                $recurRules .= $parm['rrule_yearly_interval'];
1388
                $recurRules .= '|' . $parm['rrule_yearly_byday'];
1389
                foreach ($parm['rrule_yearly_bymonths'] as $month) {
1390
                    $recurRules .= '|' . $month;
1391
                }
1392
1393
                break;
1394
1395
        }
1396
1397
        return $recurRules;
1398
    }
1399
1400
    /**
1401
     * @param $data
1402
     * @param $parm
1403
     *
1404
     * @return int
1405
     */
1406
    public function getRecurStart($data, $parm)
1407
    {
1408
1409
        // If this isn't a reccuring event
1410
        if (!$this->getIsRecur($parm)) {
1411
            return 0;
1412
        }
1413
1414
        return $data['event_start'];
1415
    }
1416
1417
    /**
1418
     * @param $data
1419
     * @param $parm
1420
     *
1421
     * @return int
1422
     */
1423
    public function getRecurEnd($data, $parm)
1424
    {
1425
        if (!$this->getIsRecur($parm)) {
1426
            return 0;
1427
        }
1428
1429
        $recurFreq = $parm['rrule_freq'];
1430
1431
        $recurStart = $this->getRecurStart($data, $parm);
1432
1433
        switch ($recurFreq) {
1434
1435
            case 'daily':
1436
                $interval = $parm['rrule_daily_interval'];
1437
                $recurEnd = $recurStart + ($interval * _EXTCAL_TS_DAY) - 1;
1438
1439
                break;
1440
1441
            case 'weekly':
1442
                  // Getting the first weekday TS
1443
                $startWeekTS = mktime(0, 0, 0, date('n', $data['event_recur_start']), date('j', $data['event_recur_start']), date('Y', $data['event_recur_start']));
0 ignored issues
show
Bug introduced by
date('j', $data['event_recur_start']) of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

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

1443
                $startWeekTS = mktime(0, 0, 0, date('n', $data['event_recur_start']), /** @scrutinizer ignore-type */ date('j', $data['event_recur_start']), date('Y', $data['event_recur_start']));
Loading history...
Bug introduced by
date('Y', $data['event_recur_start']) of type string is incompatible with the type integer expected by parameter $year of mktime(). ( Ignorable by Annotation )

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

1443
                $startWeekTS = mktime(0, 0, 0, date('n', $data['event_recur_start']), date('j', $data['event_recur_start']), /** @scrutinizer ignore-type */ date('Y', $data['event_recur_start']));
Loading history...
Bug introduced by
date('n', $data['event_recur_start']) of type string is incompatible with the type integer expected by parameter $month of mktime(). ( Ignorable by Annotation )

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

1443
                $startWeekTS = mktime(0, 0, 0, /** @scrutinizer ignore-type */ date('n', $data['event_recur_start']), date('j', $data['event_recur_start']), date('Y', $data['event_recur_start']));
Loading history...
1444
                $offset      = date('w', $startWeekTS) - Extcal\Helper::getInstance()->getConfig('week_start_day');
1445
                $startWeekTS -= ($offset * _EXTCAL_TS_DAY);
1446
1447
                $recurEnd = $startWeekTS + ($parm['rrule_weekly_interval'] * _EXTCAL_TS_WEEK) - 1;
1448
1449
                break;
1450
1451
            case 'monthly':
1452
                $recurEnd = $recurStart + ($parm['rrule_monthly_interval'] * 2678400) - 1;
1453
1454
                break;
1455
1456
            case 'yearly':
1457
                $recurEnd = $recurStart + ($parm['rrule_yearly_interval'] * 32140800) - 1;
1458
1459
                break;
1460
1461
        }
1462
1463
        return $recurEnd;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $recurEnd does not seem to be defined for all execution paths leading up to this point.
Loading history...
1464
    }
1465
1466
    /*******************************************************************
1467
     *
1468
     ******************************************************************
1469
     * @param $event
1470
     * @param $periodStart
1471
     * @param $periodEnd
1472
     * @return array
1473
     */
1474
    public function getRecurEventToDisplay($event, $periodStart, $periodEnd)
1475
    {
1476
1477
        $recuEvents   = [];
1478
        $eventOptions = explode('|', $event['event_recur_rules']);
1479
1480
        switch ($eventOptions[0]) {
1481
1482
            case 'daily':
1483
                array_shift($eventOptions);
1484
                $rRuleInterval = $eventOptions[0];
1485
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1486
                    $rRuleInterval = 54;
1487
                }
1488
1489
                $occurEventStart = $event['event_recur_start'];
1490
                $occurEventEnd   = $event['event_recur_start'] + ($event['event_end'] - $event['event_start']);
1491
1492
                $nbOccur = 0;
1493
                // This variable is used to stop the loop after we add all occur on the view to keep good performance
1494
                $isOccurOnPeriod = false;
1495
                // Parse all occurence of this event
1496
                while ($nbOccur < $rRuleInterval) {
1497
                    // Add this event occurence only if it's on the period view
1498
                    if // Event start falls within search period
1499
                    ($occurEventStart <= $periodEnd
1500
                     && // Event end falls within search period
1501
                     $occurEventEnd >= $periodStart) {
1502
                        $event['event_start'] = $occurEventStart;
1503
                        $event['event_end']   = $occurEventEnd;
1504
1505
                        $recuEvents[]    = $event;
1506
                        $isOccurOnPeriod = true;
1507
                    } elseif ($isOccurOnPeriod) {
1508
                        break;
1509
                    }
1510
1511
                    $occurEventStart += _EXTCAL_TS_DAY;
1512
                    $occurEventEnd   += _EXTCAL_TS_DAY;
1513
1514
                    ++$nbOccur;
1515
                }
1516
1517
                break;
1518
1519
            case 'weekly':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1520
1521
                array_shift($eventOptions);
1522
                $rRuleInterval = $eventOptions[0];
1523
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1524
                    $rRuleInterval = 54;
1525
                }
1526
                array_shift($eventOptions);
1527
1528
                // Getting the first weekday TS
1529
                $startWeekTS = mktime(0, 0, 0, date('n', $event['event_recur_start']), date('j', $event['event_recur_start']), date('Y', $event['event_recur_start']));
0 ignored issues
show
Bug introduced by
date('Y', $event['event_recur_start']) of type string is incompatible with the type integer expected by parameter $year of mktime(). ( Ignorable by Annotation )

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

1529
                $startWeekTS = mktime(0, 0, 0, date('n', $event['event_recur_start']), date('j', $event['event_recur_start']), /** @scrutinizer ignore-type */ date('Y', $event['event_recur_start']));
Loading history...
Bug introduced by
date('n', $event['event_recur_start']) of type string is incompatible with the type integer expected by parameter $month of mktime(). ( Ignorable by Annotation )

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

1529
                $startWeekTS = mktime(0, 0, 0, /** @scrutinizer ignore-type */ date('n', $event['event_recur_start']), date('j', $event['event_recur_start']), date('Y', $event['event_recur_start']));
Loading history...
Bug introduced by
date('j', $event['event_recur_start']) of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

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

1529
                $startWeekTS = mktime(0, 0, 0, date('n', $event['event_recur_start']), /** @scrutinizer ignore-type */ date('j', $event['event_recur_start']), date('Y', $event['event_recur_start']));
Loading history...
1530
                $offset      = date('w', $startWeekTS) - Extcal\Helper::getInstance()->getConfig('week_start_day');
1531
                $startWeekTS = $startWeekTS - ($offset * _EXTCAL_TS_DAY) + _EXTCAL_TS_WEEK;
1532
1533
                $occurEventStart = $event['event_recur_start'];
1534
                $occurEventEnd   = $event['event_recur_start'] + ($event['event_end'] - $event['event_start']);
1535
1536
                $dayArray = ['SU', 'MO', 'TU', 'WE', 'TH', 'FR', 'SA'];
1537
1538
                $nbOccur = 0;
1539
1540
                // Parse all occurence of this event
1541
                while ($nbOccur < $rRuleInterval) {
1542
                    // Add this event occurence only if it's on the period view and according to day
1543
                    if ($occurEventStart <= $periodEnd // Event start falls within search period
1544
                        && $occurEventEnd >= $periodStart // Event end falls within search period
1545
                        && in_array($dayArray[date('w', $occurEventStart)], $eventOptions)) {
1546
                        // This week day is selected
1547
1548
                        $event['event_start'] = $occurEventStart;
1549
                        $event['event_end']   = $occurEventEnd;
1550
1551
                        $recuEvents[] = $event;
1552
                    }
1553
1554
                    $occurEventStart += _EXTCAL_TS_DAY;
1555
                    $occurEventEnd   += _EXTCAL_TS_DAY;
1556
1557
                    if ($occurEventStart >= $startWeekTS) {
1558
                        ++$nbOccur;
1559
                        $startWeekTS += _EXTCAL_TS_WEEK;
1560
                    }
1561
                }
1562
1563
                break;
1564
1565
            case 'monthly':
1566
                array_shift($eventOptions);
1567
                $rRuleInterval = $eventOptions[0];
1568
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1569
                    $rRuleInterval = 100;
1570
                }
1571
                array_shift($eventOptions);
1572
1573
                $day   = date('j', $event['event_recur_start']);
1574
                $month = date('n', $event['event_recur_start']);
1575
                $year  = date('Y', $event['event_recur_start']);
1576
1577
                $nbOccur = 0;
1578
1579
                $eventHourOccurStart = $event['event_recur_start'] - mktime(0, 0, 0, $month, $day, $year);
1580
                $eventHourOccurEnd   = $event['event_end'] - $event['event_start'];
1581
1582
                // Parse all occurence of this event
1583
                while ($nbOccur < $rRuleInterval) {
1584
                    $eventDayOccurStart = $this->_getOccurTS($month, $year, $eventOptions[0]);
1585
                    if (!$eventDayOccurStart) {
1586
                        $eventDayOccurStart = mktime(0, 0, 0, $month, $day, $year);
1587
                    }
1588
1589
                    $occurEventStart = $eventDayOccurStart + $eventHourOccurStart;
1590
                    $occurEventEnd   = $occurEventStart + $eventHourOccurEnd;
1591
1592
                    if // Event start falls within search period
1593
                    ($occurEventStart <= $periodEnd
1594
                     && // Event end falls within search period
1595
                     $occurEventEnd >= $periodStart
1596
                     && // This occur is after start reccur date
1597
                     $occurEventStart >= $event['event_recur_start']) {
1598
                        $event['event_start'] = $occurEventStart;
1599
                        $event['event_end']   = $occurEventEnd;
1600
1601
                        $recuEvents[] = $event;
1602
                    } elseif ($occurEventStart > $periodEnd) {
1603
                        break;
1604
                    }
1605
1606
                    if (13 == ++$month) {
1607
                        $month = 1;
1608
                        ++$year;
1609
                    }
1610
1611
                    ++$nbOccur;
1612
                }
1613
1614
                break;
1615
1616
            case 'yearly':
1617
                array_shift($eventOptions);
1618
                $rRuleInterval = $eventOptions[0];
1619
                if ('' == $rRuleInterval || 0 == $rRuleInterval) {
1620
                    $rRuleInterval = 10;
1621
                }
1622
                array_shift($eventOptions);
1623
                $dayCode = $eventOptions[0];
1624
                array_shift($eventOptions);
1625
1626
                $day   = date('j', $event['event_recur_start']);
1627
                $month = date('n', $event['event_recur_start']);
1628
                $year  = date('Y', $event['event_recur_start']);
1629
1630
                $nbOccur = 0;
1631
1632
                $eventHourOccurStart = $event['event_recur_start'] - mktime(0, 0, 0, $month, $day, $year);
1633
                $eventHourOccurEnd   = $event['event_end'] - $event['event_start'];
1634
1635
                // If recurring month not specified, make it starting month
1636
                if (!count($eventOptions)) {
1637
                    $eventOptions[] = $month;
1638
                }
1639
1640
                // Parse all occurence of this event
1641
                while ($nbOccur < $rRuleInterval) {
1642
                    $eventDayOccurStart = $this->_getOccurTS($month, $year, $dayCode);
1643
                    if (!$eventDayOccurStart) {
1644
                        $eventDayOccurStart = mktime(0, 0, 0, $month, $day, $year);
1645
                    }
1646
1647
                    $occurEventStart = $eventDayOccurStart + $eventHourOccurStart;
1648
                    $occurEventEnd   = $eventDayOccurStart + $eventHourOccurEnd;
1649
1650
                    if // Event start falls within search period
1651
                    (($occurEventStart <= $periodEnd)
1652
                     && // Event end falls within search period
1653
                     ($occurEventEnd >= $periodStart)
1654
                     && // This week day is selected
1655
                     in_array($month, $eventOptions)) {
1656
                        $event['event_start'] = $occurEventStart;
1657
                        $event['event_end']   = $occurEventEnd;
1658
1659
                        $recuEvents[] = $event;
1660
                    } elseif ($occurEventStart > $periodEnd) {
1661
                        break;
1662
                    }
1663
1664
                    if (13 == ++$month) {
1665
                        $month = 1;
1666
                        ++$year;
1667
                        ++$nbOccur;
1668
                    }
1669
                }
1670
1671
                break;
1672
1673
        }
1674
1675
        return $recuEvents;
1676
    }
1677
1678
    //-----------------------------------------------------------------
1679
1680
    /**
1681
     * @param $month
1682
     * @param $year
1683
     * @param $dayCode
1684
     *
1685
     * @return int
1686
     */
1687
    public function getOccurTS($month, $year, $dayCode)
1688
    {
1689
        if (0 === strpos($dayCode, 'MD')) {
1690
            if ('' != substr($dayCode, 2)) {
1691
                return mktime(0, 0, 0, $month, substr($dayCode, 2), $year);
0 ignored issues
show
Bug introduced by
substr($dayCode, 2) of type string is incompatible with the type integer expected by parameter $day of mktime(). ( Ignorable by Annotation )

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

1691
                return mktime(0, 0, 0, $month, /** @scrutinizer ignore-type */ substr($dayCode, 2), $year);
Loading history...
1692
            } else {
1693
                return 0;
1694
            }
1695
        } else {
1696
            switch ($dayCode) {
1697
1698
                case '1SU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1699
1700
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1701
                    $dayOfWeek = date('w', $ts);
1702
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1703
                    $i         = 0;
1704
                    while (0 != $dayOfWeek % 7) {
1705
                        ++$dayOfWeek;
1706
                        ++$i;
1707
                    }
1708
1709
                    return $ts + (_EXTCAL_TS_DAY * $i);
1710
1711
                    break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
1712
1713
                case '1MO':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1714
1715
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1716
                    $dayOfWeek = date('w', $ts);
1717
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1718
                    $i         = 0;
1719
                    while (1 != $dayOfWeek % 7) {
1720
                        ++$dayOfWeek;
1721
                        ++$i;
1722
                    }
1723
1724
                    return $ts + (_EXTCAL_TS_DAY * $i);
1725
1726
                    break;
1727
1728
                case '1TU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1729
1730
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1731
                    $dayOfWeek = date('w', $ts);
1732
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1733
                    $i         = 0;
1734
                    while (2 != $dayOfWeek % 7) {
1735
                        ++$dayOfWeek;
1736
                        ++$i;
1737
                    }
1738
1739
                    return $ts + (_EXTCAL_TS_DAY * $i);
1740
1741
                    break;
1742
1743
                case '1WE':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1744
1745
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1746
                    $dayOfWeek = date('w', $ts);
1747
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1748
                    $i         = 0;
1749
                    while (3 != $dayOfWeek % 7) {
1750
                        ++$dayOfWeek;
1751
                        ++$i;
1752
                    }
1753
1754
                    return $ts + (_EXTCAL_TS_DAY * $i);
1755
1756
                    break;
1757
1758
                case '1TH':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1759
1760
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1761
                    $dayOfWeek = date('w', $ts);
1762
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1763
                    $i         = 0;
1764
                    while (4 != $dayOfWeek % 7) {
1765
                        ++$dayOfWeek;
1766
                        ++$i;
1767
                    }
1768
1769
                    return $ts + (_EXTCAL_TS_DAY * $i);
1770
1771
                    break;
1772
1773
                case '1FR':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1774
1775
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1776
                    $dayOfWeek = date('w', $ts);
1777
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1778
                    $i         = 0;
1779
                    while (5 != $dayOfWeek % 7) {
1780
                        ++$dayOfWeek;
1781
                        ++$i;
1782
                    }
1783
1784
                    return $ts + (_EXTCAL_TS_DAY * $i);
1785
1786
                    break;
1787
1788
                case '1SA':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1789
1790
                    $ts        = mktime(0, 0, 0, $month, 1, $year);
1791
                    $dayOfWeek = date('w', $ts);
1792
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1793
                    $i         = 0;
1794
                    while (6 != $dayOfWeek % 7) {
1795
                        ++$dayOfWeek;
1796
                        ++$i;
1797
                    }
1798
1799
                    return $ts + (_EXTCAL_TS_DAY * $i);
1800
1801
                    break;
1802
1803
                case '2SU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1804
1805
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1806
                    $dayOfWeek = date('w', $ts);
1807
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1808
                    $i         = 0;
1809
                    while (0 != $dayOfWeek % 7) {
1810
                        ++$dayOfWeek;
1811
                        ++$i;
1812
                    }
1813
1814
                    return $ts + (_EXTCAL_TS_DAY * $i);
1815
1816
                    break;
1817
1818
                case '2MO':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1819
1820
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1821
                    $dayOfWeek = date('w', $ts);
1822
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1823
                    $i         = 0;
1824
                    while (1 != $dayOfWeek % 7) {
1825
                        ++$dayOfWeek;
1826
                        ++$i;
1827
                    }
1828
1829
                    return $ts + (_EXTCAL_TS_DAY * $i);
1830
1831
                    break;
1832
1833
                case '2TU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1834
1835
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1836
                    $dayOfWeek = date('w', $ts);
1837
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1838
                    $i         = 0;
1839
                    while (2 != $dayOfWeek % 7) {
1840
                        ++$dayOfWeek;
1841
                        ++$i;
1842
                    }
1843
1844
                    return $ts + (_EXTCAL_TS_DAY * $i);
1845
1846
                    break;
1847
1848
                case '2WE':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1849
1850
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1851
                    $dayOfWeek = date('w', $ts);
1852
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1853
                    $i         = 0;
1854
                    while (3 != $dayOfWeek % 7) {
1855
                        ++$dayOfWeek;
1856
                        ++$i;
1857
                    }
1858
1859
                    return $ts + (_EXTCAL_TS_DAY * $i);
1860
1861
                    break;
1862
1863
                case '2TH':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1864
1865
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1866
                    $dayOfWeek = date('w', $ts);
1867
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1868
                    $i         = 0;
1869
                    while (4 != $dayOfWeek % 7) {
1870
                        ++$dayOfWeek;
1871
                        ++$i;
1872
                    }
1873
1874
                    return $ts + (_EXTCAL_TS_DAY * $i);
1875
1876
                    break;
1877
1878
                case '2FR':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1879
1880
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1881
                    $dayOfWeek = date('w', $ts);
1882
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1883
                    $i         = 0;
1884
                    while (5 != $dayOfWeek % 7) {
1885
                        ++$dayOfWeek;
1886
                        ++$i;
1887
                    }
1888
1889
                    return $ts + (_EXTCAL_TS_DAY * $i);
1890
1891
                    break;
1892
1893
                case '2SA':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1894
1895
                    $ts        = mktime(0, 0, 0, $month, 7, $year);
1896
                    $dayOfWeek = date('w', $ts);
1897
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1898
                    $i         = 0;
1899
                    while (6 != $dayOfWeek % 7) {
1900
                        ++$dayOfWeek;
1901
                        ++$i;
1902
                    }
1903
1904
                    return $ts + (_EXTCAL_TS_DAY * $i);
1905
1906
                    break;
1907
1908
                case '3SU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1909
1910
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1911
                    $dayOfWeek = date('w', $ts);
1912
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1913
                    $i         = 0;
1914
                    while (0 != $dayOfWeek % 7) {
1915
                        ++$dayOfWeek;
1916
                        ++$i;
1917
                    }
1918
1919
                    return $ts + (_EXTCAL_TS_DAY * $i);
1920
1921
                    break;
1922
1923
                case '3MO':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1924
1925
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1926
                    $dayOfWeek = date('w', $ts);
1927
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1928
                    $i         = 0;
1929
                    while (1 != $dayOfWeek % 7) {
1930
                        ++$dayOfWeek;
1931
                        ++$i;
1932
                    }
1933
1934
                    return $ts + (_EXTCAL_TS_DAY * $i);
1935
1936
                    break;
1937
1938
                case '3TU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1939
1940
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1941
                    $dayOfWeek = date('w', $ts);
1942
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1943
                    $i         = 0;
1944
                    while (2 != $dayOfWeek % 7) {
1945
                        ++$dayOfWeek;
1946
                        ++$i;
1947
                    }
1948
1949
                    return $ts + (_EXTCAL_TS_DAY * $i);
1950
1951
                    break;
1952
1953
                case '3WE':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1954
1955
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1956
                    $dayOfWeek = date('w', $ts);
1957
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1958
                    $i         = 0;
1959
                    while (3 != $dayOfWeek % 7) {
1960
                        ++$dayOfWeek;
1961
                        ++$i;
1962
                    }
1963
1964
                    return $ts + (_EXTCAL_TS_DAY * $i);
1965
1966
                    break;
1967
1968
                case '3TH':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1969
1970
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1971
                    $dayOfWeek = date('w', $ts);
1972
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1973
                    $i         = 0;
1974
                    while (4 != $dayOfWeek % 7) {
1975
                        ++$dayOfWeek;
1976
                        ++$i;
1977
                    }
1978
1979
                    return $ts + (_EXTCAL_TS_DAY * $i);
1980
1981
                    break;
1982
1983
                case '3FR':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1984
1985
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
1986
                    $dayOfWeek = date('w', $ts);
1987
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
1988
                    $i         = 0;
1989
                    while (5 != $dayOfWeek % 7) {
1990
                        ++$dayOfWeek;
1991
                        ++$i;
1992
                    }
1993
1994
                    return $ts + (_EXTCAL_TS_DAY * $i);
1995
1996
                    break;
1997
1998
                case '3SA':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
1999
2000
                    $ts        = mktime(0, 0, 0, $month, 14, $year);
2001
                    $dayOfWeek = date('w', $ts);
2002
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2003
                    $i         = 0;
2004
                    while (6 != $dayOfWeek % 7) {
2005
                        ++$dayOfWeek;
2006
                        ++$i;
2007
                    }
2008
2009
                    return $ts + (_EXTCAL_TS_DAY * $i);
2010
2011
                    break;
2012
2013
                case '4SU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2014
2015
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2016
                    $dayOfWeek = date('w', $ts);
2017
                    $ts        = (0 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2018
                    $i         = 0;
2019
                    while (0 != $dayOfWeek % 7) {
2020
                        ++$dayOfWeek;
2021
                        ++$i;
2022
                    }
2023
2024
                    return $ts + (_EXTCAL_TS_DAY * $i);
2025
2026
                    break;
2027
2028
                case '4MO':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2029
2030
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2031
                    $dayOfWeek = date('w', $ts);
2032
                    $ts        = (1 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2033
                    $i         = 0;
2034
                    while (1 != $dayOfWeek % 7) {
2035
                        ++$dayOfWeek;
2036
                        ++$i;
2037
                    }
2038
2039
                    return $ts + (_EXTCAL_TS_DAY * $i);
2040
2041
                    break;
2042
2043
                case '4TU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2044
2045
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2046
                    $dayOfWeek = date('w', $ts);
2047
                    $ts        = (2 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2048
                    $i         = 0;
2049
                    while (2 != $dayOfWeek % 7) {
2050
                        ++$dayOfWeek;
2051
                        ++$i;
2052
                    }
2053
2054
                    return $ts + (_EXTCAL_TS_DAY * $i);
2055
2056
                    break;
2057
2058
                case '4WE':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2059
2060
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2061
                    $dayOfWeek = date('w', $ts);
2062
                    $ts        = (3 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2063
                    $i         = 0;
2064
                    while (3 != $dayOfWeek % 7) {
2065
                        ++$dayOfWeek;
2066
                        ++$i;
2067
                    }
2068
2069
                    return $ts + (_EXTCAL_TS_DAY * $i);
2070
2071
                    break;
2072
2073
                case '4TH':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2074
2075
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2076
                    $dayOfWeek = date('w', $ts);
2077
                    $ts        = (4 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2078
                    $i         = 0;
2079
                    while (4 != $dayOfWeek % 7) {
2080
                        ++$dayOfWeek;
2081
                        ++$i;
2082
                    }
2083
2084
                    return $ts + (_EXTCAL_TS_DAY * $i);
2085
2086
                    break;
2087
2088
                case '4FR':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2089
2090
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2091
                    $dayOfWeek = date('w', $ts);
2092
                    $ts        = (5 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2093
                    $i         = 0;
2094
                    while (5 != $dayOfWeek % 7) {
2095
                        ++$dayOfWeek;
2096
                        ++$i;
2097
                    }
2098
2099
                    return $ts + (_EXTCAL_TS_DAY * $i);
2100
2101
                    break;
2102
2103
                case '4SA':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2104
2105
                    $ts        = mktime(0, 0, 0, $month, 21, $year);
2106
                    $dayOfWeek = date('w', $ts);
2107
                    $ts        = (6 == date('w', $ts)) ? $ts + (_EXTCAL_TS_DAY * 7) : $ts;
2108
                    $i         = 0;
2109
                    while (6 != $dayOfWeek % 7) {
2110
                        ++$dayOfWeek;
2111
                        ++$i;
2112
                    }
2113
2114
                    return $ts + (_EXTCAL_TS_DAY * $i);
2115
2116
                    break;
2117
2118
                case '-1SU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2119
2120
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2121
                    $dayOfWeek = date('w', $ts);
2122
                    $i         = 0;
2123
                    while (0 != $dayOfWeek % 7) {
2124
                        ++$dayOfWeek;
2125
                        ++$i;
2126
                    }
2127
                    if (0 == $i) {
2128
                        return $ts;
2129
                    }
2130
2131
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2132
2133
                    break;
2134
2135
                case '-1MO':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2136
2137
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2138
                    $dayOfWeek = date('w', $ts);
2139
                    $i         = 0;
2140
                    while (1 != $dayOfWeek % 7) {
2141
                        ++$dayOfWeek;
2142
                        ++$i;
2143
                    }
2144
                    if (0 == $i) {
2145
                        return $ts;
2146
                    }
2147
2148
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2149
2150
                    break;
2151
2152
                case '-1TU':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2153
2154
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2155
                    $dayOfWeek = date('w', $ts);
2156
                    $i         = 0;
2157
                    while (2 != $dayOfWeek % 7) {
2158
                        ++$dayOfWeek;
2159
                        ++$i;
2160
                    }
2161
                    if (0 == $i) {
2162
                        return $ts;
2163
                    }
2164
2165
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2166
2167
                    break;
2168
2169
                case '-1WE':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2170
2171
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2172
                    $dayOfWeek = date('w', $ts);
2173
                    $i         = 0;
2174
                    while (3 != $dayOfWeek % 7) {
2175
                        ++$dayOfWeek;
2176
                        ++$i;
2177
                    }
2178
                    if (0 == $i) {
2179
                        return $ts;
2180
                    }
2181
2182
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2183
2184
                    break;
2185
2186
                case '-1TH':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2187
2188
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2189
                    $dayOfWeek = date('w', $ts);
2190
                    $i         = 0;
2191
                    while (4 != $dayOfWeek % 7) {
2192
                        ++$dayOfWeek;
2193
                        ++$i;
2194
                    }
2195
                    if (0 == $i) {
2196
                        return $ts;
2197
                    }
2198
2199
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2200
2201
                    break;
2202
2203
                case '-1FR':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2204
2205
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2206
                    $dayOfWeek = date('w', $ts);
2207
                    $i         = 0;
2208
                    while (5 != $dayOfWeek % 7) {
2209
                        ++$dayOfWeek;
2210
                        ++$i;
2211
                    }
2212
                    if (0 == $i) {
2213
                        return $ts;
2214
                    }
2215
2216
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2217
2218
                    break;
2219
2220
                case '-1SA':
0 ignored issues
show
Coding Style introduced by
The case body in a switch statement must start on the line following the statement.

According to the PSR-2, the body of a case statement must start on the line immediately following the case statement.

switch ($expr) {
case "A":
    doSomething(); //right
    break;
case "B":

    doSomethingElse(); //wrong
    break;

}

To learn more about the PSR-2 coding standard, please refer to the PHP-Fig.

Loading history...
2221
2222
                    $ts        = mktime(0, 0, 0, $month, date('t', mktime(0, 0, 0, $month, 1, $year)), $year);
2223
                    $dayOfWeek = date('w', $ts);
2224
                    $i         = 0;
2225
                    while (6 != $dayOfWeek % 7) {
2226
                        ++$dayOfWeek;
2227
                        ++$i;
2228
                    }
2229
                    if (0 == $i) {
2230
                        return $ts;
2231
                    }
2232
2233
                    return $ts + (_EXTCAL_TS_DAY * ($i - 7));
2234
2235
                    break;
2236
2237
                default:
2238
                    return 0;
2239
2240
                    break;
2241
2242
            }
2243
        }
2244
    }
2245
2246
    /*************************************************************************
2247
     *
2248
     ************************************************************************
2249
     * @param $year
2250
     * @param $month
2251
     * @param $day
2252
     * @param $cat
2253
     * @param $searchExp
2254
     * @param $andor
2255
     * @param $orderBy
2256
     * @return array
2257
     */
2258
    public function getSearchEvent2($year, $month, $day, $cat, $searchExp, $andor, $orderBy)
2259
    {
2260
        global $xoopsDB, $xoopsUser;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2261
2262
        if (isset($xoopsUser)) {
2263
            $userId = $xoopsUser->getVar('uid');
2264
            $result = $this->getSearchEvents($year, $month, $day, $cat, $searchExp, $andor, $orderBy, 0, 0, $userId, $xoopsUser);
2265
        } else {
2266
            $result = $this->getSearchEvents($year, $month, $day, $cat, $searchExp, $andor, $orderBy, 0, 0);
2267
        }
2268
2269
        $ret = [];
2270
        while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
2271
            $myrow['cat']['cat_name']        = $myrow['cat_name'];
2272
            $myrow['cat']['cat_color']       = $myrow['cat_color'];
2273
            $myrow['cat']['cat_light_color'] = Extcal\Utility::getLighterColor($myrow['cat']['cat_color'], _EXTCAL_INFOBULLE_RGB_MIN, _EXTCAL_INFOBULLE_RGB_MAX);
2274
            if ('' == $myrow['event_icone']) {
2275
                $myrow['event_icone'] = $myrow['cat']['cat_icone'];
2276
            }
2277
            $ret[] = $myrow;
2278
        }
2279
2280
        return $ret;
2281
    }
2282
2283
    //-----------------------------------------------------------
2284
2285
    /**
2286
     * @param int    $year
2287
     * @param int    $month
2288
     * @param int    $day
2289
     * @param int    $cat
2290
     * @param        $queryarray
2291
     * @param        $andor
2292
     * @param        $orderBy
2293
     * @param int    $limit
2294
     * @param int    $offset
2295
     * @param int    $userId
2296
     * @param string $user
2297
     *
2298
     * @return mixed
2299
     */
2300
    public function getSearchEvents(
2301
        $year = 0,
2302
        $month = 0,
2303
        $day = 0,
2304
        $cat = 0,
2305
        $queryarray,
2306
        $andor,
2307
        $orderBy,
2308
        $limit = 0,
2309
        $offset = 0,
2310
        $userId = 0,
2311
        $user = '')
2312
    {
2313
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2314
2315
        //echo "<hr>{$andor}-{$limit}-{$offset}-{$userId}-{$user}<br>{$criteresPlus}";
2316
        $tEvent = $xoopsDB->prefix('extcal_event') . ' AS te';
2317
        $tCat   = $xoopsDB->prefix('extcal_cat') . ' AS tc';
2318
2319
        $sql = 'SELECT te.*, tc.cat_name , tc.cat_color, ' . 'year(FROM_UNIXTIME(event_start)) AS year,' . 'month(FROM_UNIXTIME(event_start)) AS month,' . 'day(FROM_UNIXTIME(event_start)) AS day' . " FROM {$tEvent}, {$tCat}";
2320
        //---------------------------------------------------
2321
        $tw   = [];
2322
        $tw[] = 'te.cat_id = tc.cat_id';
2323
        $tw[] = 'event_approved = 1';
2324
2325
        $authorizedAccessCats = $this->extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
2326
        $inCat                = 'te.cat_id IN (0)';
2327
        if (count($authorizedAccessCats) > 0) {
0 ignored issues
show
Bug introduced by
$authorizedAccessCats of type boolean is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

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

2327
        if (count(/** @scrutinizer ignore-type */ $authorizedAccessCats) > 0) {
Loading history...
2328
            $inCat = 'te.cat_id IN (' . implode(',', $authorizedAccessCats) . ')';
0 ignored issues
show
Bug introduced by
$authorizedAccessCats of type boolean is incompatible with the type array expected by parameter $pieces of implode(). ( Ignorable by Annotation )

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

2328
            $inCat = 'te.cat_id IN (' . implode(',', /** @scrutinizer ignore-type */ $authorizedAccessCats) . ')';
Loading history...
2329
        }
2330
        //echo $tw[count($tw)-1];
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2331
2332
        if (0 != $userId) {
2333
            $tw[] .= "({$inCat} OR event_submitter = {$userId} )";
2334
        } else {
2335
            $tw[] = $inCat;
2336
        }
2337
        //--------------------------------------------------------
2338
        if ($cat > 0) {
2339
            $tw[] .= "te.cat_id = {$cat}";
2340
        }
2341
        if ($year > 0) {
2342
            $tw[] .= "year(FROM_UNIXTIME(event_start)) = {$year}";
2343
        }
2344
        if ($month > 0) {
2345
            $tw[] .= "month(FROM_UNIXTIME(event_start)) = {$month}";
2346
        }
2347
        if ($day > 0) {
2348
            $tw[] .= "day(FROM_UNIXTIME(event_start)) = {$day}";
2349
        }
2350
2351
        //echoArray($queryarray,false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2352
        if (!is_array($queryarray)) {
2353
            $queryarray = (('' != $queryarray) ? explode(' ', $queryarray) : '');
2354
        }
2355
2356
        if (is_array($queryarray)) {
2357
            $tFields = [
2358
                'te.event_title',
2359
                'te.event_desc',
2360
                'te.event_contact',
2361
                'te.event_address',
2362
                'tc.cat_name',
2363
            ];
2364
            $t       = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $t is dead and can be removed.
Loading history...
2365
            foreach ($queryarray as $i => $iValue) {
2366
                $t1[] = " %1\$s LIKE '#{$queryarray[$i]}#' ";
2367
            }
2368
2369
            $flt = '(' . implode(" {$andor} ", $t1) . ')';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $t1 seems to be defined by a foreach iteration on line 2365. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
2370
2371
            $t = [];
2372
            foreach ($tFields as $h => $hValue) {
2373
                $t[] = sprintf($flt, $tFields[$h]);
2374
            }
2375
2376
            $filtre = implode(' OR ', $t);
2377
            $filtre = str_replace('#', '%', $filtre);
2378
            $tw[]   = '(' . $filtre . ')';
2379
        }
2380
2381
        $sql .= ' WHERE ' . implode(' AND ', $tw);
2382
        //------------------------------------------------------------
2383
        if (count($orderBy) > 0) {
2384
            $t = [];
2385
            foreach ($orderBy as $hValue) {
2386
                if ('' != $hValue) {
2387
                    $t[] = $hValue;
2388
                }
2389
            }
2390
            if (count($t) > 0) {
2391
                $sql .= ' ORDER BY ' . implode(',', $t);
2392
            }
2393
        }
2394
2395
        //----------------------------------------------------------------
2396
2397
        $result = $xoopsDB->query($sql, $limit, $offset);
2398
2399
        // echo "<hr>{$sql}<hr>";
2400
        return $result;
2401
    }
2402
2403
    //-----------------------------------------------------------
2404
2405
    /**
2406
     * @param $queryarray
2407
     * @param $andor
2408
     * @param $limit
2409
     * @param $offset
2410
     * @param $userId
2411
     * @param $user
2412
     *
2413
     * @return mixed
2414
     */
2415
    public function getSearchEvent($queryarray, $andor, $limit, $offset, $userId, $user)
2416
    {
2417
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2418
2419
        $result = $this->getSearchEvents(0, 0, 0, 0, $queryarray, $andor, ['event_id DESC']);
2420
2421
        $i = 0;
2422
        while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
2423
            $ret[$i]['image'] = 'assets/images/icons/extcal.gif';
2424
            $ret[$i]['link']  = 'event.php?event=' . $myrow['event_id'];
2425
            $ret[$i]['title'] = $myrow['event_title'];
2426
            $ret[$i]['time']  = $myrow['event_submitdate'];
2427
            $ret[$i]['uid']   = $myrow['event_submitter'];
2428
            ++$i;
2429
        }
2430
2431
        return $ret;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $ret does not seem to be defined for all execution paths leading up to this point.
Loading history...
2432
    }
2433
2434
    /**
2435
     * @param        $queryarray
2436
     * @param        $andor
2437
     * @param        $limit
2438
     * @param        $offset
2439
     * @param        $userId
2440
     * @param        $user
2441
     * @param string $criteresPlus
2442
     * @param bool   $xoopsSearch
2443
     *
2444
     * @return array
2445
     */
2446
    public function getSearchEvent3(
2447
        $queryarray,
2448
        $andor,
2449
        $limit,
2450
        $offset,
2451
        $userId,
2452
        $user,
2453
        $criteresPlus = '',
2454
        $xoopsSearch = true)
2455
    {
2456
        global $xoopsDB;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2457
        //echo "<hr>{$andor}-{$limit}-{$offset}-{$userId}-{$user}<br>{$criteresPlus}";
2458
2459
        //        if ($cols == '') {
0 ignored issues
show
Unused Code Comprehensibility introduced by
50% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2460
        //            $cols = 'event_id, event_title, event_submitter, event_submitdate';
0 ignored issues
show
Unused Code Comprehensibility introduced by
43% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2461
        //        }
2462
        $tEvent = $xoopsDB->prefix('extcal_event');
2463
        $tCat   = $xoopsDB->prefix('extcal_cat');
2464
        $sql    = "SELECT {$tEvent}.*, {$tCat}.cat_name AS categorie, {$tCat}.cat_color " . " FROM {$tEvent}, {$tCat}" . " WHERE {$tEvent}.cat_id = {$tCat}.cat_id AND event_approved = '1'";
2465
2466
        $authorizedAccessCats = $this->extcalPerm->getAuthorizedCat($user, 'extcal_cat_view');
2467
        $count                = count($authorizedAccessCats);
0 ignored issues
show
Bug introduced by
$authorizedAccessCats of type boolean is incompatible with the type Countable|array expected by parameter $var of count(). ( Ignorable by Annotation )

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

2467
        $count                = count(/** @scrutinizer ignore-type */ $authorizedAccessCats);
Loading history...
2468
        if ($count > 0) {
2469
            $in = '(' . $authorizedAccessCats[0];
2470
            array_shift($authorizedAccessCats);
0 ignored issues
show
Bug introduced by
$authorizedAccessCats of type boolean is incompatible with the type array expected by parameter $array of array_shift(). ( Ignorable by Annotation )

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

2470
            array_shift(/** @scrutinizer ignore-type */ $authorizedAccessCats);
Loading history...
2471
            foreach ($authorizedAccessCats as $authorizedAccessCat) {
0 ignored issues
show
Bug introduced by
The expression $authorizedAccessCats of type boolean is not traversable.
Loading history...
2472
                $in .= ',' . $authorizedAccessCat;
2473
            }
2474
            $in .= ')';
2475
        } else {
2476
            $in = '(0)';
2477
        }
2478
        $sql .= " AND {$tEvent}.cat_id IN " . $in . '';
2479
        if (0 != $userId) {
2480
            $sql .= " AND event_submitter = '" . $userId . "'";
2481
        }
2482
2483
        //echoArray($queryarray,false);
0 ignored issues
show
Unused Code Comprehensibility introduced by
86% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2484
        if (is_array($queryarray)) {
2485
            /*
0 ignored issues
show
Unused Code Comprehensibility introduced by
44% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
2486
            $sql .= " AND ((event_title LIKE '%$queryarray[0]%' OR event_desc LIKE '%$queryarray[0]%' OR event_contact LIKE '%$queryarray[0]%' OR event_address LIKE '%$queryarray[0]%')";
2487
            for ($i = 1; $i < $count; ++$i) {
2488
                $sql .= " $andor ";
2489
                $sql .= "(event_title LIKE '%$queryarray[0]%' OR event_desc LIKE '%$queryarray[0]%' OR event_contact LIKE '%$queryarray[0]%' OR event_address LIKE '%$queryarray[0]%')";
2490
            }
2491
            $sql .= ") ";
2492
            */
2493
2494
            $tFields = ['event_title', 'event_desc', 'event_contact', 'event_address', 'cat_name'];
2495
            $t       = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $t is dead and can be removed.
Loading history...
2496
            foreach ($queryarray as $i => $iValue) {
2497
                $t1[] = " %1\$s LIKE '#{$queryarray[$i]}#' ";
2498
            }
2499
2500
            $flt = '(' . implode(" {$andor} ", $t1) . ')';
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $t1 seems to be defined by a foreach iteration on line 2496. Are you sure the iterator is never empty, otherwise this variable is not defined?
Loading history...
2501
2502
            $t = [];
2503
            foreach ($tFields as $h => $hValue) {
2504
                $t[] = sprintf($flt, $tFields[$h]);
2505
            }
2506
2507
            $filtre = implode(' OR ', $t);
2508
            $filtre = str_replace('#', '%', $filtre);
2509
            $sql    .= " AND ($filtre)";
2510
        }
2511
2512
        if ('' != $criteresPlus) {
2513
            $sql .= ' AND ' . $criteresPlus;
2514
        }
2515
        $sql .= ' ORDER BY event_id DESC';
2516
2517
        $result = $xoopsDB->query($sql, $limit, $offset);
2518
        $ret    = [];
2519
        $i      = 0;
2520
        if ($xoopsSearch) {
2521
            while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
2522
                $ret[$i]['image'] = 'assets/images/icons/extcal.gif';
2523
                $ret[$i]['link']  = 'event.php?event=' . $myrow['event_id'];
2524
                $ret[$i]['title'] = $myrow['event_title'];
2525
                $ret[$i]['time']  = $myrow['event_submitdate'];
2526
                $ret[$i]['uid']   = $myrow['event_submitter'];
2527
                ++$i;
2528
            }
2529
        } else {
2530
            while (false !== ($myrow = $xoopsDB->fetchArray($result))) {
2531
                $myrow['cat']['cat_name']  = $myrow['cat_name'];
2532
                $myrow['cat']['cat_color'] = $myrow['cat_color'];
2533
                $ret[]                     = $myrow;
2534
                ++$i;
2535
            }
2536
        }
2537
2538
        return $ret;
2539
    }
2540
2541
    /**
2542
     * @param $event
2543
     * @param $eventsArray
2544
     * @param $startPeriod
2545
     * @param $endPeriod
2546
     */
2547
    public function addEventToCalArray(&$event, &$eventsArray, $startPeriod, $endPeriod)
2548
    {
2549
        global $timeHandler, $xoopsUser, $month, $year;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
2550
2551
        // Calculating the start and the end of the event
2552
        $startEvent = $event['event_start'];
2553
        $endEvent   = $event['event_end'];
2554
2555
        // This event start before this month and finish after
2556
        if ($startEvent < $startPeriod && $endEvent > $endPeriod) {
2557
            $endFor = date('t', mktime(0, 0, 0, $month, 1, $year));
2558
            for ($i = 1; $i <= $endFor; ++$i) {
2559
                $event['status']   = 'middle';
2560
                $eventsArray[$i][] = $event;
2561
            }
2562
            // This event start before this month and finish during
2563
        } else {
2564
            if ($startEvent < $startPeriod) {
2565
                $endFor = date('j', $endEvent);
2566
                for ($i = 1; $i <= $endFor; ++$i) {
2567
                    $event['status']   = ($i != $endFor) ? 'middle' : 'end';
2568
                    $eventsArray[$i][] = $event;
2569
                }
2570
                // This event start during this month and finish after
2571
            } else {
2572
                if ($endEvent > $endPeriod) {
2573
                    $startFor = date('j', $startEvent);
2574
                    $endFor   = date('t', mktime(0, 0, 0, $month, 1, $year));
2575
                    for ($i = $startFor; $i <= $endFor; ++$i) {
2576
                        $event['status']   = ($i == $startFor) ? 'start' : 'middle';
2577
                        $eventsArray[$i][] = $event;
2578
                    }
2579
                    // This event start and finish during this month
2580
                } else {
2581
                    $startFor = date('j', $startEvent);
2582
                    $endFor   = date('j', $endEvent);
2583
                    for ($i = $startFor; $i <= $endFor; ++$i) {
2584
                        if ($startFor == $endFor) {
2585
                            $event['status'] = 'single';
2586
                        } else {
2587
                            if ($i == $startFor) {
2588
                                $event['status'] = 'start';
2589
                            } else {
2590
                                if ($i == $endFor) {
2591
                                    $event['status'] = 'end';
2592
                                } else {
2593
                                    $event['status'] = 'middle';
2594
                                }
2595
                            }
2596
                        }
2597
                        $eventsArray[$i][] = $event;
2598
                    }
2599
                }
2600
            }
2601
        }
2602
    }
2603
2604
    //-------------------------------------------------
2605
} // -------- Fin e la classe ---------------------
2606