ChangeSelectedState   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 17
c 0
b 0
f 0
dl 0
loc 32
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A statusesByState() 0 26 3
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Xhelp;
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    {@link https://xoops.org/ XOOPS Project}
17
 * @license      {@link https://www.gnu.org/licenses/gpl-2.0.html GNU GPL 2 or later}
18
 * @author       Brian Wahoff <[email protected]>
19
 * @author       Eric Juden <[email protected]>
20
 * @author       XOOPS Development Team
21
 */
22
23
use Xmf\Request;
24
use XoopsModules\Xhelp;
25
26
require_once \dirname(__DIR__, 3) . '/mainfile.php';
27
28
if (!\defined('XHELP_CONSTANTS_INCLUDED')) {
29
    //    require_once XOOPS_ROOT_PATH . '/modules/xhelp/include/constants.php';
30
    require_once Helper::getInstance()
31
        ->path('include/constants.php');
32
}
33
require_once \XHELP_JPSPAN_PATH . '/JPSpan.php';       // Including this sets up the JPSPAN constants
34
require_once JPSPAN . 'Server/PostOffice.php';         // Load the PostOffice server
35
//require_once XHELP_BASE_PATH . '/functions.php'; //moved functions to /Utility
36
37
// Create the PostOffice server
38
$server = new JPSpan_Server_PostOffice();
0 ignored issues
show
Bug introduced by
The type XoopsModules\Xhelp\JPSpan_Server_PostOffice was not found. Did you mean JPSpan_Server_PostOffice? If so, make sure to prefix the type with \.
Loading history...
39
$server->addHandler(new WebLib());
40
41
if (Request::hasVar('QUERY_STRING', 'SERVER') && 0 === \strcasecmp($_SERVER['QUERY_STRING'], 'client')) {
42
    // Compress the output Javascript (e.g. strip whitespace)
43
    \define('JPSPAN_INCLUDE_COMPRESS', true);
44
45
    // Display the Javascript client
46
    $server->displayClient();
47
} else {
48
    // This is where the real serving happens...
49
    // Include error handler
50
    // PHP errors, warnings and notices serialized to JS
51
    require_once JPSPAN . 'ErrorHandler.php';
52
53
    // Start serving requests...
54
    $server->serve();
55
}
56
57
/**
58
 * class ChangeSelectedState
59
 */
60
class ChangeSelectedState
61
{
62
    /**
63
     * @param int $state
64
     * @return array
65
     */
66
    public function statusesByState(int $state): array
67
    {
68
        $helper = Helper::getInstance();
69
        $state  = $state;
70
        /** @var \XoopsModules\Xhelp\StatusHandler $statusHandler */
71
        $statusHandler = $helper->getHandler('Status');
72
73
        if (-1 == $state) {   // If select all is chosen
74
            $statuses = $statusHandler->getObjects(null, true);
75
        } else {
76
            $statuses = &$statusHandler->getStatusesByState($state);
77
        }
78
        $aStatuses   = [];
79
        $aStatuses[] = [
80
            'key'   => -1,
81
            'value' => \_XHELP_TEXT_SELECT_ALL,
82
        ];
83
84
        foreach ($statuses as $status) {
85
            $aStatuses[] = [
86
                'key'   => $status->getVar('id'),
87
                'value' => $status->getVar('description'),
88
            ];
89
        }
90
91
        return $aStatuses;
92
    }
93
}
94