-
Notifications
You must be signed in to change notification settings - Fork 148
Expand file tree
/
Copy pathUserTrophyListBoxController.class.php
More file actions
162 lines (140 loc) · 4.79 KB
/
UserTrophyListBoxController.class.php
File metadata and controls
162 lines (140 loc) · 4.79 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\system\box;
use wcf\data\user\trophy\UserTrophyList;
use wcf\data\user\User;
use wcf\system\cache\runtime\UserProfileRuntimeCache;
use wcf\system\database\util\PreparedStatementConditionBuilder;
use wcf\system\WCF;
/**
* Box controller for a list of articles.
*
* @author Joshua Ruesweg
* @copyright 2001-2019 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @since 3.1
*
* @extends AbstractDatabaseObjectListBoxController<UserTrophyList>
*/
class UserTrophyListBoxController extends AbstractDatabaseObjectListBoxController
{
/**
* @inheritDoc
*/
public $defaultLimit = 10;
/**
* @inheritDoc
*/
public $maximumLimit = 50;
/**
* @inheritDoc
*/
public $minimumLimit = 3;
/**
* @inheritDoc
*/
protected static $supportedPositions = [
'sidebarLeft',
'sidebarRight',
'contentTop',
'contentBottom',
'top',
'bottom',
];
/**
* @inheritDoc
*/
public $sortOrder = 'DESC';
/**
* @inheritDoc
*/
public $sortField = 'time';
/**
* @inheritDoc
*/
protected $conditionDefinition = 'com.woltlab.wcf.box.userTrophyList.condition';
/**
* @inheritDoc
*/
protected function getObjectList()
{
$list = new UserTrophyList();
if (!empty($list->sqlJoins)) {
$list->sqlJoins .= ' ';
}
if (!empty($list->sqlConditionJoins)) {
$list->sqlConditionJoins .= ' ';
}
$list->sqlJoins .= '
LEFT JOIN wcf1_trophy trophy
ON user_trophy.trophyID = trophy.trophyID';
$list->sqlConditionJoins .= '
LEFT JOIN wcf1_trophy trophy
ON user_trophy.trophyID = trophy.trophyID';
// trophy category join
$list->sqlJoins .= '
LEFT JOIN wcf1_category category
ON trophy.categoryID = category.categoryID';
$list->sqlConditionJoins .= '
LEFT JOIN wcf1_category category
ON trophy.categoryID = category.categoryID';
$list->getConditionBuilder()->add('trophy.isDisabled = ?', [0]);
$list->getConditionBuilder()->add('category.isDisabled = ?', [0]);
$canViewTrophiesOptionID = User::getUserOptionID('canViewTrophies');
if (!WCF::getUser()->userID) {
$list->getConditionBuilder()->add('user_trophy.userID IN (
SELECT userID
FROM wcf1_user_option_value
WHERE userOption' . $canViewTrophiesOptionID . ' = 0
)');
} elseif (!WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
$conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR');
$conditionBuilder->add('user_trophy.userID IN (
SELECT userID
FROM wcf1_user_option_value
WHERE (
userOption' . $canViewTrophiesOptionID . ' = 0
OR userOption' . $canViewTrophiesOptionID . ' = 1
)
)');
$friendshipConditionBuilder = new PreparedStatementConditionBuilder(false);
$friendshipConditionBuilder->add('user_trophy.userID IN (
SELECT userID
FROM wcf1_user_option_value
WHERE userOption' . $canViewTrophiesOptionID . ' = 2
)');
$friendshipConditionBuilder->add(
'user_trophy.userID IN (
SELECT userID
FROM wcf1_user_follow
WHERE followUserID = ?
)',
[WCF::getUser()->userID]
);
$conditionBuilder->add(
'(' . $friendshipConditionBuilder . ')',
$friendshipConditionBuilder->getParameters()
);
$conditionBuilder->add('user_trophy.userID = ?', [WCF::getUser()->userID]);
$list->getConditionBuilder()->add('(' . $conditionBuilder . ')', $conditionBuilder->getParameters());
}
return $list;
}
/**
* @inheritDoc
*/
public function getTemplate()
{
$userIDs = [];
foreach ($this->objectList->getObjects() as $trophy) {
$userIDs[] = $trophy->userID;
}
UserProfileRuntimeCache::getInstance()->cacheObjectIDs(\array_unique($userIDs));
$templateName = match ($this->getBox()->position) {
'sidebarLeft', 'sidebarRight' => 'boxUserTrophyListSidebar',
default => 'boxUserTrophyList',
};
return WCF::getTPL()->render('wcf', $templateName, [
'boxUserTrophyList' => $this->objectList,
]);
}
}