smartfaq_notify_iteminfo()   B
last analyzed

Complexity

Conditions 6
Paths 8

Size

Total Lines 45
Code Lines 28

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 28
c 0
b 0
f 0
dl 0
loc 45
rs 8.8497
cc 6
nc 8
nop 2
1
<?php declare(strict_types=1);
2
3
/**
4
 * Module: SmartFAQ
5
 * Author: The SmartFactory <www.smartfactory.ca>
6
 * Licence: GNU
7
 * @param $category
8
 * @param $item_id
9
 * @return mixed
10
 */
11
function smartfaq_notify_iteminfo($category, $item_id)
12
{
13
    global $xoopsModule, $xoopsModuleConfig, $xoopsConfig;
14
15
    if (empty($xoopsModule) || 'smartfaq' !== $xoopsModule->getVar('dirname')) {
16
        /** @var \XoopsModuleHandler $moduleHandler */
17
        $moduleHandler = xoops_getHandler('module');
18
        $module        = $moduleHandler->getByDirname('smartfaq');
19
        /** @var \XoopsConfigHandler $configHandler */
20
        $configHandler = xoops_getHandler('config');
21
        $config        = $configHandler->getConfigsByCat(0, $module->getVar('mid'));
0 ignored issues
show
Unused Code introduced by
The assignment to $config is dead and can be removed.
Loading history...
22
    } else {
23
        $module = $xoopsModule;
24
        $config = $xoopsModuleConfig;
25
    }
26
27
    if ('global' === $category) {
28
        $item['name'] = '';
0 ignored issues
show
Comprehensibility Best Practice introduced by
$item was never initialized. Although not strictly required by PHP, it is generally a good practice to add $item = array(); before regardless.
Loading history...
29
        $item['url']  = '';
30
31
        return $item;
32
    }
33
34
    global $xoopsDB;
35
36
    if ('category' === $category) {
37
        // Assume we have a valid category id
38
        $sql          = 'SELECT name FROM ' . $xoopsDB->prefix('smartfaq_categories') . ' WHERE categoryid  = ' . $item_id;
39
        $result       = $xoopsDB->queryF($sql); // TODO: error check
40
        $result_array = $xoopsDB->fetchArray($result);
41
        $item['name'] = $result_array['name'];
42
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/category.php?categoryid=' . $item_id;
43
44
        return $item;
45
    }
46
47
    if ('faq' === $category) {
48
        // Assume we have a valid story id
49
        $sql          = 'SELECT question FROM ' . $xoopsDB->prefix('smartfaq_faq') . ' WHERE faqid = ' . $item_id;
50
        $result       = $xoopsDB->queryF($sql); // TODO: error check
51
        $result_array = $xoopsDB->fetchArray($result);
52
        $item['name'] = $result_array['question'];
53
        $item['url']  = XOOPS_URL . '/modules/' . $module->getVar('dirname') . '/faq.php?faqid=' . $item_id;
54
55
        return $item;
56
    }
57
}
58