-
Notifications
You must be signed in to change notification settings - Fork 147
Expand file tree
/
Copy pathWhoWasOnlineBoxController.class.php
More file actions
124 lines (107 loc) · 3 KB
/
WhoWasOnlineBoxController.class.php
File metadata and controls
124 lines (107 loc) · 3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
<?php
namespace wcf\system\box;
use wcf\data\DatabaseObject;
use wcf\data\DatabaseObjectList;
use wcf\data\user\online\UserOnline;
use wcf\data\user\online\UsersOnlineList;
use wcf\data\user\UserProfile;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\cache\tolerant\WhoWasOnlineCache;
use wcf\system\event\EventHandler;
use wcf\system\WCF;
use wcf\util\DateUtil;
/**
* Box controller for a list of registered users that visited the website in last 24 hours.
*
* @author Marcel Werk
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 3.0
*
* @extends AbstractDatabaseObjectListBoxController<DatabaseObjectList<DatabaseObject>>
*/
class WhoWasOnlineBoxController extends AbstractDatabaseObjectListBoxController
{
/**
* @inheritDoc
*/
protected static $supportedPositions = ['footerBoxes', 'sidebarLeft', 'sidebarRight'];
/**
* @inheritDoc
*/
protected $sortFieldLanguageItemPrefix = 'wcf.user.sortField';
/**
* @inheritDoc
*/
public $validSortFields = [
'username',
'lastActivityTime',
];
/**
* users loaded from cache
* @var UserProfile[]
*/
public $users = [];
/**
* @inheritDoc
*/
protected function getObjectList()
{
return null;
}
/**
* @inheritDoc
*/
protected function getTemplate()
{
return WCF::getTPL()->render('wcf', 'boxWhoWasOnline', [
'whoWasOnlineList' => $this->users,
'whoWasOnlineTimeFormat' => DateUtil::TIME_FORMAT,
]);
}
/**
* @inheritDoc
*/
public function hasContent()
{
if (!MODULE_USERS_ONLINE || !WCF::getSession()->getPermission('user.profile.canViewUsersOnlineList')) {
return false;
}
parent::hasContent();
return \count($this->users) > 0;
}
/**
* @inheritDoc
*/
protected function loadContent()
{
$this->readObjects();
$this->content = $this->getTemplate();
}
/**
* @inheritDoc
*/
protected function readObjects()
{
EventHandler::getInstance()->fireAction($this, 'readObjects');
$userIDs = (new WhoWasOnlineCache())->getCache();
if (!empty($userIDs)) {
$this->users = \array_filter(
UserProfileRuntimeCache::getInstance()->getObjects($userIDs),
static function ($user) {
return $user !== null;
}
);
foreach ($this->users as $key => $user) {
// remove invisible users
if (!UsersOnlineList::isVisibleUser(new UserOnline($user->getDecoratedObject()))) {
unset($this->users[$key]);
}
}
// sort users
if (!empty($this->users)) {
DatabaseObject::sort($this->users, $this->sortField, $this->sortOrder);
}
}
}
}