Split additional joins into multiple lines
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / box / UserTrophyListBoxController.class.php
1 <?php
2
3 namespace wcf\system\box;
4
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 *
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
19 *
20 * @property UserTrophyList $objectList
21 */
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 }
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';
85
86 // trophy category join
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';
93
94 $list->getConditionBuilder()->add('trophy.isDisabled = ?', [0]);
95 $list->getConditionBuilder()->add('category.isDisabled = ?', [0]);
96
97 if (!WCF::getUser()->userID) {
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 )');
103 } elseif (!WCF::getSession()->getPermission('admin.general.canViewPrivateUserOptions')) {
104 $conditionBuilder = new PreparedStatementConditionBuilder(false, 'OR');
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 )');
113
114 $friendshipConditionBuilder = new PreparedStatementConditionBuilder(false);
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 )');
120 $friendshipConditionBuilder->add(
121 'user_trophy.userID IN (
122 SELECT userID
123 FROM wcf' . WCF_N . '_user_follow
124 WHERE followUserID = ?
125 )',
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 }
158 }