search.inc.php ➔ instruction_search()   C
last analyzed

Complexity

Conditions 8
Paths 10

Size

Total Lines 45
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 8
eloc 28
nc 10
nop 5
dl 0
loc 45
rs 5.3846
c 0
b 0
f 0
1
<?php
2
3
include_once dirname(__DIR__) . '/include/common.php';
4
require_once __DIR__ . '/../../../header.php';
5
6
/**
7
 * @param $queryarray
8
 * @param $andor
9
 * @param $limit
10
 * @param $offset
11
 * @param $userid
12
 * @return array
13
 */
14
function instruction_search($queryarray, $andor, $limit, $offset, $userid)
15
{
16
    // Подключаем функции
17
    $moduleDirName = basename(dirname(__DIR__));
18
    include_once $GLOBALS['xoops']->path('modules/' . $moduleDirName . '/class/utility.php');
19
20
    $sql = 'SELECT p.pageid, p.title, p.uid, p.datecreated, i.title FROM ' . $GLOBALS['xoopsDB']->prefix('instruction_page') . ' p, ' . $GLOBALS['xoopsDB']->prefix('instruction_instr') . ' i WHERE i.instrid = p.instrid AND i.status > 0 AND p.status > 0 AND p.type > 0';
21
    if (0 != $userid) {
22
        $sql .= ' AND p.uid = ' . (int)$userid . ' ';
23
        //return NULL;
24
    }
25
26
    // Права на просмотр
27
    $categories = Xoopsmodules\instruction\Utility::getItemIds();
28
    if (is_array($categories) && count($categories) > 0) {
29
        $sql .= ' AND i.cid IN ( ' . implode(', ', $categories) . ' ) ';
30
        // Если пользователь не имеет прав просмотра ни одной категории
31
    } else {
32
        return null;
33
    }
34
35
    // Добавляем в условие ключевые слова поиска
36
    if (is_array($queryarray) && $count = count($queryarray)) {
37
        $sql .= " AND ( ( p.title LIKE '%$queryarray[0]%' OR p.hometext LIKE '%$queryarray[0]%' )";
38
        for ($i = 1; $i < $count; $i++) {
39
            $sql .= " $andor ";
40
            $sql .= "( p.title LIKE '%$queryarray[$i]%' OR p.hometext LIKE '%$queryarray[$i]%' )";
41
        }
42
        $sql .= ' ) ';
43
    }
44
    //$sql .= "ORDER BY date DESC";
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...
45
    $result = $GLOBALS['xoopsDB']->query($sql, $limit, $offset);
46
    $ret    = [];
47
    $i      = 0;
48
    // Перебираем все результаты
49
    while (list($pageid, $ptitle, $puid, $pdatecreated, $ititle) = $GLOBALS['xoopsDB']->fetchRow($result)) {
50
        $ret[$i]['image'] = 'assets/images/size2.gif';
51
        $ret[$i]['link']  = 'page.php?id=' . $pageid;
52
        $ret[$i]['title'] = $ititle . ': ' . $ptitle;
53
        $ret[$i]['time']  = $pdatecreated;
54
        $ret[$i]['uid']   = $puid;
55
        $i++;
56
    }
57
    return $ret;
58
}
59