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