Merge pull request #5989 from WoltLab/wsc-rpc-api-const
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / page / UsersOnlineListPage.class.php
CommitLineData
320f4a6d 1<?php
a9229942 2
320f4a6d 3namespace wcf\page;
a9229942 4
cccad2a0
MS
5use wcf\data\page\PageCache;
6use wcf\data\user\online\UserOnline;
7use wcf\data\user\online\UsersOnlineList;
cccad2a0 8use wcf\system\page\handler\IOnlineLocationPageHandler;
ac4ff35d 9use wcf\system\page\PageLocationManager;
320f4a6d 10use wcf\system\request\LinkHandler;
320f4a6d 11use wcf\system\WCF;
909b697f 12use wcf\util\HeaderUtil;
320f4a6d
MW
13
14/**
15 * Shows page which lists all users who are online.
a9229942
TD
16 *
17 * @author Marcel Werk
18 * @copyright 2001-2019 WoltLab GmbH
19 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
a9229942
TD
20 *
21 * @property UsersOnlineList $objectList
320f4a6d 22 */
a9229942
TD
23class UsersOnlineListPage extends SortablePage
24{
25 /**
26 * @inheritDoc
27 */
28 public $neededPermissions = ['user.profile.canViewUsersOnlineList'];
29
30 /**
31 * @inheritDoc
32 */
33 public $itemsPerPage = 100;
34
35 /**
36 * @inheritDoc
37 */
38 public $defaultSortField = USERS_ONLINE_DEFAULT_SORT_FIELD;
39
40 /**
41 * @inheritDoc
42 */
43 public $defaultSortOrder = USERS_ONLINE_DEFAULT_SORT_ORDER;
44
45 /**
46 * @inheritDoc
47 */
48 public $validSortFields = ['username', 'lastActivityTime', 'requestURI'];
49
50 /**
51 * @inheritDoc
52 */
53 public $objectListClassName = UsersOnlineList::class;
54
55 /**
56 * page locations
57 * @var array
58 */
59 public $locations = [];
60
61 /**
62 * @inheritDoc
63 */
64 public function readParameters()
65 {
66 parent::readParameters();
67
68 if (WCF::getSession()->getPermission('admin.user.canViewIpAddress')) {
69 $this->validSortFields[] = 'ipAddress';
70 $this->validSortFields[] = 'userAgent';
71 }
72
73 if (!empty($_POST)) {
74 HeaderUtil::redirect(LinkHandler::getInstance()->getLink(
75 'UsersOnlineList',
76 [],
77 'sortField=' . $this->sortField . '&sortOrder=' . $this->sortOrder
78 ));
79
80 exit;
81 }
82 }
83
84 /**
85 * @inheritDoc
86 */
87 protected function initObjectList()
88 {
89 parent::initObjectList();
90 $this->objectList->readStats();
91 $this->objectList->checkRecord();
92
93 if (!USERS_ONLINE_SHOW_ROBOTS) {
e2542b4c 94 $this->objectList->getConditionBuilder()->add('session.spiderIdentifier IS NULL');
a9229942
TD
95 }
96 if (!USERS_ONLINE_SHOW_GUESTS) {
97 if (USERS_ONLINE_SHOW_ROBOTS) {
e2542b4c 98 $this->objectList->getConditionBuilder()->add('(session.userID IS NOT NULL OR session.spiderIdentifier IS NOT NULL)');
a9229942
TD
99 } else {
100 $this->objectList->getConditionBuilder()->add('session.userID IS NOT NULL');
101 }
102 }
103
104 $this->objectList->sqlSelects .= ", CASE WHEN session.userID IS NULL THEN 1 ELSE 0 END AS userIsGuest";
e2542b4c 105 $this->objectList->sqlSelects .= ", CASE WHEN session.spiderIdentifier IS NOT NULL THEN 1 ELSE 0 END AS userIsRobot";
a9229942
TD
106 }
107
108 /**
109 * @inheritDoc
110 */
111 public function readData()
112 {
113 parent::readData();
114
115 // add breadcrumbs
116 if (MODULE_MEMBERS_LIST) {
117 PageLocationManager::getInstance()->addParentLocation('com.woltlab.wcf.MembersList');
118 }
119
120 // cache all necessary data for showing locations
121 foreach ($this->objectList as $userOnline) {
122 $page = PageCache::getInstance()->getPage($userOnline->pageID);
123 if ($page !== null && $page->getHandler() !== null && $page->getHandler() instanceof IOnlineLocationPageHandler) {
124 /** @noinspection PhpUndefinedMethodInspection */
125 $page->getHandler()->prepareOnlineLocation($page, $userOnline);
126 }
127 }
128
129 // set locations
130 /** @var UserOnline $userOnline */
131 foreach ($this->objectList as $userOnline) {
132 $userOnline->setLocation();
133 }
134 }
135
136 /**
137 * @inheritDoc
138 */
139 protected function readObjects()
140 {
141 if ($this->sqlOrderBy) {
142 $this->sqlOrderBy = ($this->sortField == 'lastActivityTime' ? 'session.' : '') . $this->sqlOrderBy;
143 }
144
145 $originalSqlOrderBy = $this->sqlOrderBy;
146 // sort in this order: users -> guests -> robots
147 $this->sqlOrderBy = "userIsGuest ASC, userIsRobot DESC, " . $this->sqlOrderBy;
148
149 parent::readObjects();
150
151 // restore original order
152 $this->sqlOrderBy = $originalSqlOrderBy;
153 }
320f4a6d 154}