b_marquee_xoopspoll()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 33
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 26
c 1
b 0
f 0
nc 3
nop 3
dl 0
loc 33
rs 9.504
1
<?php declare(strict_types=1);
2
/**
3
 * ****************************************************************************
4
 * Marquee - MODULE FOR XOOPS
5
 * Copyright (c) Hervé Thouzard (https://www.herve-thouzard.com)
6
 *
7
 * You may not change or alter any portion of this comment or credits
8
 * of supporting developers from this source code or any supporting source code
9
 * which is considered copyrighted (c) material of the original comment or credit authors.
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
 * @copyright ::   {@link https://www.herve-thouzard.com Hervé Thouzard}
16
 * @license   ::     {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2.0 or later}
17
 * @author    ::      Hervé Thouzard (https://www.herve-thouzard.com)
18
 * @subpackage::  plugins
19
 */
20
21
/**
22
 * Script to list the recent polls from the xoopspoll module version 1.40
23
 * @param $limit
24
 * @param $dateformat
25
 * @param $itemssize
26
 * @return array
27
 */
28
29
use XoopsModules\Xoopspoll\{
30
    Helper,
31
    PollHandler
32
};
33
34
/**
35
 * @param $limit
36
 * @param $dateformat
37
 * @param $itemssize
38
 * @return array
39
 */
40
function b_marquee_xoopspoll($limit, $dateformat, $itemssize)
41
{
42
    require_once $GLOBALS['xoops']->path('modules/marquee/include/functions.php');
43
    $block = [];
44
    $myts  = \MyTextSanitizer::getInstance();
0 ignored issues
show
Unused Code introduced by
The assignment to $myts is dead and can be removed.
Loading history...
45
    /** @var PollHandler $pollHandler */
46
    $pollHandler = Helper::getInstance()->getHandler('Poll');
47
    $criteria    = new \CriteriaCompo();
48
    $criteria->add(new \Criteria('start_time', time(), '<='));
49
    $criteria->add(new \Criteria('end_time', time(), '>'));
50
    $criteria->setLimit((int)$limit);
51
    $criteria->setSort('start_time');
52
    $criteria->setOrder('DESC');
53
    $pollFields = ['poll_id', 'question', 'start_time', 'user_id'];
54
    $pollObjs   = $pollHandler->getAll($criteria, $pollFields);
55
    foreach ($pollObjs as $pollObj) {
56
        $pollValues = $pollObj->getValues();
57
        $title      = htmlspecialchars($pollValues['question'], ENT_QUOTES | ENT_HTML5);
58
        if ((int)$itemssize > 0) {
59
            $title = xoops_substr($title, 0, $itemssize + 3);
60
        }
61
        $xuStartTimestamp = xoops_getUserTimestamp($pollValues['start_time']);
62
        $block[]          = [
63
            'date'     => formatTimestamp($xuStartTimestamp, $dateformat),
64
            'category' => '',
65
            'author'   => $pollValues['user_id'],
66
            'title'    => $title,
67
            'link'     => "<a href='" . $GLOBALS['xoops']->url('modules/xoopspoll/index.php') . "?poll_id={$pollValues['poll_id']}'>{$title}</a>",
68
        ];
69
        unset($pollValues);
70
    }
71
72
    return $block;
73
}
74