91a70cbdc90438d62cd1a7d84e4451b3d98c5fbd
[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 // 1. fetch assigned user
34 // 2. fetch users who commented on the moderation queue entry
35 // 3. fetch users who responded to a comment on the moderation queue entry
36 $sql = "(
37 SELECT assignedUserID
38 FROM wcf".WCF_N."_moderation_queue
39 WHERE queueID = ?
40 AND assignedUserID IS NOT NULL
41 )
42 UNION
43 (
44 SELECT DISTINCT userID
45 FROM wcf".WCF_N."_comment
46 WHERE objectID = ?
47 AND objectTypeID = ?
48 )
49 UNION
50 (
51 SELECT DISTINCT comment_response.userID
52 FROM wcf".WCF_N."_comment_response comment_response
53 INNER JOIN wcf".WCF_N."_comment comment
54 ON (comment.commentID = comment_response.commentID)
55 WHERE comment.objectID = ?
56 AND comment.objectTypeID = ?
57 )";
58 $statement = WCF::getDB()->prepareStatement($sql);
59 $statement->execute([
60 $comment->objectID,
61 $comment->objectID,
62 $objectTypeID,
63 $comment->objectID,
64 $objectTypeID
65 ]);
66 $recipientIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
67
68 // make sure that all users can (still) access the moderation queue entry
69 if (!empty($recipientIDs)) {
70 $conditionBuilder = new PreparedStatementConditionBuilder();
71 $conditionBuilder->add('userID IN (?)', [$recipientIDs]);
72 $conditionBuilder->add('queueID = ?', [$comment->objectID]);
73 $conditionBuilder->add('isAffected = ?', [1]);
74 $sql = "SELECT userID
75 FROM wcf".WCF_N."_moderation_queue_to_user
76 ".$conditionBuilder;
77 $statement = WCF::getDB()->prepareStatement($sql);
78 $statement->execute($conditionBuilder->getParameters());
79 $recipientIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
80
81 // make sure that all users (still) have permission to access moderation
82 if (!$recipientIDs) {
83 UserStorageHandler::getInstance()->loadStorage($recipientIDs);
84 $userProfiles = UserProfileRuntimeCache::getInstance()->getObjects($recipientIDs);
85 $recipientIDs = array_keys(array_filter($userProfiles, function(UserProfile $userProfile) {
86 return $userProfile->getPermission('mod.general.canUseModeration');
87 }));
88 }
89 }
90
91 return $recipientIDs;
92 }
93 }