Passed
Pull Request — master (#18)
by Michael
02:50
created

include/search.php (2 issues)

Labels
Severity
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
*/
11
12
/**
13
 * Description: Search function for the XoopsPoll Module
14
 *
15
 * @copyright ::  {@link https://xoops.org/ XOOPS Project}
16
 * @license   ::    {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
17
 * @package   ::    xoopspoll
18
 * @subpackage:: search
19
 * @since     ::      1.40
20
 * @author    ::     John Neill, zyspec <[email protected]>
21
 */
22
23
use XoopsModules\Newbb;
24
use XoopsModules\Xoopspoll\{
25
    Helper
26
};
27
28
29
30
/**
31
 * xoopspoll_search()
32
 *
33
 * @param        $queryArray
34
 * @param  mixed $andor
35
 * @param  mixed $limit
36
 * @param  mixed $offset
37
 * @param        $uid
38
 * @return array
39
 * @internal param mixed $queryarray
40
 * @internal param mixed $userid
41
 */
42
function xoopspoll_search($queryArray, $andor, $limit, $offset, $uid)
43
{
44
    $ret = [];
45
    if (0 === (int)$uid) {
46
        //        xoops_load('pollUtility', 'xoopspoll');
47
        $pollHandler = Helper::getInstance()->getHandler('Poll');
48
        $pollFields  = ['poll_id', 'user_id', 'question', 'start_time'];
49
        $criteria    = new \CriteriaCompo();
50
        $criteria->add(new \Criteria('start_time', time(), '<=')); // only show polls that have started
51
52
         /**
53
         * @todo:
54
         * find out if want to show polls that were created with a forum. If no, then change
55
         * the link to forum topic_id
56
         */
57
58
        /**
59
         * check to see if we want to include polls created with forum (newbb)
60
         */
61
        $configHandler      = xoops_getHandler('config');
62
        /** @var \XoopsModuleHandler $moduleHandler */
63
        $moduleHandler = xoops_getHandler('module');
64
        $thisModule         = $moduleHandler->getByDirname('xoopspoll');
65
        $this_module_config = $configHandler->getConfigsByCat(0, $thisModule->getVar('mid'));
0 ignored issues
show
The method getConfigsByCat() does not exist on XoopsObjectHandler. It seems like you code against a sub-type of XoopsObjectHandler such as XoopsPersistableObjectHandler. ( Ignorable by Annotation )

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

65
        /** @scrutinizer ignore-call */ 
66
        $this_module_config = $configHandler->getConfigsByCat(0, $thisModule->getVar('mid'));
Loading history...
66
67
        $pollsWithTopics = [];
68
        if (($thisModule instanceof \XoopsModule) && $thisModule->isactive()
69
            && $this_module_config['hide_forum_polls']) {
70
            $newbbModule = $moduleHandler->getByDirname('newbb');
71
            if ($newbbModule instanceof \XoopsModule && $newbbModule->isactive()) {
72
                /** @var Newbb\TopicHandler $topicHandler */
73
                $topicHandler = Newbb\Helper::getInstance()->getHandler('Topic');
0 ignored issues
show
The type XoopsModules\Newbb\Helper 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...
74
                $tFields      = ['topic_id', 'poll_id'];
75
                $tArray       = $topicHandler->getAll(new \Criteria('topic_haspoll', 0, '>'), $tFields, false);
76
                foreach ($tArray as $t) {
77
                    $pollsWithTopics[$t['poll_id']] = $t['topic_id'];
78
                }
79
            }
80
            unset($newbbModule);
81
        }
82
83
        $criteria->setSort('start_time');
84
        $criteria->setOrder('DESC');
85
        $criteria->setLimit((int)$limit);
86
        $criteria->setStart((int)$offset);
87
88
        if (is_array($queryArray) && !empty($queryArray)) {
89
            $criteria->add(new \Criteria('question', "%{$queryArray[0]}%", 'LIKE'));
90
            $criteria->add(new \Criteria('description', "%{$queryArray[0]}%", 'LIKE'), 'OR');
91
            array_shift($queryArray); //get rid of first element
92
93
            foreach ($queryArray as $query) {
94
                $criteria->add(new \Criteria('question', "%{$query}%", 'LIKE'), $andor);
95
                $criteria->add(new \Criteria('description', "%{$query}%", 'LIKE'), 'OR');
96
            }
97
        }
98
        $pollArray = $pollHandler->getAll($criteria, $pollFields, false);
99
        foreach ($pollArray as $poll) {
100
            $link = "pollresults.php?poll_id={$poll['poll_id']}";
101
            if (array_key_exists($poll['poll_id'], $pollsWithTopics)) {
102
                $link = $GLOBALS['xoops']->url("modules/newbb/viewtopic.php?topic_id={$pollsWithTopics[$poll['poll_id']]}");
103
            }
104
105
            $ret[] = [
106
                'image' => 'assets/images/icons/logo_large.png',
107
                'link'  => $link,
108
                'title' => $poll['question'],
109
                'time'  => $poll['start_time'],
110
            ];
111
        }
112
    }
113
114
    return $ret;
115
}
116