xoopsfaq_rss()   B
last analyzed

Complexity

Conditions 6
Paths 24

Size

Total Lines 45
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 6
eloc 30
c 2
b 0
f 0
nc 24
nop 1
dl 0
loc 45
rs 8.8177
1
<?php declare(strict_types=1);
2
/*
3
 You may not change or alter any portion of this comment or credits of
4
 supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit
6
 authors.
7
8
 This program is distributed in the hope that it will be useful, but
9
 WITHOUT ANY WARRANTY; without even the implied warranty of
10
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11
 */
12
13
/**
14
 * XoopsFAQ module
15
 * Description: RSS Definition file
16
 *
17
 * @param int $max
18
 * @return array
19
 * @copyright Copyright (c) 2001-2017 {@link https://xoops.org XOOPS Project}
20
 * @license   https://www.gnu.org/licenses/gpl-2.0.html GNU Public License
21
 *
22
 * @see       Xmf\Request
23
 * @see       \XoopsModules\Xoopsfaq\Helper
24
 * @author    XOOPS Module Development Team
25
 */
26
27
use XoopsModules\Xoopsfaq\{
28
    Constants,
29
    CategoryHandler,
30
    ContentsHandler,
31
    Helper
32
};
33
34
/**
35
 * @return array
36
 */
37
function xoopsfaq_rss(int $max = 10): array
38
{
39
    /** @var Helper $helper */
40
    $helper = Helper::getInstance();
41
    /** @var CategoryHandler $categoryHandler */
42
    $categoryHandler = $helper->getHandler('Category');
43
    /** @var ContentsHandler $contentsHandler */
44
    $contentsHandler = $helper->getHandler('Contents');
45
    $catId           = Xmf\Request::getInt('categoryid', Constants::DEFAULT_CATEGORY, 'GET');
46
    $cat_title       = '';
47
    if ($catId > Constants::DEFAULT_CATEGORY) {
48
        $categoryObj = $categoryHandler->get($catId);
49
        if ($categoryObj) {
0 ignored issues
show
introduced by
$categoryObj is of type XoopsObject, thus it always evaluated to true.
Loading history...
50
            $cat_title = $categoryObj->getVar('category_title');
51
            unset($categoryHandler, $categoryObj);
52
        }
53
    }
54
55
    $max      = ($max > 0) ? $max : 10;
56
    $criteria = new \CriteriaCompo();
57
    $criteria->setLimit($max);
58
    $criteria->add(new \Criteria('contents_active', Constants::ACTIVE, '='));
59
    $criteria->add(new \Criteria('contents_publish', Constants::NOT_PUBLISHED, '>'));
60
    $criteria->add(new \Criteria('contents_publish', time(), '<='));
61
    if ($catId > Constants::DEFAULT_CATEGORY) {
62
        $criteria->add(new \Criteria('contents_cid', $catId, '='));
63
    }
64
    $contentObjs = $contentsHandler->getAll($criteria);
65
66
    $retVal = [];
67
68
    /** @var \XoopsObject $contentObj */
69
    foreach ($contentObjs as $contentObj) {
70
        $retVal[] = [
71
            'image'    => '',
72
            'title'    => $contentObj->getVar('contents_title'),
73
            'link'     => $contentObj->getVar('contents_contents'),
74
            'time'     => $contentObj->getVar('contents_publish'),
75
            'desc'     => '',
76
            'category' => $cat_title,
77
        ];
78
    }
79
    unset($contentsHandler, $contentObjs);
80
81
    return $retVal;
82
}
83