CommentsPlugin::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
rs 10
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 XooghostCommentsPlugin
24
 */
25
class CommentsPlugin extends \Xoops\Module\Plugin\PluginAbstract implements \CommentsPluginInterface
26
{
27
    /**
28
     * @return string
29
     */
30
    public function itemName()
31
    {
32
        return 'ghost_id';
33
    }
34
35
    /**
36
     * @return string
37
     */
38
    public function pageName()
39
    {
40
        return 'page_comment.php';
41
    }
42
43
    /**
44
     * @return array
45
     */
46
    public function extraParams()
47
    {
48
        return [];
49
    }
50
51
    /**
52
     * This method will be executed upon successful post of an approved comment.
53
     * This includes comment posts by administrators, and change of comment status from 'pending' to 'active' state.
54
     * An CommentsComment object that has been approved will be passed as the first and only parameter.
55
     * This should be useful for example notifying the item submitter of a comment post.
56
     *
57
     * @param \CommentsComment $comment
58
     */
59
    public function approve(\CommentsComment $comment)
60
    {
61
        //Where are you looking at?
62
    }
63
64
    /**
65
     * This method will be executed whenever the total number of 'active' comments for an item is changed.
66
     *
67
     * @param int $item_id   The unique ID of an item
68
     * @param int $total_num The total number of active comments
69
     */
70
    public function update($item_id, $total_num)
71
    {
72
        $db = \Xoops::getInstance()->db();
73
        $sql = 'UPDATE ' . $db->prefix('xooghost') . ' SET xooghost_comments = ' . (int)($total_num) . ' WHERE xooghost_id = ' . (int)($item_id);
74
        $db->query($sql);
75
    }
76
77
    /**
78
     * This method will be executed whenever a new comment form is displayed.
79
     * You can set a default title for the comment and a header to be displayed on top of the form
80
     * ex: return array(
81
     *      'title' => 'My Article Title',
82
     *      'text' => 'Content of the article');
83
     *      'timestamp' => time(); //Date of the article in unix format
84
     *      'uid' => Id of the article author
85
     *
86
     * @param int $item_id The unique ID of an item
87
     *
88
     * @return array
89
     */
90
    public function itemInfo($item_id)
91
    {
92
        $ret = [];
93
94
        $helper = \XoopsModules\Xooghost\Helper::getInstance();
95
        $pageHandler = $helper->getHandler('Page');
96
        $page = $page = $pageHandler->get($item_id);
0 ignored issues
show
Unused Code introduced by
The assignment to $page is dead and can be removed.
Loading history...
97
98
        $ret['text'] = $page->getVar('xooghost_content');
0 ignored issues
show
Bug introduced by
The method getVar() does not exist on null. ( Ignorable by Annotation )

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

98
        /** @scrutinizer ignore-call */ 
99
        $ret['text'] = $page->getVar('xooghost_content');

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...
99
        $ret['title'] = $page->getVar('xooghost_title');
100
        $ret['uid'] = $page->getVar('xooghost_uid');
101
        $ret['timestamp'] = $page->getVar('xooghost_published');
102
103
        return $ret;
104
    }
105
}
106