SearchPlugin::search()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 48
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 33
nc 8
nop 5
dl 0
loc 48
rs 8.7697
c 0
b 0
f 0
1
<?php
2
3
namespace XoopsModules\Xooghost\Plugin;
4
5
/**
6
 * Xooghost module
7
 *
8
 * You may not change or alter any portion of this comment or credits
9
 * of supporting developers from this source code or any supporting source code
10
 * which is considered copyrighted (c) material of the original comment or credit authors.
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14
 *
15
 * @copyright       XOOPS Project (https://xoops.org)
16
 * @license         GNU GPL 2 (http://www.gnu.org/licenses/old-licenses/gpl-2.0.html)
17
 * @package         Xooghost
18
 * @since           2.6.0
19
 * @author          Laurent JEN (Aka DuGris)
20
 */
21
22
/**
23
 * Class XooghostSearchPlugin
24
 */
25
class SearchPlugin extends \Xoops\Module\Plugin\PluginAbstract implements \SearchPluginInterface
26
{
27
    /**
28
     * @param $queries
29
     * @param $andor
30
     * @param $limit
31
     * @param $start
32
     * @param $uid
33
     *
34
     * @return array
35
     */
36
    public function search($queries, $andor, $limit, $start, $uid)
37
    {
38
        $searchstring = '';
0 ignored issues
show
Unused Code introduced by
The assignment to $searchstring is dead and can be removed.
Loading history...
39
        $ret = [];
40
41
        $criteria = new \CriteriaCompo();
42
43
        $criteria->setLimit($limit);
44
        $criteria->setStart($start);
45
        $criteria->setSort('xooghost_published');
46
        $criteria->setOrder('DESC');
47
48
        $criteria->add(new \Criteria('xooghost_online', 1));
49
        $criteria->add(new \Criteria('xooghost_published', 0, '>'));
50
        $criteria->add(new \Criteria('xooghost_published', time(), '<='));
51
52
        if (is_array($queries) && $count = count($queries)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $count is dead and can be removed.
Loading history...
53
            foreach ($queries as $k => $v) {
54
                $criteria_content = new \CriteriaCompo();
55
                $criteria_content->add(new \Criteria('xooghost_title', '%' . $v . '%', 'LIKE'), 'OR');
56
                $criteria_content->add(new \Criteria('xooghost_content', '%' . $v . '%', 'LIKE'), 'OR');
57
                $criteria_content->add(new \Criteria('xooghost_description', '%' . $v . '%', 'LIKE'), 'OR');
58
                $criteria_content->add(new \Criteria('xooghost_keywords', '%' . $v . '%', 'LIKE'), 'OR');
59
                $criteria->add($criteria_content, $andor);
60
            }
61
        }
62
63
        if (0 != $uid) {
64
            $criteria->add(new \Criteria('xooghost_uid', $uid));
65
        }
66
67
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
68
        $pageHandler = $helper->getHandler('Page');
69
70
        $pages = $pageHandler->getObjects($criteria, true, false);
0 ignored issues
show
Bug introduced by
The method getObjects() does not exist on XoopsObjectHandler. ( Ignorable by Annotation )

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

70
        /** @scrutinizer ignore-call */ 
71
        $pages = $pageHandler->getObjects($criteria, true, false);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
71
72
        $k = 0;
73
        foreach ($pages as $page) {
74
            $ret[$k]['image'] = 'assets/icons/logo_small.png';
75
            $ret[$k]['link'] = $page['xooghost_url'];
76
            $ret[$k]['title'] = $page['xooghost_title'];
77
            $ret[$k]['time'] = $page['xooghost_time'];
78
            $ret[$k]['uid'] = $page['xooghost_uid'];
79
            $ret[$k]['content'] = $page['xooghost_content'];
80
            ++$k;
81
        }
82
83
        return $ret;
84
    }
85
}
86