/** * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare() */ public function prepare(array $events) { $responseIDs = array(); foreach ($events as $event) { $responseIDs[] = $event->objectID; } $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); $commentIDs = $comments = array(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } if (!empty($commentIDs)) { $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); } // fetch news entries $entryIDs = $entry = array(); foreach ($comments as $comment) { $entryIDs[] = $comment->objectID; } if (!empty($entryIDs)) { $entryList = new ViewableEntryList(); $entryList->getConditionBuilder()->add("news_entry.entryID IN (?)", array($entryIDs)); $entryList->readObjects(); $entry = $entryList->getObjects(); } $userIDs = $user = array(); foreach ($comments as $comment) { $userIDs[] = $comment->userID; } if (!empty($userIDs)) { $userList = new UserList(); $userList->getConditionBuilder()->add("user_table.userID IN (?)", array($userIDs)); $userList->readObjects(); $users = $userList->getObjects(); } foreach ($events as $event) { if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; $comment = $comments[$response->commentID]; if (isset($entry[$comment->objectID]) && isset($users[$comment->userID])) { $newsEntry = $entry[$comment->objectID]; if (!$newsEntry->canRead()) { continue; } $event->setIsAccessible(); $text = WCF::getLanguage()->getDynamicVariable('cms.recentActivity.newsCommentResponse', array('commentAuthor' => $users[$comment->userID], 'entry' => $newsEntry)); $event->setTitle($text); $event->setDescription($response->getExcerpt()); continue; } } $event->setIsOrphaned(); } }
/** * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare() */ public function prepare(array $events) { if (!WCF::getSession()->getPermission('user.profile.canViewUserProfile')) { return; } $responses = $responseIDs = array(); foreach ($events as $event) { $responseIDs[] = $event->objectID; } // fetch responses $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); // fetch comments $commentIDs = $comments = array(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } if (!empty($commentIDs)) { $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); } // fetch users $userIDs = $users = array(); foreach ($comments as $comment) { $userIDs[] = $comment->objectID; $userIDs[] = $comment->userID; } if (!empty($userIDs)) { $userList = new UserProfileList(); $userList->getConditionBuilder()->add("user_table.userID IN (?)", array($userIDs)); $userList->readObjects(); $users = $userList->getObjects(); } // set message foreach ($events as $event) { if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; $comment = $comments[$response->commentID]; if (isset($users[$comment->objectID]) && isset($users[$comment->userID])) { if (!$users[$comment->objectID]->isProtected()) { $event->setIsAccessible(); // title $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.profileCommentResponse', array('commentAuthor' => $users[$comment->userID], 'user' => $users[$comment->objectID])); $event->setTitle($text); // description $event->setDescription($response->getExcerpt()); } continue; } } $event->setIsOrphaned(); } }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); // get user ids $userIDs = array(); foreach ($this->objects as &$response) { if (!$this->minResponseTime || $response->time < $this->minResponseTime) { $this->minResponseTime = $response->time; } $userIDs[] = $response->userID; $response = new StructuredCommentResponse($response); $response->setIsDeletable($this->commentManager->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject())); } unset($response); // fetch user data and avatars if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $response) { if (isset($users[$response->userID])) { $response->setUserProfile($users[$response->userID]); } } } }
public function prepare(array $events) { $objectIDs = array(); foreach ($events as $event) { $objectIDs[] = $event->objectID; } // comments responses $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($objectIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); // comments $commentIDs = array(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); // get news $newsIDs = array(); foreach ($comments as $comment) { $newsIDs[] = $comment->objectID; } $list = new NewsList(); $list->getConditionBuilder()->add("news.newsID IN (?)", array($newsIDs)); $list->readObjects(); $newss = $list->getObjects(); foreach ($events as $event) { if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; if (isset($comments[$response->commentID])) { $comment = $comments[$response->commentID]; if (isset($newss[$comment->objectID])) { $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.newsCommentResponse', array('author' => new User($comment->userID), 'news' => $newss[$comment->objectID])); $event->setTitle($text); $event->setDescription($response->getFormattedMessage()); $event->setIsAccessible(); } } } else { $event->setIsOrphaned(); } } }
/** * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare() */ public function prepare(array $events) { $commentsIDs = $responseIDs = $userIDs = array(); foreach ($events as $event) { $responseIDs[] = $event->objectID; } $responseList = new CommentResponseList(); $responseList->setObjectIDs($responseIDs); $responseList->readObjects(); $responses = $responseList->getObjects(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } $commentList = new CommentList(); $commentList->setObjectIDs($commentIDs); $commentList->readObjects(); $comments = $commentList->getObjects(); foreach ($comments as $comment) { if (!in_array($comment->userID, $userIDs)) { $userIDs[] = $comment->userID; } } $userList = new UserList(); $userList->setObjectIDs($userIDs); $userList->readObjects(); $users = $userList->getObjects(); foreach ($events as $event) { if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; $comment = $comments[$response->commentID]; $page = PageCache::getInstance()->getPage($comment->objectID); if ($page !== null && isset($users[$comment->userID])) { if (!$page->canRead()) { continue; } $event->setIsAccessible(); $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.pageCommentResponse', array('author' => $users[$comment->userID], 'page' => $pages[$comment->objectID])); $event->setTitle($text); $event->setDescription($response->getFormattedMessage()); continue; } } else { $event->setIsOrphaned(); } } }
/** * @see \wcf\system\user\activity\event\IUserActivityEvent::prepare() */ public function prepare(array $events) { $responseIDs = array(); foreach ($events as $event) { $responseIDs[] = $event->objectID; } // fetch responses $responseList = new CommentResponseList(); $responseList->setObjectIDs($responseIDs); $responseList->readObjects(); $responses = $responseList->getObjects(); // fetch comments $commentIDs = $comments = array(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } if (!empty($commentIDs)) { $commentList = new CommentList(); $commentList->setObjectIDs($commentIDs); $commentList->readObjects(); $comments = $commentList->getObjects(); } // fetch entries $entryIDs = $entries = array(); foreach ($comments as $comment) { $entryIDs[] = $comment->objectID; } if (!empty($entryIDs)) { $entryList = new EntryList(); $entryList->setObjectIDs($entryIDs); $entryList->readObjects(); $entries = $entryList->getObjects(); } // fetch users $userIDs = $user = array(); foreach ($comments as $comment) { $userIDs[] = $comment->userID; } if (!empty($userIDs)) { $userList = new UserList(); $userList->setObjectIDs($userIDs); $userList->readObjects(); $users = $userList->getObjects(); } // set message foreach ($events as $event) { if (isset($responses[$event->objectID])) { $response = $responses[$event->objectID]; $comment = $comments[$response->commentID]; if (isset($entries[$comment->objectID]) && isset($users[$comment->userID])) { $entry = $entries[$comment->objectID]; // check permissions if (!$entry->canRead()) { continue; } $event->setIsAccessible(); // title $text = WCF::getLanguage()->getDynamicVariable('linklist.recentActivity.entryCommentResponse', array('commentAuthor' => $users[$comment->userID], 'entry' => $entry)); $event->setTitle($text); // description $event->setDescription($response->getExcerpt()); continue; } } $event->setIsOrphaned(); } }
/** * Removes all comments for given objects. * * @param string $objectType * @param array<integer> $objectIDs */ public function deleteObjects($objectType, array $objectIDs) { $objectTypeID = $this->getObjectTypeID($objectType); $objectTypeObj = $this->getObjectType($objectTypeID); // get comment ids $commentList = new CommentList(); $commentList->getConditionBuilder()->add('comment.objectTypeID = ?', array($objectTypeID)); $commentList->getConditionBuilder()->add('comment.objectID IN (?)', array($objectIDs)); $commentList->readObjectIDs(); $commentIDs = $commentList->getObjectIDs(); // no comments -> skip if (empty($commentIDs)) { return; } // get response ids $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add('comment_response.commentID IN (?)', array($commentIDs)); $responseList->readObjectIDs(); $responseIDs = $responseList->getObjectIDs(); // delete likes $notificationObjectTypes = array(); if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.like.notification')) { $notificationObjectTypes[] = $objectTypeObj->objectType . '.like.notification'; } LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $commentIDs, $notificationObjectTypes); // delete activity events if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.recentActivityEvent', $commentIDs); } // delete notifications if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectTypeObj->objectType . '.notification', $commentIDs); } if (!empty($responseIDs)) { // delete likes (for responses) $notificationObjectTypes = array(); if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.like.notification')) { $notificationObjectTypes[] = $objectTypeObj->objectType . '.response.like.notification'; } LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $responseIDs, $notificationObjectTypes); // delete activity events (for responses) if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectTypeObj->objectType . '.response.recentActivityEvent', $responseIDs); } // delete notifications (for responses) if (UserNotificationHandler::getInstance()->getObjectTypeID($objectTypeObj->objectType . '.response.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectTypeObj->objectType . '.response.notification', $responseIDs); } } // delete comments / responses CommentEditor::deleteAll($commentIDs); }
/** * @see \wcf\system\moderation\queue\IModerationQueueHandler::populate() */ public function populate(array $queues) { $objectIDs = array(); foreach ($queues as $object) { $objectIDs[] = $object->objectID; } // fetch responses $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($objectIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); // fetch comments $commentIDs = array(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; } if (!empty($commentIDs)) { $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); } foreach ($queues as $object) { if (isset($responses[$object->objectID])) { $response = $responses[$object->objectID]; $response->setComment($comments[$response->commentID]); $object->setAffectedObject($response); } else { $object->setIsOrphaned(); } } }
/** * @see \wcf\system\like\IViewableLikeProvider::prepare() */ public function prepare(array $likes) { if (!WCF::getSession()->getPermission('user.news.canReadEntry')) { return; } $commentLikeObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.like.likeableObject', 'com.woltlab.wcf.comment'); $commentIDs = $responseIDs = array(); foreach ($likes as $like) { if ($like->objectTypeID == $commentLikeObjectType->objectTypeID) { $commentIDs[] = $like->objectID; } else { $responseIDs[] = $like->objectID; } } // fetch response $userIDs = $responses = array(); if (!empty($responseIDs)) { $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array($responseIDs)); $responseList->readObjects(); $responses = $responseList->getObjects(); foreach ($responses as $response) { $commentIDs[] = $response->commentID; if ($response->userID) { $userIDs[] = $response->userID; } } } // fetch comments $commentList = new CommentList(); $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs)); $commentList->readObjects(); $comments = $commentList->getObjects(); // fetch users $users = array(); $entryIDs = array(); foreach ($comments as $comment) { $entryIDs[] = $comment->objectID; if ($comment->userID) { $userIDs[] = $comment->userID; } } if (!empty($userIDs)) { $users = UserProfile::getUserProfiles(array_unique($userIDs)); } $entries = array(); if (!empty($entryIDs)) { $entryList = new EntryList(); $entryList->setObjectIDs($entryIDs); $entryList->readObjects(); $entries = $entryList->getObjects(); } // set message foreach ($likes as $like) { if ($like->objectTypeID == $commentLikeObjectType->objectTypeID) { // comment like if (isset($comments[$like->objectID])) { $comment = $comments[$like->objectID]; if (isset($entries[$comment->objectID]) && $entries[$comment->objectID]->canRead()) { $like->setIsAccessible(); // short output $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.de.incendium.cms.news.comment', array('commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'entry' => $entries[$comment->objectID], 'like' => $like)); $like->setTitle($text); // output $like->setDescription($comment->getExcerpt()); } } } else { // response like if (isset($responses[$like->objectID])) { $response = $responses[$like->objectID]; $comment = $comments[$response->commentID]; if (isset($entries[$comment->objectID]) && $entries[$comment->objectID]->canRead()) { $like->setIsAccessible(); // short output $text = WCF::getLanguage()->getDynamicVariable('wcf.like.title.de.incendium.cms.news.comment.response', array('responseAuthor' => $comment->userID ? $users[$response->userID] : null, 'commentAuthor' => $comment->userID ? $users[$comment->userID] : null, 'entry' => $entries[$comment->objectID], 'like' => $like)); $like->setTitle($text); // output $like->setDescription($response->getExcerpt()); } } } } }
/** * @see \wcf\data\DatabaseObjectList::readObjects() */ public function readObjects() { parent::readObjects(); // fetch response ids $responseIDs = $userIDs = array(); foreach ($this->objects as &$comment) { if (!$this->minCommentTime || $comment->time < $this->minCommentTime) { $this->minCommentTime = $comment->time; } $commentResponseIDs = $comment->getResponseIDs(); foreach ($commentResponseIDs as $responseID) { $this->responseIDs[] = $responseID; $responseIDs[$responseID] = $comment->commentID; } if ($comment->userID) { $userIDs[] = $comment->userID; } $comment = new StructuredComment($comment); $comment->setIsDeletable($this->commentManager->canDeleteComment($comment->getDecoratedObject())); $comment->setIsEditable($this->commentManager->canEditComment($comment->getDecoratedObject())); } unset($comment); // fetch last responses if (!empty($responseIDs)) { $responseList = new CommentResponseList(); $responseList->getConditionBuilder()->add("comment_response.responseID IN (?)", array(array_keys($responseIDs))); $responseList->readObjects(); foreach ($responseList as $response) { $response = new StructuredCommentResponse($response); $response->setIsDeletable($this->commentManager->canDeleteResponse($response->getDecoratedObject())); $response->setIsEditable($this->commentManager->canEditResponse($response->getDecoratedObject())); $commentID = $responseIDs[$response->responseID]; $this->objects[$commentID]->addResponse($response); if ($response->userID) { $userIDs[] = $response->userID; } } } // fetch user data and avatars if (!empty($userIDs)) { $userIDs = array_unique($userIDs); $users = UserProfile::getUserProfiles($userIDs); foreach ($this->objects as $comment) { if ($comment->userID && isset($users[$comment->userID])) { $comment->setUserProfile($users[$comment->userID]); } foreach ($comment as $response) { if ($response->userID && isset($users[$response->userID])) { $response->setUserProfile($users[$response->userID]); } } } } }
/** * @see \wcf\data\AbstractDatabaseObjectAction::delete() */ public function delete() { if (empty($this->objects)) { $this->readObjects(); } // update counters $processors = array(); $groupCommentIDs = $commentIDs = array(); foreach ($this->objects as $comment) { if (!isset($processors[$comment->objectTypeID])) { $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID); $processors[$comment->objectTypeID] = $objectType->getProcessor(); $groupCommentIDs[$comment->objectTypeID] = array(); } $processors[$comment->objectTypeID]->updateCounter($comment->objectID, -1 * ($comment->responses + 1)); $groupCommentIDs[$comment->objectTypeID][] = $comment->commentID; $commentIDs[] = $comment->commentID; } if (!empty($groupCommentIDs)) { $likeObjectIDs = array(); $notificationObjectTypes = array(); foreach ($groupCommentIDs as $objectTypeID => $objectIDs) { // remove activity events $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID); if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.recentActivityEvent')) { UserActivityEventHandler::getInstance()->removeEvents($objectType->objectType . '.recentActivityEvent', $objectIDs); } $likeObjectIDs = array_merge($likeObjectIDs, $objectIDs); // delete notifications $objectType = ObjectTypeCache::getInstance()->getObjectType($comment->objectTypeID); if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.notification')) { UserNotificationHandler::getInstance()->removeNotifications($objectType->objectType . '.notification', $objectIDs); } if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.like.notification')) { $notificationObjectTypes[] = $objectType->objectType . '.like.notification'; } } // remove likes LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment', $likeObjectIDs, $notificationObjectTypes); } // delete responses if (!empty($commentIDs)) { $commentResponseList = new CommentResponseList(); $commentResponseList->getConditionBuilder()->add('comment_response.commentID IN (?)', array($commentIDs)); $commentResponseList->readObjectIDs(); if (count($commentResponseList->getObjectIDs())) { $action = new CommentResponseAction($commentResponseList->getObjectIDs(), 'delete', array('ignoreCounters' => true)); $action->executeAction(); } } return parent::delete(); }