Completed
Push — master ( 33267f...6861ed )
by Michael
33:49 queued 15:31
created

PublisherCommentsPlugin::pageName()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
//namespace XoopsModules\Publisher\Plugin;
4
5
/*
6
 You may not change or alter any portion of this comment or credits
7
 of supporting developers from this source code or any supporting source code
8
 which is considered copyrighted (c) material of the original comment or credit authors.
9
10
 This program is distributed in the hope that it will be useful,
11
 but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
 */
14
15
/**
16
 *  Publisher class
17
 *
18
 * @copyright       The XUUPS Project http://sourceforge.net/projects/xuups/
19
 * @license         GNU GPL V2 or later (http://www.gnu.org/licenses/gpl-2.0.html)
20
 * @package         Class
21
 * @subpackage      Utils
22
 * @since           1.0
23
 * @author          trabis <[email protected]>
24
 * @version         $Id$
25
 */
26
use CommentsComment;
27
use CommentsPluginInterface;
28
use Xoops;
29
use Xoops\Module\Plugin\PluginAbstract;
30
use XoopsModules\Publisher;
31
use XoopsModules\Publisher\Helper;
32
33
/**
34
 * Class CommentsPlugin
35
 * @package XoopsModules\Publisher\Plugin
36
 */
37
class PublisherCommentsPlugin extends PluginAbstract implements CommentsPluginInterface
38
{
39
    /**
40
     * @return string
41
     */
42
    public function itemName()
43
    {
44
        return 'itemid';
45
    }
46
47
    /**
48
     * @return string
49
     */
50
    public function pageName()
51
    {
52
        return 'item.php';
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function extraParams()
59
    {
60
        return [];
61
    }
62
63
    /**
64
     * This method will be executed upon successful post of an approved comment.
65
     * This includes comment posts by administrators, and change of comment status from 'pending' to 'active' state.
66
     * An CommentsComment object that has been approved will be passed as the first and only parameter.
67
     * This should be useful for example notifying the item submitter of a comment post.
68
     */
69
    public function approve(CommentsComment $comment)
70
    {
71
        //Where are you looking at?
72
    }
73
74
    /**
75
     * This method will be executed whenever the total number of 'active' comments for an item is changed.
76
     *
77
     * @param int $item_id   The unique ID of an item
78
     * @param int $total_num The total number of active comments
79
     */
80
    public function update($item_id, $total_num)
81
    {
82
        $db = Xoops::getInstance()->db();
83
        $sql = 'UPDATE ' . $db->prefix('publisher_items') . ' SET comments = ' . (int)$total_num . ' WHERE itemid = ' . (int)$item_id;
84
        $db->query($sql);
85
    }
86
87
    /**
88
     * This method will be executed whenever a new comment form is displayed.
89
     * You can set a default title for the comment and a header to be displayed on top of the form
90
     * ex: return array(
91
     *      'title' => 'My Article Title',
92
     *      'text' => 'Content of the article');
93
     *      'timestamp' => time(); //Date of the article in unix format
94
     *      'uid' => Id of the article author
95
     *
96
     * @param int $item_id The unique ID of an item
97
     *
98
     * @return array
99
     */
100
    public function itemInfo($item_id)
101
    {
102
        $ret = [];
103
        require_once \dirname(\dirname(__DIR__)) . '/include/common.php';
104
105
        /* @var Publisher\Item $itemObj */
106
        $itemObj = Helper::getInstance()->getItemHandler()->get((int)$item_id);
107
        $ret['text'] = '';
108
        $summary = $itemObj->summary();
109
        if ('' != $summary) {
110
            $ret['text'] .= $summary . '<br><br>';
111
        }
112
        $ret['text'] .= $itemObj->body();
113
        $ret['title'] = $itemObj->title();
114
        $ret['uid'] = $itemObj->getVar('uid');
115
        $ret['timestamp'] = $itemObj->getVar('datesub', 'n');
116
117
        return $ret;
118
    }
119
}
120