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;
13 * Implements IMultiRecipientCommentUserNotificationObjectType::getRecipientIDs()
14 * for moderation queue comment user notification object types.
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
22 trait TMultiRecipientModerationQueueCommentUserNotificationObjectType {
26 public function getRecipientIDs(Comment $comment) {
27 $objectTypeID = CommentHandler::getInstance()->getObjectTypeID('com.woltlab.wcf.moderation.queue');
28 if ($comment->objectTypeID != $objectTypeID) {
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
37 FROM wcf".WCF_N."_moderation_queue
39 AND assignedUserID IS NOT NULL
43 SELECT DISTINCT userID
44 FROM wcf".WCF_N."_comment
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 = ?
57 $statement = WCF::getDB()->prepareStatement($sql);
65 $recipientIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
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]);
74 FROM wcf".WCF_N."_moderation_queue_to_user
76 $statement = WCF::getDB()->prepareStatement($sql);
77 $statement->execute($conditionBuilder->getParameters());
78 $recipientIDs = $statement->fetchAll(\PDO::FETCH_COLUMN);
80 // make sure that all users (still) have permission to access moderation
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');