Passed
Push — master ( 08c22c...f61562 )
by Michael
03:58
created

xoopsfaq_rss()   A

Complexity

Conditions 5
Paths 16

Size

Total Lines 42
Code Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 30
c 1
b 0
f 0
nc 16
nop 1
dl 0
loc 42
rs 9.1288
1
<?php
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 http://xoops.org XOOPS Project}
20
 * @license   http://www.gnu.org/licenses/gpl-2.0.html GNU Public License
21
 *
22
 * @see       Xmf\Request
23
 * @see       \XoopsModules\Xoopsfaq\Helper
24
 * @package   module\xoopsfaq\rss
25
 * @author    XOOPS Module Development Team
26
 */
27
28
use XoopsModules\Xoopsfaq;
29
30
/**
31
 * @param int $max
32
 * @return array
33
 */
34
function xoopsfaq_rss($max = 10)
35
{
36
    /** @var Xoopsfaq\CategoryHandler $categoryHandler */ /** @var Xoopsfaq\ContentsHandler $contentsHandler */
37
    /** @var Xoopsfaq\Helper $helper */
38
    $helper          = \XoopsModules\Xoopsfaq\Helper::getInstance();
39
    $categoryHandler = $helper->getHandler('Category');
40
    $contentsHandler = $helper->getHandler('Contents');
41
    $catId           = Xmf\Request::getInt('categoryid', Xoopsfaq\Constants::DEFAULT_CATEGORY, 'GET');
42
    if ($catId > Xoopsfaq\Constants::DEFAULT_CATEGORY) {
43
        $categoryObj = $categoryHandler->get($catId);
44
        $cat_title   = $categoryObj->getVar('category_title');
45
        unset($categoryHandler, $categoryObj);
46
    } else {
47
        $cat_title = '';
48
    }
49
50
    $max      = ((int)$max > 0) ? (int)$max : 10;
51
    $criteria = new \CriteriaCompo();
52
    $criteria->setLimit($max);
53
    $criteria->add(new \Criteria('contents_active', Xoopsfaq\Constants::ACTIVE, '='));
54
    $criteria->add(new \Criteria('contents_publish', Xoopsfaq\Constants::NOT_PUBLISHED, '>'));
55
    $criteria->add(new \Criteria('contents_publish', time(), '<='));
56
    if ($catId > Xoopsfaq\Constants::DEFAULT_CATEGORY) {
57
        $criteria->add(new \Criteria('contents_cid', $catId, '='));
58
    }
59
    $contentObjs = $contentsHandler->getAll($criteria);
60
61
    $retVal = [];
62
63
    /** @var XoopsObject $contentObj */
64
    foreach ($contentObjs as $contentObj) {
65
        $retVal[] = [
66
            'image'    => '',
67
            'title'    => $contentObj->getVar('contents_title'),
68
            'link'     => $contentObj->getVar('contents_contents'),
69
            'time'     => $contentObj->getVar('contents_publish'),
70
            'desc'     => '',
71
            'category' => $cat_title,
72
        ];
73
    }
74
    unset($contentsHandler, $contentObjs);
75
    return $retVal;
76
}
77