-
Notifications
You must be signed in to change notification settings - Fork 149
Expand file tree
/
Copy pathUserActivityEventAction.class.php
More file actions
162 lines (142 loc) · 4.83 KB
/
UserActivityEventAction.class.php
File metadata and controls
162 lines (142 loc) · 4.83 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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php
namespace wcf\data\user\activity\event;
use wcf\data\AbstractDatabaseObjectAction;
use wcf\data\box\Box;
use wcf\data\user\User;
use wcf\data\user\UserAction;
use wcf\system\box\RecentActivityListBoxController;
use wcf\system\exception\UserInputException;
use wcf\system\user\activity\event\UserActivityEventHandler;
use wcf\system\user\UserProfileHandler;
use wcf\system\WCF;
/**
* Executes user activity event-related actions.
*
* @author Alexander Ebert
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
*
* @extends AbstractDatabaseObjectAction<UserActivityEvent, UserActivityEventEditor>
*/
class UserActivityEventAction extends AbstractDatabaseObjectAction
{
/**
* @inheritDoc
*/
public $allowGuestAccess = ['load'];
/**
* @var RecentActivityListBoxController
*/
public $boxController;
/**
* Validates parameters to load recent activity entries.
*
* @return void
* @deprecated 6.3
*/
public function validateLoad()
{
$this->readInteger('boxID', true);
$this->readBoolean('filteredByFollowedUsers', true);
$this->readInteger('lastEventTime');
$this->readInteger('lastEventID', true);
$this->readInteger('userID', true);
if ($this->parameters['boxID']) {
$box = new Box($this->parameters['boxID']);
if ($box->boxID) {
$boxController = $box->getController();
if ($boxController instanceof RecentActivityListBoxController) {
// all checks passed, end validation; otherwise throw the exception below
$this->boxController = $boxController;
return;
}
}
throw new UserInputException('boxID');
}
}
/**
* Loads a list of recent activity entries.
*
* @return array{
* lastEventID: int,
* lastEventTime: int,
* template: string,
* }|array{}
* @deprecated 6.3 Use `RenderUserActivityEvents` endpoint instead.
*/
public function load()
{
if ($this->boxController !== null) {
$eventList = $this->boxController->getFilteredList();
} else {
$eventList = new ViewableUserActivityEventList();
// profile view
if ($this->parameters['userID']) {
$eventList->getConditionBuilder()->add("user_activity_event.userID = ?", [$this->parameters['userID']]);
} else {
if ($this->parameters['filteredByFollowedUsers'] && \count(UserProfileHandler::getInstance()->getFollowingUsers())) {
$eventList->getConditionBuilder()->add(
'user_activity_event.userID IN (?)',
[UserProfileHandler::getInstance()->getFollowingUsers()]
);
}
}
}
if ($this->parameters['lastEventID']) {
$eventList->getConditionBuilder()->add(
"user_activity_event.time <= ?",
[$this->parameters['lastEventTime']]
);
$eventList->getConditionBuilder()->add(
"user_activity_event.eventID < ?",
[$this->parameters['lastEventID']]
);
} else {
$eventList->getConditionBuilder()->add(
"user_activity_event.time < ?",
[$this->parameters['lastEventTime']]
);
}
$eventList->readObjects();
$lastEventTime = $eventList->getLastEventTime();
if (!$lastEventTime) {
return [];
}
// removes orphaned and non-accessible events
UserActivityEventHandler::validateEvents($eventList);
if ($this->boxController !== null) {
$eventList->truncate($this->boxController->getBox()->limit);
}
if (!\count($eventList)) {
return [];
}
// parse template
$events = $eventList->getObjects();
return [
'lastEventID' => \end($events)->eventID,
'lastEventTime' => $lastEventTime,
'template' => WCF::getTPL()->render('wcf', 'recentActivityListItem', [
'eventList' => $eventList,
]),
];
}
/**
* Does nothing.
*
* @return void
*/
public function validateSwitchContext() {}
/**
* @return void
*/
public function switchContext()
{
/** @noinspection PhpUndefinedFieldInspection */
$userAction = new UserAction([WCF::getUser()], 'update', [
'options' => [
User::getUserOptionID('recentActivitiesFilterByFollowing') => WCF::getUser()->recentActivitiesFilterByFollowing ? 0 : 1,
],
]);
$userAction->executeAction();
}
}