Commit | Line | Data |
---|---|---|
dccfd5b7 | 1 | <?php |
a9229942 | 2 | |
dccfd5b7 | 3 | namespace wcf\system\box; |
a9229942 | 4 | |
dccfd5b7 JR |
5 | use wcf\data\user\trophy\UserTrophyList; |
6 | use wcf\system\cache\builder\UserOptionCacheBuilder; | |
7 | use wcf\system\cache\runtime\UserProfileRuntimeCache; | |
8 | use wcf\system\database\util\PreparedStatementConditionBuilder; | |
9 | use wcf\system\WCF; | |
10 | ||
11 | /** | |
12 | * Box controller for a list of articles. | |
13 | * | |
a9229942 TD |
14 | * @author Joshua Ruesweg |
15 | * @copyright 2001-2019 WoltLab GmbH | |
16 | * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php> | |
17 | * @package WoltLabSuite\Core\System\Box | |
18 | * @since 3.1 | |
dccfd5b7 | 19 | * |
a9229942 | 20 | * @property UserTrophyList $objectList |
dccfd5b7 | 21 | */ |
a9229942 TD |
22 | class UserTrophyListBoxController extends AbstractDatabaseObjectListBoxController |
23 | { | |
24 | /** | |
25 | * @inheritDoc | |
26 | */ | |
27 | public $defaultLimit = 10; | |
28 | ||
29 | /** | |
30 | * @inheritDoc | |
31 | */ | |
32 | public $maximumLimit = 50; | |
33 | ||
34 | /** | |
35 | * @inheritDoc | |
36 | */ | |
37 | public $minimumLimit = 3; | |
38 | ||
39 | /** | |
40 | * @inheritDoc | |
41 | */ | |
42 | protected static $supportedPositions = [ | |
43 | 'sidebarLeft', | |
44 | 'sidebarRight', | |
45 | 'contentTop', | |
46 | 'contentBottom', | |
47 | 'top', | |
48 | 'bottom', | |
49 | ]; | |
50 | ||
51 | /** | |
52 | * @inheritDoc | |
53 | */ | |
54 | public $sortOrder = 'DESC'; | |
55 | ||
56 | /** | |
57 | * @inheritDoc | |
58 | */ | |
59 | public $sortField = 'time'; | |
60 | ||
61 | /** | |
62 | * @inheritDoc | |
63 | */ | |
64 | protected $conditionDefinition = 'com.woltlab.wcf.box.userTrophyList.condition'; | |
65 | ||
66 | /** | |
67 | * @inheritDoc | |
68 | */ | |
69 | protected function getObjectList() | |
70 | { | |
71 | $list = new UserTrophyList(); | |
72 | ||
73 | if (!empty($list->sqlJoins)) { | |
74 | $list->sqlJoins .= ' '; | |
75 | } | |
76 | if (!empty($list->sqlConditionJoins)) { | |
77 | $list->sqlConditionJoins .= ' '; | |
78 | } | |
d3bd0a85 MS |
79 | $list->sqlJoins .= ' |
80 | LEFT JOIN wcf' . WCF_N . '_trophy trophy | |
81 | ON user_trophy.trophyID = trophy.trophyID'; | |
82 | $list->sqlConditionJoins .= ' | |
83 | LEFT JOIN wcf' . WCF_N . '_trophy trophy | |
84 | ON user_trophy.trophyID = trophy.trophyID'; | |
a9229942 TD |
85 | |
86 | // trophy category join | |
d3bd0a85 MS |
87 | $list->sqlJoins .= ' |
88 | LEFT JOIN wcf' . WCF_N . '_category category | |
89 | ON trophy.categoryID = category.categoryID'; | |
90 | $list->sqlConditionJoins .= ' | |
91 | LEFT JOIN wcf' . WCF_N . '_category category | |
92 | ON trophy.categoryID = category.categoryID'; | |
a9229942 TD |
93 | |
94 | $list->getConditionBuilder()->add('trophy.isDisabled = ?', [0]); | |
95 | $list->getConditionBuilder()->add('category.isDisabled = ?', [0]); | |
96 | ||
97 | if (!WCF::getUser()->userID) { | |
94d12f75 MS |
98 | $list->getConditionBuilder()->add('user_trophy.userID IN ( |
99 | SELECT userID | |
100 | FROM wcf' . WCF_N . '_user_option_value | |
101 | WHERE userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 0 | |
102 | )'); | |
a9229942 TD |
103 | } elseif (!WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) { |
104 | $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR'); | |
94d12f75 MS |
105 | $conditionBuilder->add('user_trophy.userID IN ( |
106 | SELECT userID | |
107 | FROM wcf' . WCF_N . '_user_option_value | |
108 | WHERE ( | |
109 | userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 0 | |
110 | OR userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 1 | |
111 | ) | |
112 | )'); | |
a9229942 TD |
113 | |
114 | $friendshipConditionBuilder = new PreparedStatementConditionBuilder(false); | |
94d12f75 MS |
115 | $friendshipConditionBuilder->add('user_trophy.userID IN ( |
116 | SELECT userID | |
117 | FROM wcf' . WCF_N . '_user_option_value | |
118 | WHERE userOption' . UserOptionCacheBuilder::getInstance()->getData()['options']['canViewTrophies']->optionID . ' = 2 | |
119 | )'); | |
a9229942 | 120 | $friendshipConditionBuilder->add( |
94d12f75 MS |
121 | 'user_trophy.userID IN ( |
122 | SELECT userID | |
123 | FROM wcf' . WCF_N . '_user_follow | |
124 | WHERE followUserID = ? | |
125 | )', | |
a9229942 TD |
126 | [WCF::getUser()->userID] |
127 | ); | |
128 | $conditionBuilder->add( | |
129 | '(' . $friendshipConditionBuilder . ')', | |
130 | $friendshipConditionBuilder->getParameters() | |
131 | ); | |
132 | $conditionBuilder->add('user_trophy.userID = ?', [WCF::getUser()->userID]); | |
133 | ||
134 | $list->getConditionBuilder()->add('(' . $conditionBuilder . ')', $conditionBuilder->getParameters()); | |
135 | } | |
136 | ||
137 | return $list; | |
138 | } | |
139 | ||
140 | /** | |
141 | * @inheritDoc | |
142 | */ | |
143 | public function getTemplate() | |
144 | { | |
145 | $userIDs = []; | |
146 | ||
147 | foreach ($this->objectList->getObjects() as $trophy) { | |
148 | $userIDs[] = $trophy->userID; | |
149 | } | |
150 | ||
151 | UserProfileRuntimeCache::getInstance()->cacheObjectIDs(\array_unique($userIDs)); | |
152 | ||
153 | return WCF::getTPL()->fetch('boxUserTrophyList', 'wcf', [ | |
154 | 'boxUserTrophyList' => $this->objectList, | |
155 | 'boxPosition' => $this->box->position, | |
156 | ], true); | |
157 | } | |
dccfd5b7 | 158 | } |