884dc21266956dc4830a1bd08b58469daa5ed5f9
[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 com.woltlab.wcf
19 * @subpackage system.user.notification.object.type
20 * @category Community Framework
21 * @since 2.2
22 */
23 trait TMultiRecipientModerationQueueCommentUserNotificationObjectType {
24 /**
25 * @see IMultiRecipientCommentUserNotificationObjectType::getRecipientIDs()
26 */
27 public function getRecipientIDs(Comment $comment) {
28 $objectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue');
29 if ($comment->objectTypeID != $objectTypeID) {
30 return [];
31 }
32
33 $recipientIDs = [];
34
35 // 1. fetch assigned user
36 // 2. fetch users who commented on the moderation queue entry
37 // 3. fetch users who responded to a comment on the moderation queue entry
38 $sql = "(
39 SELECT assignedUserID
40 FROM wcf".WCF_N."_moderation_queue
41 WHERE queueID = ?
42 AND assignedUserID IS NOT NULL
43 )
44 UNION
45 (
46 SELECT DISTINCT userID
47 FROM wcf".WCF_N."_comment
48 WHERE objectID = ?
49 AND objectTypeID = ?
50 )
51 UNION
52 (
53 SELECT DISTINCT comment_response.userID
54 FROM wcf".WCF_N."_comment_response comment_response
55 INNER JOIN wcf".WCF_N."_comment comment
56 ON (comment.commentID = comment_response.commentID)
57 WHERE comment.objectID = ?
58 AND comment.objectTypeID = ?
59 )";
60 $statement = WCF::getDB()->prepareStatement($sql);
61 $statement->execute([
62 $comment->objectID,
63 $comment->objectID,
64 $objectTypeID,
65 $comment->objectID,
66 $objectTypeID
67 ]);
68 while ($userID = $statement->fetchColumn()) {
69 $recipientIDs[] = $userID;
70 }
71
72 // make sure that all users can (still) access the moderation queue entry
73 if (!empty($recipientIDs)) {
74 $conditionBuilder = new PreparedStatementConditionBuilder();
75 $conditionBuilder->add('userID IN (?)', [$recipientIDs]);
76 $conditionBuilder->add('queueID = ?', [$comment->objectID]);
77 $conditionBuilder->add('isAffected = ?', [1]);
78 $sql = "SELECT userID
79 FROM wcf".WCF_N."_moderation_queue_to_user
80 ".$conditionBuilder;
81 $statement = WCF::getDB()->prepareStatement($sql);
82 $statement->execute($conditionBuilder->getParameters());
83
84 $recipientIDs = [];
85 while ($userID = $statement->fetchColumn()) {
86 $recipientIDs[] = $userID;
87 }
88
89 // make sure that all users (still) have permission to access moderation
90 if (!$recipientIDs) {
91 UserStorageHandler::getInstance()->loadStorage($recipientIDs);
92 $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($recipientIDs);
93 $recipientIDs = array_keys(array_filter($userProfiles, function(UserProfile $userProfile) {
94 return $userProfile->getPermission('mod.general.canUseModeration');
95 }));
96 }
97 }
98
99 return $recipientIDs;
100 }
101 }