publisher_date_to_date_show()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 45
Code Lines 31

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 5
eloc 31
c 0
b 0
f 0
nc 2
nop 1
dl 0
loc 45
rs 9.1128
1
<?php declare(strict_types=1);
2
/*
3
 You may not change or alter any portion of this comment or credits
4
 of supporting developers from this source code or any supporting source code
5
 which is considered copyrighted (c) material of the original comment or credit authors.
6
7
 This program is distributed in the hope that it will be useful,
8
 but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10
 */
11
12
/**
13
 * @copyright       XOOPS Project (https://xoops.org)
14
 * @license         https://www.fsf.org/copyleft/gpl.html GNU public license
15
 * @since           1.0
16
 * @author          trabis <[email protected]>
17
 * @author          The SmartFactory <www.smartfactory.ca>
18
 */
19
20
use XoopsModules\Publisher\BlockForm;
21
use XoopsModules\Publisher\Helper;
22
use XoopsModules\Publisher\ItemHandler;
23
24
require_once \dirname(__DIR__) . '/include/common.php';
25
26
/**
27
 * @param $options
28
 *
29
 * @return array
30
 */
31
function publisher_date_to_date_show($options)
32
{
33
    $myts   = \MyTextSanitizer::getInstance();
34
    $helper = Helper::getInstance();
35
36
    $block = $newItems = [];
37
38
    $criteria = new \CriteriaCompo();
39
    $criteria->add(new \Criteria('datesub', strtotime($options[0]), '>'));
40
    $criteria->add(new \Criteria('datesub', isset($options[1]) ? strtotime($options[1]) : '', '<'));
41
    $criteria->setSort('datesub');
42
    $criteria->setOrder('DESC');
43
44
    // creating the ITEM objects that belong to the selected category
45
    /** @var ItemHandler $itemHandler */
46
    $itemHandler = $helper->getHandler('Item');
47
    $itemsObj    = $itemHandler->getObjects($criteria);
48
    //    $totalItems = count($itemsObj);
49
50
    if ($itemsObj && \is_array($itemsObj)) {
51
        foreach ($itemsObj as $iValue) {
52
            $newItems['itemid']       = $iValue->itemid();
53
            $newItems['title']        = $iValue->getTitle();
54
            $newItems['categoryname'] = $iValue->getCategoryName();
55
            $newItems['categoryid']   = $iValue->categoryid();
56
            $newItems['date']         = $iValue->getDatesub();
57
            $newItems['poster']       = $iValue->getLinkedPosterName();
58
            $newItems['itemlink']     = $iValue->getItemLink(false, $options[3] ?? 65);
59
            $newItems['categorylink'] = $iValue->getCategoryLink();
60
            $block['items'][]         = $newItems;
61
        }
62
63
        $block['lang_title']            = _MB_PUBLISHER_ITEMS;
64
        $block['lang_category']         = _MB_PUBLISHER_CATEGORY;
65
        $block['lang_poster']           = _MB_PUBLISHER_POSTEDBY;
66
        $block['lang_date']             = _MB_PUBLISHER_DATE;
67
        $moduleName                     = $myts->displayTarea(
68
            $helper->getModule()
0 ignored issues
show
Bug introduced by
It seems like $helper->getModule()->getVar('name') can also be of type array and array; however, parameter $text of MyTextSanitizer::displayTarea() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

68
            /** @scrutinizer ignore-type */ $helper->getModule()
Loading history...
69
                   ->getVar('name')
70
        );
71
        $block['lang_visitItem']        = _MB_PUBLISHER_VISITITEM . ' ' . $moduleName;
72
        $block['lang_articles_from_to'] = sprintf(_MB_PUBLISHER_ARTICLES_FROM_TO, $options[0], $options[1] ?? 0);
73
    }
74
75
    return $block;
76
}
77
78
/**
79
 * @param $options
80
 *
81
 * @return string
82
 */
83
function publisher_date_to_date_edit($options)
84
{
85
    // require_once PUBLISHER_ROOT_PATH . '/class/blockform.php';
86
    xoops_load('XoopsFormLoader');
87
    xoops_load('XoopsFormTextDateSelect');
88
89
    if ('' === $options[0]) {
90
        $options[0] = formatTimestamp(1424860422);
91
    }
92
93
    $form    = new BlockForm();
94
    $fromEle = new \XoopsFormTextDateSelect(_MB_PUBLISHER_FROM, 'options[0]', 15, strtotime($options[0]));
95
    //    $fromEle->setNocolspan();
96
    $untilEle = new \XoopsFormTextDateSelect(_MB_PUBLISHER_UNTIL, 'options[1]', 15, isset($options[1]) ? strtotime($options[1]) : '');
0 ignored issues
show
Bug introduced by
It seems like IssetNode ? strtotime($options[1]) : '' can also be of type string; however, parameter $value of XoopsFormTextDateSelect::__construct() does only seem to accept integer, maybe add an additional type check? ( Ignorable by Annotation )

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

96
    $untilEle = new \XoopsFormTextDateSelect(_MB_PUBLISHER_UNTIL, 'options[1]', 15, /** @scrutinizer ignore-type */ isset($options[1]) ? strtotime($options[1]) : '');
Loading history...
97
    //    $untilEle->setNocolspan();
98
99
    $form->addElement($fromEle);
100
    $form->addElement($untilEle);
101
102
    return $form->render();
103
}
104