Пример #1
0
 /**
  * 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)
 {
     $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();
     }
 }