countdown_search()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 20
nc 8
nop 5
dl 0
loc 28
rs 8.9777
c 2
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
use Xmf\Request;
6
7
/**
8
 * @param $queryarray
9
 * @param $andor
10
 * @param $limit
11
 * @param $offset
12
 * @param $userid
13
 * @return array
14
 */
15
function countdown_search($queryarray, $andor, $limit, $offset, $userid)
16
{
17
    $sql = 'SELECT * FROM ' . $GLOBALS['xoopsDB']->prefix('countdown_events') . ' ';
18
    if (0 != $userid) {
19
        $sql .= " WHERE event_uid='$userid'";
20
    }
21
    // because count() returns 1 even if a supplied variable
22
    // is not an array, we must check if $querryarray is really an array
23
    if (is_array($queryarray) && $count = count($queryarray)) {
24
        $sql .= " WHERE ((event_name LIKE '%{$queryarray[0]}%')";
25
        for ($i = 1; $i < $count; $i++) {
26
            $sql .= " $andor ";
27
            $sql .= "(event_name LIKE '%{$queryarray[$i]}%')";
28
        }
29
        $sql .= ') ';
30
    }
31
    $sql    .= ' ORDER BY event_name ASC';
32
    $result = $GLOBALS['xoopsDB']->query($sql, (int)$limit, (int)$offset);
33
    $ret    = [];
34
    $i      = 0;
35
    while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
36
        $ret[$i]['link']  = '' . XOOPS_URL . "/modules/countdown/event.php?op=view&id=" . $myrow['event_id'] . '';
37
        $ret[$i]['title'] = '' . htmlspecialchars($myrow['event_name'], ENT_QUOTES | ENT_HTML5) . '';
38
        $ret[$i]['time']  = '' . strtotime($myrow['event_date']) . '';
39
        $ret[$i]['uid']   = '' . $myrow['event_uid'] . '';
40
        $i++;
41
    }
42
    return $ret;
43
}
44