6ce729ab45ea8d34b3d03712c04843456634a73c
[GitHub/WoltLab/WCF.git] /
1 <?php
2 namespace wcf\system\user\notification\object\type;
3 use wcf\data\comment\Comment;
4 use wcf\data\user\UserProfile;
5 use wcf\system\cache\runtime\UserProfileRuntimeCache;
6 use wcf\system\comment\CommentHandler;
7 use wcf\system\database\util\PreparedStatementConditionBuilder;
8 use wcf\system\user\storage\UserStorageHandler;
9 use wcf\system\WCF;
10
11 /**
12 * Implements IMultiRecipientCommentUserNotificationObjectType::getRecipientIDs()
13 * for moderation queue comment user notification object types.
14 *
15 * @author Mathias Schmidt
16 * @copyright 2001-2016 WoltLab GmbH
17 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
18 * @package WoltLabSuite\Core\System\User\Notification\Object\Type
19 * @since 3.0
20 */
21 trait TMultiRecipientModerationQueueCommentUserNotificationObjectType {
22 /**
23 * @inheritDoc
24 */
25 public function getRecipientIDs(Comment $comment) {
26 $objectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue');
27 if ($comment->objectTypeID != $objectTypeID) {
28 return [];
29 }
30
31 // 1. fetch assigned user
32 // 2. fetch users who commented on the moderation queue entry
33 // 3. fetch users who responded to a comment on the moderation queue entry
34 $sql = "(
35 SELECT assignedUserID
36 FROM wcf".WCF_N."_moderation_queue
37 WHERE queueID = ?
38 AND assignedUserID IS NOT NULL
39 )
40 UNION
41 (
42 SELECT DISTINCT userID
43 FROM wcf".WCF_N."_comment
44 WHERE objectID = ?
45 AND objectTypeID = ?
46 )
47 UNION
48 (
49 SELECT DISTINCT comment_response.userID
50 FROM wcf".WCF_N."_comment_response comment_response
51 INNER JOIN wcf".WCF_N."_comment comment
52 ON (comment.commentID = comment_response.commentID)
53 WHERE comment.objectID = ?
54 AND comment.objectTypeID = ?
55 )";
56 $statement = WCF::getDB()->prepareStatement($sql);
57 $statement->execute([
58 $comment->objectID,
59 $comment->objectID,
60 $objectTypeID,
61 $comment->objectID,
62 $objectTypeID
63 ]);
64 $recipientIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
65
66 // make sure that all users can (still) access the moderation queue entry
67 if (!empty($recipientIDs)) {
68 $conditionBuilder = new PreparedStatementConditionBuilder();
69 $conditionBuilder->add('userID IN (?)', [$recipientIDs]);
70 $conditionBuilder->add('queueID = ?', [$comment->objectID]);
71 $conditionBuilder->add('isAffected = ?', [1]);
72 $sql = "SELECT userID
73 FROM wcf".WCF_N."_moderation_queue_to_user
74 ".$conditionBuilder;
75 $statement = WCF::getDB()->prepareStatement($sql);
76 $statement->execute($conditionBuilder->getParameters());
77 $recipientIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
78
79 // make sure that all users (still) have permission to access moderation
80 if (!$recipientIDs) {
81 UserStorageHandler::getInstance()->loadStorage($recipientIDs);
82 $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($recipientIDs);
83 $recipientIDs = array_keys(array_filter($userProfiles, function(UserProfile $userProfile) {
84 return $userProfile->getPermission('mod.general.canUseModeration');
85 }));
86 }
87 }
88
89 return $recipientIDs;
90 }
91 }