public function prepare(array $events)
 {
     $objectIDs = array();
     foreach ($events as $event) {
         $objectIDs[] = $event->objectID;
     }
     // comments
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($objectIDs));
     $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($comments[$event->objectID])) {
             $comment = $comments[$event->objectID];
             if (isset($newss[$comment->objectID])) {
                 $news = $newss[$comment->objectID];
                 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.newsComment', array('news' => $news));
                 $event->setTitle($text);
                 $event->setDescription($comment->getFormattedMessage());
                 $event->setIsAccessible();
             }
         } else {
             $event->setIsOrphaned();
         }
     }
 }
 /**
  * @see	\wcf\system\like\IViewableLikeProvider::prepare()
  */
 public function prepare(array $likes)
 {
     $commentIDs = array();
     foreach ($likes as $like) {
         $commentIDs[] = $like->objectID;
     }
     // fetch comments
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     // group likes by object type id
     $likeData = array();
     foreach ($likes as $like) {
         if (isset($comments[$like->objectID])) {
             if (!isset($likeData[$comments[$like->objectID]->objectTypeID])) {
                 $likeData[$comments[$like->objectID]->objectTypeID] = array();
             }
             $likeData[$comments[$like->objectID]->objectTypeID][] = $like;
         }
     }
     foreach ($likeData as $objectTypeID => $likes) {
         $objectType = CommentHandler::getInstance()->getObjectType($objectTypeID);
         if (CommentHandler::getInstance()->getCommentManager($objectType->objectType) instanceof IViewableLikeProvider) {
             CommentHandler::getInstance()->getCommentManager($objectType->objectType)->prepare($likes);
         }
     }
 }
 /**
  * @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)
 {
     $commentIDs = array();
     foreach ($events as $event) {
         $commentIDs[] = $event->objectID;
     }
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add('comment.commentID IN (?)', array($objectIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     foreach ($events as $event) {
         if (isset($comments[$event->objectID])) {
             $comment = $comments[$event->objectID];
             $page = PageCache::getInstance()->getPage($comment->objectID);
             if ($page !== null) {
                 if (!$page->canRead()) {
                     continue;
                 }
                 $event->setIsAccessible();
                 $text = WCF::getLanguage()->getDynamicVariable('wcf.user.profile.recentActivity.pageComment', array('page' => $page));
                 $event->setTitle($text);
                 $event->setDescription($comment->getFormattedMessage());
                 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();
     }
 }
 /**
  * Returns a comment by id, fetches comments on first call.
  * 
  * @param	integer		$commentID
  * @return	\wcf\data\comment\Comment
  */
 public function getComment($commentID)
 {
     if (!empty($this->commentIDs)) {
         $this->commentIDs = array_diff($this->commentIDs, array_keys($this->comments));
         if (!empty($this->commentIDs)) {
             $commentList = new CommentList();
             $commentList->setObjectIDs($this->commentIDs);
             $commentList->readObjects();
             $this->comments += $commentList->getObjects();
             $this->commentIDs = array();
         }
     }
     if (isset($this->comments[$commentID])) {
         return $this->comments[$commentID];
     }
     return null;
 }
 /**
  * @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)
 {
     $comentIDs = array();
     foreach ($events as $event) {
         $comentIDs[] = $event->objectID;
     }
     // fetch comments
     $commentList = new CommentList();
     $commentList->setObjectIDs($comentIDs);
     $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();
     }
     // set message
     foreach ($events as $event) {
         if (isset($comments[$event->objectID])) {
             $comment = $comments[$event->objectID];
             if (isset($entries[$comment->objectID])) {
                 $entry = $entries[$comment->objectID];
                 // check permissions
                 if (!$entry->canRead()) {
                     continue;
                 }
                 $event->setIsAccessible();
                 // add title
                 $text = WCF::getLanguage()->getDynamicVariable('linklist.recentActivity.entryComment', array('entry' => $entry));
                 $event->setTitle($text);
                 // add text
                 $event->setDescription($comment->getExcerpt());
                 continue;
             }
         }
         $event->setIsOrphaned();
     }
 }
 /**
  * @see	\wcf\system\user\activity\event\IUserActivityEvent::prepare()
  */
 public function prepare(array $events)
 {
     $comentIDs = array();
     foreach ($events as $event) {
         $comentIDs[] = $event->objectID;
     }
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($comentIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     $newsIDs = $news = array();
     foreach ($comments as $comment) {
         $newsIDs[] = $comment->objectID;
     }
     if (!empty($newsIDs)) {
         $newsList = new ViewableNewsList();
         $newsList->getConditionBuilder()->add("news.newsID IN (?)", array($newsIDs));
         $newsList->readObjects();
         $news = $newsList->getObjects();
     }
     foreach ($events as $event) {
         if (isset($comments[$event->objectID])) {
             $comment = $comments[$event->objectID];
             if (isset($news[$comment->objectID])) {
                 $newsEntry = $news[$comment->objectID];
                 if (!$newsEntry->canRead()) {
                     continue;
                 }
                 $event->setIsAccessible();
                 $text = WCF::getLanguage()->getDynamicVariable('news.recentActivity.newsComment', array('news' => $newsEntry));
                 $event->setTitle($text);
                 $event->setDescription($comment->getExcerpt());
                 continue;
             }
         }
         $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();
     }
 }
 /**
  * @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\moderation\queue\IModerationQueueHandler::populate()
  */
 public function populate(array $queues)
 {
     $objectIDs = array();
     foreach ($queues as $object) {
         $objectIDs[] = $object->objectID;
     }
     // fetch comments
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($objectIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     foreach ($queues as $object) {
         if (isset($comments[$object->objectID])) {
             $object->setAffectedObject($comments[$object->objectID]);
         } 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\AbstractDatabaseObjectAction::delete()
  */
 public function delete()
 {
     if (empty($this->objects)) {
         $this->readObjects();
     }
     if (empty($this->objects)) {
         return 0;
     }
     $ignoreCounters = !empty($this->parameters['ignoreCounters']);
     // read object type ids for comments
     $commentIDs = array();
     foreach ($this->objects as $response) {
         $commentIDs[] = $response->commentID;
     }
     $commentList = new CommentList();
     $commentList->getConditionBuilder()->add("comment.commentID IN (?)", array($commentIDs));
     $commentList->readObjects();
     $comments = $commentList->getObjects();
     // update counters
     $processors = $responseIDs = $updateComments = array();
     foreach ($this->objects as $response) {
         $objectTypeID = $comments[$response->commentID]->objectTypeID;
         if (!isset($processors[$objectTypeID])) {
             $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
             $processors[$objectTypeID] = $objectType->getProcessor();
             $responseIDs[$objectTypeID] = array();
         }
         $responseIDs[$objectTypeID][] = $response->responseID;
         if (!$ignoreCounters) {
             $processors[$objectTypeID]->updateCounter($comments[$response->commentID]->objectID, -1);
             if (!isset($updateComments[$response->commentID])) {
                 $updateComments[$response->commentID] = 0;
             }
             $updateComments[$response->commentID]++;
         }
     }
     // remove responses
     $count = parent::delete();
     // update comment responses and cached response ids
     if (!$ignoreCounters) {
         foreach ($comments as $comment) {
             $commentEditor = new CommentEditor($comment);
             $commentEditor->updateResponseIDs();
             $commentEditor->updateCounters(array('responses' => -1 * $updateComments[$comment->commentID]));
         }
     }
     $likeObjectIDs = array();
     $notificationObjectTypes = array();
     foreach ($responseIDs as $objectTypeID => $objectIDs) {
         // remove activity events
         $objectType = ObjectTypeCache::getInstance()->getObjectType($objectTypeID);
         if (UserActivityEventHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.recentActivityEvent')) {
             UserActivityEventHandler::getInstance()->removeEvents($objectType->objectType . '.response.recentActivityEvent', $objectIDs);
         }
         // delete notifications
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.notification')) {
             UserNotificationHandler::getInstance()->removeNotifications($objectType->objectType . '.response.notification', $objectIDs);
         }
         $likeObjectIDs = array_merge($likeObjectIDs, $objectIDs);
         if (UserNotificationHandler::getInstance()->getObjectTypeID($objectType->objectType . '.response.like.notification')) {
             $notificationObjectTypes[] = $objectType->objectType . '.response.like.notification';
         }
     }
     // remove likes
     if (!empty($likeObjectIDs)) {
         LikeHandler::getInstance()->removeLikes('com.woltlab.wcf.comment.response', $likeObjectIDs, $notificationObjectTypes);
     }
     return $count;
 }