Passed
Push — master ( b0fca4...7540c5 )
by Michael
06:08 queued 02:59
created

Wgsimpleacc::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 2
nop 0
dl 0
loc 4
rs 10
1
<?php
2
3
namespace XoopsModules\Rssfit\Plugins;
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
 * @copyright    XOOPS Project (https://xoops.org)
17
 * @license      GNU GPL 2 or later (https://www.gnu.org/licenses/gpl-2.0.html)
18
 * @package      RSSFit - Extendable XML news feed generator
19
 * @author       NS Tai (aka tuff) <http://www.brandycoke.com>
20
 * @author       XOOPS Development Team
21
 */
22
23
24
use XoopsModules\Rssfit\{
25
    AbstractPlugin
26
};
27
use XoopsModules\Wgsimpleacc\Helper as PluginHelper;
28
29
if (!\defined('RSSFIT_ROOT_PATH')) {
30
    exit();
31
}
32
33
/**
34
 * Class Sample
35
 * @package XoopsModules\Rssfit\Plugins
36
 */
37
final class Wgsimpleacc extends AbstractPlugin
38
{
39
    public function __construct() {
40
        if (\class_exists(PluginHelper::class)) {
41
            $this->helper = PluginHelper::getInstance();
42
            $this->dirname = $this->helper->dirname();
43
        }
44
    }
45
46
    public function grabEntries(\XoopsMySQLDatabase $xoopsDB): ?array
47
    {
48
        $ret  = null;
49
        $i    = 0;
50
        //  The following example code grabs the latest entries from the module
51
        $sql  = 'SELECT t.tra_id, t.tra_datecreated, t.tra_year, t.tra_nb, t.tra_desc, a1.acc_key, a1.acc_name, a2.all_name, a3.as_name, c.cli_name ';
52
        $sql .= 'FROM (((' . $xoopsDB->prefix('wgsimpleacc_transactions') . ' t INNER JOIN ' . $xoopsDB->prefix('wgsimpleacc_accounts') . ' a1 ';
53
        $sql .= 'ON t.tra_accid = a1.acc_id) INNER JOIN ' . $xoopsDB->prefix('wgsimpleacc_allocations') . ' a2 ON t.tra_allid = a2.all_id) ';
54
        $sql .= 'INNER JOIN ' . $xoopsDB->prefix('wgsimpleacc_assets') . ' a3 ON t.tra_asid = a3.as_id) ';
55
        $sql .= 'LEFT JOIN ' . $xoopsDB->prefix('wgsimpleacc_clients') . ' c ON t.tra_cliid = c.cli_id ';
56
        $sql .= 'ORDER BY t.tra_datecreated DESC';
57
58
        $result = $xoopsDB->query($sql, $this->grab, 0);
59
        if ($result instanceof \mysqli_result) {
60
            $ret = [];
61
            while (false !== ($row = $xoopsDB->fetchArray($result))) {
62
                $link = XOOPS_URL . '/modules/' . $this->dirname . '/transactions.php?op=show&amp;tra_id=' . $row['tra_id'];
63
                /*
64
                * Required elements of an RSS item
65
                */
66
                //  1. Title of an item
67
                $ret[$i]['title'] = $row['tra_year'] . '/' . $row['tra_nb'];
68
                //  2. URL of an item
69
                $ret[$i]['link'] = $link;
70
                //  3. Item modification date, must be in Unix time format
71
                $ret[$i]['timestamp'] = $row['tra_datecreated'];
72
                //  4. The item synopsis, or description, whatever
73
                $ret[$i]['description'] = \strip_tags($row['tra_desc']);
74
                /*
75
                * Optional elements of an RSS item
76
                */
77
                //  5. The item synopsis, or description, whatever
78
                $ret[$i]['guid'] = $link;
79
                //  6. A string + domain that identifies a categorization taxonomy
80
                $ret[$i]['category'] = $this->modname;
81
                $ret[$i]['domain']   = XOOPS_URL . '/modules/' . $this->dirname . '/';
82
                //  7. extra tags examples
83
                $ret[$i]['extras'] = [];
84
                //  7a. without attribute
85
                $ret[$i]['extras']['account'] = ['content' => $row['acc_name']];
86
                $ret[$i]['extras']['allocation'] = ['content' => $row['all_name']];
87
                if ('' !== \strip_tags($row['cli_name'])) {
88
                    $ret[$i]['extras']['client'] = ['content' => \strip_tags($row['cli_name'])];
89
                }
90
                //  7b. with attributes
91
                //$ret[$i]['extras']['enclosure']['attributes'] = ['url' => 'url-to-any-file', 'length' => 1024000, 'type' => 'audio/mpeg'];
92
                $i++;
93
            }
94
        }
95
        return $ret;
96
    }
97
}
98