notification.inc.php ➔ gwiki_notify_iteminfo()   B
last analyzed

Complexity

Conditions 5
Paths 6

Size

Total Lines 50
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 33
nc 6
nop 2
dl 0
loc 50
rs 8.6315
c 0
b 0
f 0
1
<?php
2
/**
3
 * include/notification.inc.php - notification lookup
4
 *
5
 * This file is part of gwiki - geekwright wiki
6
 *
7
 * @copyright  Copyright © 2013 geekwright, LLC. All rights reserved.
8
 * @license    gwiki/docs/license.txt  GNU General Public License (GPL)
9
 * @since      1.0
10
 * @author     Richard Griffith <[email protected]>
11
 * @package    gwiki
12
 */
13
if (!defined('GWIKI_NOTIFY_ITEMINFO')) {
14
    define('GWIKI_NOTIFY_ITEMINFO', 1);
15
16
    /**
17
     * @param $category
18
     * @param $item_id
19
     *
20
     * @return mixed
21
     */
22
    function gwiki_notify_iteminfo($category, $item_id)
23
    {
24
        global $xoopsDB;
25
26
        $dir = basename(dirname(__DIR__));
27
        //include_once XOOPS_ROOT_PATH.'/modules/'.$dir.'/class/GwikiPage.php';
28
        //$wikiPage = new GwikiPage;
29
        $moduleHelper = Xmf\Module\Helper::getHelper($dir);
30
31
        switch ($category) {
32
            case 'page':
33
                $item_id = (int)$item_id;
34
                $sql     = 'SELECT i.keyword as keyword, display_keyword, title FROM ';
35
                $sql .= $xoopsDB->prefix('gwiki_pageids') . ' i, ' . $xoopsDB->prefix('gwiki_pages') . ' p ';
36
                //            $sql .= ' WHERE i.keyword = p.keyword AND active = 1 AND page_id = '.$item_id;
37
                $sql .= " WHERE i.keyword = p.keyword AND active = 1 AND page_id = {$item_id}";
38
39
                $result = $xoopsDB->query($sql);
40
                $row    = $xoopsDB->fetchArray($result);
41
42
                $item['name'] = $row['display_keyword'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
43
                if (empty($item['name'])) {
44
                    $item['name'] = $row['title'];
45
                }
46
                if (empty($item['name'])) {
47
                    $item['name'] = $row['keyword'];
48
                }
49
50
                $item['url'] = sprintf($moduleHelper->getConfig('wikilink_template'), $row['keyword']);
51
                break;
52
            case 'namespace':
53
                $item_id = (int)$item_id;
54
                $sql     = 'SELECT prefix, prefix_home FROM ' . $xoopsDB->prefix('gwiki_prefix');
55
                //            $sql .= ' WHERE prefix_id = '.$item_id;
56
                $sql .= " WHERE prefix_id = {$item_id}";
57
58
                $result = $xoopsDB->query($sql);
59
                $row    = $xoopsDB->fetchArray($result);
60
61
                $item['name'] = $row['prefix'];
0 ignored issues
show
Coding Style Comprehensibility introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
62
                $item['url']  = sprintf($moduleHelper->getConfig('wikilink_template'), $row['prefix'] . ':' . $row['prefix_home']);
63
                break;
64
            default:
65
                $item['name'] = $category;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
66
                $item['url']  = XOOPS_URL . '/modules/' . $dir . '/';
67
                break;
68
        }
69
70
        return $item;
71
    }
72
}
73