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