Completed
Push — master ( 8786b6...8e35b4 )
by Michael
8s
created

search.inc.php ➔ randomquote_search()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 45
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 1
Metric Value
cc 6
eloc 31
c 1
b 1
f 1
nc 5
nop 5
dl 0
loc 45
rs 8.439
1
<?php
2
/*
3
 You may not change or alter any portion of this comment or credits of
4
 supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit
6
 authors.
7
8
 This program is distributed in the hope that it will be useful, but
9
 WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
/**
13
 * Module: RandomQuote
14
 *
15
 * @category        Module
16
 * @package         randomquote
17
 * @author          XOOPS Module Development Team
18
 * @copyright       {@link http://xoops.org 2001-2016 XOOPS Project}
19
 * @license         {@link http://www.fsf.org/copyleft/gpl.html GNU public license}
20
 * @link            http://xoops.org XOOPS
21
 * @since           2.00
22
 */
23
24
function randomquote_search($queryarray, $andor, $limit, $offset, $userid)
0 ignored issues
show
Coding Style introduced by
randomquote_search uses the super-global variable $GLOBALS which is generally not recommended.

Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable:

// Bad
class Router
{
    public function generate($path)
    {
        return $_SERVER['HOST'].$path;
    }
}

// Better
class Router
{
    private $host;

    public function __construct($host)
    {
        $this->host = $host;
    }

    public function generate($path)
    {
        return $this->host.$path;
    }
}

class Controller
{
    public function myAction(Request $request)
    {
        // Instead of
        $page = isset($_GET['page']) ? intval($_GET['page']) : 1;

        // Better (assuming you use the Symfony2 request)
        $page = $request->query->get('page', 1);
    }
}
Loading history...
25
{
26
    $ret = array();
27
    if (0 != (int)$userid) {
28
        return $ret;
29
    }
30
31
    $moduleDirName = basename(dirname(__DIR__));
32
    include_once $GLOBALS['xoops']->path("/modules/{$moduleDirName}/class/constants.php");
33
34
    $quoteHandler = xoops_getmodulehandler('quotes', 'randomquote');
35
    $entryFields  = array('id', 'quote', 'author', 'create_date');
36
    $criteria     = new CriteriaCompo();
37
    $criteria->add(new Criteria('quote_status', RandomquoteConstants::STATUS_ONLINE));
38
    $criteria->setSort('create_date');
39
    $criteria->setOrder('DESC');
40
    $criteria->setLimit((int) $limit);
41
    $criteria->setStart((int) $offset);
42
43
    if ((is_array($queryarray)) && !empty($queryarray)) {
44
        $criteria->add(new Criteria('quote', "%{$queryarray[0]}%", 'LIKE'));
45
        $criteria->add(new Criteria('author', "%{$queryarray[0]}%", 'LIKE'), 'OR');
46
        array_shift($queryarray); //get rid of first element
47
48
        foreach ($queryarray as $query) {
49
            $criteria->add(new Criteria('quote', "%{$query}%", 'LIKE'), $andor);
50
            $criteria->add(new Criteria('author', "%{$query}%", 'LIKE'), 'OR');
51
        }
52
    }
53
    $quoteObjs = $quoteHandler->getAll($criteria, $entryFields);
54
    foreach ($quoteObjs as $thisQuote) {
55
        $ttl = xoops_substr(strip_tags((string) $thisQuote), 0, 60, $trimmarker = '...');
56
        $ret[] = array (
57
                        'image' => 'assets/images/icons/quote.png',
58
                         'link' => "index.php?id=" . $thisQuote->getVar('id'),
59
                        'title' => $ttl,
60
                         'time' => strtotime($thisQuote->getVar('create_date')),
61
//                          'uid' => $entry['uid']
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...
62
                       );
63
64
    }
65
66
    unset($quoteObjs);
67
    return $ret;
68
}
69