NotificationsPlugin::item()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 3
nop 2
dl 0
loc 24
rs 9.7666
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 XooghostNotificationsPlugin
24
 */
25
class NotificationsPlugin extends \Xoops\Module\Plugin\PluginAbstract implements \NotificationsPluginInterface
26
{
27
    /**
28
     * @param string $category
29
     * @param int    $item_id
30
     *
31
     * @return array
32
     */
33
    public function item($category, $item_id)
34
    {
35
        $xoops = \Xoops::getInstance();
36
        $item = [];
37
        $item_id = (int)$item_id;
38
39
        if ('global' === $category) {
40
            $item['name'] = '';
41
            $item['url'] = '';
42
43
            return $item;
44
        }
45
46
        if ('item' === $category) {
47
            $sql = 'SELECT xooghost_title, xooghost_url FROM ' . $xoops->db()->prefix('xooghost') . ' WHERE xooghost_id = ' . $item_id;
48
            $result = $xoops->db()->query($sql); // TODO: error check
49
            $result_array = $xoops->db()->fetchArray($result);
50
            $item['name'] = $result_array['xooghost_title'];
51
            $item['url'] = $result_array['xooghost_url'];
52
53
            return $item;
54
        }
55
56
        return $item;
57
    }
58
59
    /**
60
     * @return array
61
     */
62
    public function categories()
63
    {
64
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
65
        $pageHandler = $helper->getHandler('Page');
66
        $ret = [];
67
        $ret[1]['name'] = 'global';
68
        $ret[1]['title'] = _MI_XOO_GHOST_NOTIFICATION_GLOBAL;
69
        $ret[1]['description'] = _MI_XOO_GHOST_NOTIFICATION_GLOBAL_DSC;
70
        $ret[1]['subscribe_from'] = ['index.php'];
71
72
        $ret[2]['name'] = 'item';
73
        $ret[2]['title'] = _MI_XOO_GHOST_NOTIFICATION_ITEM;
74
        $ret[2]['description'] = _MI_XOO_GHOST_NOTIFICATION_ITEM_DSC;
75
        $ret[2]['subscribe_from'] = $pageHandler->getUrls();
0 ignored issues
show
Bug introduced by
The method getUrls() 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

75
        /** @scrutinizer ignore-call */ 
76
        $ret[2]['subscribe_from'] = $pageHandler->getUrls();

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...
76
        $ret[2]['item_name'] = 'ghost_id';
77
        $ret[2]['allow_bookmark'] = 1;
78
79
        return $ret;
80
    }
81
82
    /**
83
     * @return array
84
     */
85
    public function events()
86
    {
87
        $ret = [];
88
        $ret[1]['name'] = 'newcontent';
89
        $ret[1]['category'] = 'global';
90
        $ret[1]['title'] = _MI_XOO_GHOST_NOTIFICATION_GLOBAL_NEWCONTENT;
91
        $ret[1]['caption'] = _MI_XOO_GHOST_NOTIFICATION_GLOBAL_NEWCONTENT_CAP;
92
        $ret[1]['description'] = _MI_XOO_GHOST_NOTIFICATION_GLOBAL_NEWCONTENT_DSC;
93
        $ret[1]['mail_template'] = 'global_newcontent';
94
        $ret[1]['mail_subject'] = _MI_XOO_GHOST_NOTIFICATION_GLOBAL_NEWCONTENT_SBJ;
95
96
        return $ret;
97
    }
98
99
    /**
100
     * @param string $category
101
     * @param int    $item_id
102
     * @param string $event
103
     *
104
     * @return array
105
     */
106
    public function tags($category, $item_id, $event)
107
    {
108
        return [];
109
    }
110
}
111