Split additional joins into multiple lines
[GitHub/WoltLab/WCF.git] / wcfsetup / install / files / lib / system / box / ProfileCommentListBoxController.class.php
1 <?php
2
3 namespace wcf\system\box;
4
5 use wcf\data\comment\ViewableCommentList;
6 use wcf\data\user\profile\comment\ViewableUserProfileComment;
7 use wcf\data\user\User;
8 use wcf\data\user\UserProfile;
9 use wcf\system\user\UserProfileHandler;
10 use wcf\system\WCF;
11
12 /**
13 * Box controller implementation for a list of comments on user profiles.
14 *
15 * @author Alexander Ebert
16 * @copyright 2001-2019 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\System\Box
19 */
20 class ProfileCommentListBoxController extends AbstractCommentListBoxController
21 {
22 /**
23 * @inheritDoc
24 */
25 protected $objectTypeName = 'com.woltlab.wcf.user.profileComment';
26
27 /**
28 * @inheritDoc
29 */
30 protected function applyObjectTypeFilters(ViewableCommentList $commentList)
31 {
32 $commentList->decoratorClassName = ViewableUserProfileComment::class;
33
34 if (WCF::getSession()->getPermission('user.profile.canViewUserProfile')) {
35 $optionID = User::getUserOptionID('canViewProfile');
36 $commentList->sqlJoins .= '
37 INNER JOIN wcf' . WCF_N . '_user_option_value user_option_value
38 ON user_option_value.userID = comment.objectID';
39
40 if (WCF::getUser()->userID) {
41 $followers = UserProfileHandler::getInstance()->getFollowers();
42 if (empty($followers)) {
43 $commentList->getConditionBuilder()->add("(
44 user_option_value.userOption{$optionID} IN (?)
45 OR user_option_value.userID = ?
46 )", [
47 [
48 UserProfile::ACCESS_EVERYONE,
49 UserProfile::ACCESS_REGISTERED,
50 ],
51 WCF::getUser()->userID,
52 ]);
53 } else {
54 $commentList->getConditionBuilder()->add("(
55 user_option_value.userOption{$optionID} IN (?)
56 OR (
57 user_option_value.userOption{$optionID} = ?
58 AND comment.objectID IN (?)
59 )
60 OR user_option_value.userID = ?
61 )", [
62 [
63 UserProfile::ACCESS_EVERYONE,
64 UserProfile::ACCESS_REGISTERED,
65 ],
66 UserProfile::ACCESS_FOLLOWING,
67 $followers,
68 WCF::getUser()->userID,
69 ]);
70 }
71 } else {
72 $commentList->getConditionBuilder()->add(
73 "user_option_value.userOption{$optionID} = ?",
74 [UserProfile::ACCESS_EVERYONE]
75 );
76 }
77 } else {
78 $commentList->getConditionBuilder()->add('0 = 1');
79 }
80 }
81 }