UserHandler::loadUserDigest()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
nc 4
nop 0
dl 0
loc 11
rs 10
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace XoopsModules\Newbb;
4
5
/**
6
 * NewBB,  the forum module for XOOPS project
7
 *
8
 * @copyright      XOOPS Project (https://xoops.org)
9
 * @license        GNU GPL 2.0 or later (https://www.gnu.org/licenses/gpl-2.0.html)
10
 * @author         Taiwen Jiang (phppp or D.J.) <[email protected]>
11
 * @since          4.00
12
 */
13
14
use XoopsModules\Newbb;
15
16
\defined('NEWBB_FUNCTIONS_INI') || require $GLOBALS['xoops']->path('modules/newbb/include/functions.ini.php');
17
18
/**
19
 * Class UserHandler
20
 */
21
class UserHandler
22
{
23
    /** @var array */
24
    public array $users = [];
25
    /**
26
     * @readonly
27
     */
28
    private bool $enableGroup = true;
29
    /**
30
     * @readonly
31
     */
32
    private bool $enableOnline = true;
33
    /** @var array */
34
    private array $userlist = [];
35
    public array $online;
36
37
    /**
38
     * @param bool $enableGroup
39
     * @param bool $enableOnline
40
     */
41
    public function __construct(bool $enableGroup = true, bool $enableOnline = true)
42
    {
43
        $this->enableGroup = $enableGroup;
44
        $this->enableOnline = $enableOnline;
45
    }
46
47
    public function loadUserInfo(): void
48
    {
49
        $helper = Helper::getInstance();
50
        $helper->loadLanguage('user');
51
        //        @require_once $GLOBALS['xoops']->path('modules/' . $GLOBALS['xoopsModule']->getVar('dirname', 'n') . '/language/' . $GLOBALS['xoopsConfig']['language'] . '/user.php');
52
        if (\class_exists('UserLanguage')) {
53
            $handler = new UserLanguage();
0 ignored issues
show
Bug introduced by
The call to XoopsModules\Newbb\UserLanguage::__construct() has too few arguments starting with user. ( Ignorable by Annotation )

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

53
            $handler = /** @scrutinizer ignore-call */ new UserLanguage();

This check compares calls to functions or methods with their respective definitions. If the call has less arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
54
        } else {
55
            $handler = new User();
56
        }
57
        foreach (\array_keys($this->users) as $uid) {
58
            $this->userlist[$uid] = $handler->getInfo($this->users[$uid]);
59
        }
60
    }
61
62
    public function loadUserOnline(): void
63
    {
64
        if (empty($this->users) || !$this->enableOnline) {
65
            return;
66
        }
67
        require_once \dirname(__DIR__) . '/include/functions.render.php';
68
        $image_online  = \newbbDisplayImage('online', \_MD_NEWBB_ONLINE);
69
        $image_offline = \newbbDisplayImage('offline', \_MD_NEWBB_OFFLINE);
70
71
        /** @var OnlineHandler $onlineHandler */
72
        $onlineHandler = Helper::getInstance()->getHandler('Online');
73
        $onlines       = $onlineHandler->checkStatus(\array_keys($this->users));
74
75
        foreach (\array_keys($this->users) as $uid) {
76
            $this->userlist[$uid]['status'] = empty($onlines[$uid]) ? $image_offline : $image_online;
77
        }
78
    }
79
80
    // START irmtfan remove function - no deprecated is needed because just use in this file
81
    //    function loadUserGroups()
82
    //    {
83
    //        return true;
84
    //    }
85
    // END irmtfan remove function - no deprecated is needed because just use in this file
86
87
    public function loadUserDigest(): void
88
    {
89
        if (empty($this->users)) {
90
            return;
91
        }
92
93
        $sql    = 'SELECT user_digests, uid FROM ' . $GLOBALS['xoopsDB']->prefix('newbb_user_stats') . ' WHERE uid IN( ' . \implode(', ', \array_keys($this->users)) . ')';
94
        $result = $GLOBALS['xoopsDB']->query($sql);
95
        if ($GLOBALS['xoopsDB']->isResultSet($result)) {
96
            while (false !== ($myrow = $GLOBALS['xoopsDB']->fetchArray($result))) {
97
                $this->userlist[$myrow['uid']]['digests'] = (int)$myrow['user_digests'];
98
            }
99
        }
100
    }
101
102
    // START irmtfan remove function
103
    //    function loadUserRank()
104
    //    {
105
    //          return true;
106
    //    }
107
    // END irmtfan remove function
108
109
    /**
110
     * @return array
111
     */
112
    public function getUsers(): array
113
    {
114
        $this->loadUserInfo();
115
        $this->loadUserOnline();
116
        // irmtfan removed $this->loadUserGroups();
117
        // irmtfan removed $this->loadUserRank();
118
        $this->loadUserDigest();
119
120
        return $this->userlist;
121
    }
122
}
123