/**
  * @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)
 {
     $entryIDs = array();
     foreach ($events as $event) {
         $entryIDs[] = $event->objectID;
     }
     $entryList = new ViewableEntryList();
     $entryList->getConditionBuilder()->add("news_entry.entryID IN (?)", array($entryIDs));
     $entryList->readObjects();
     $newsEntries = $entryList->getObjects();
     foreach ($events as $event) {
         if (isset($newsEntries[$event->objectID])) {
             $entry = $newsEntries[$event->objectID];
             if (!$entry->canRead()) {
                 continue;
             }
             $event->setIsAccessible();
             $text = WCF::getLanguage()->getDynamicVariable('cms.recentActivity.likedNews', array('entry' => $entry));
             $event->setTitle($text);
             $event->setDescription($entry->getExcerpt());
         } else {
             $event->setIsOrphaned();
         }
     }
 }
 /**
  * @see	\wcf\data\DatabaseObjectList::readObjects()
  */
 public function readObjects()
 {
     if ($this->objectIDs === null) {
         $this->readObjectIDs();
     }
     parent::readObjects();
 }
 /**
  * Creates a new NewsCategoryList object.
  * 
  * @param	array<integer>		$categoryIDs
  */
 public function __construct(array $categoryIDs)
 {
     ViewableEntryList::__construct();
     // accessible news categories
     if (!empty($categoryIDs)) {
         $this->getConditionBuilder()->add('news_entry_to_category.categoryID IN (?)', array($categoryIDs));
         $this->getConditionBuilder()->add('news_entry.entryID = news_entry_to_category.entryID');
     } else {
         $this->getConditionBuilder()->add('1=0');
     }
     // default conditions
     if (!WCF::getSession()->getPermission('mod.news.canModerateEntry')) {
         $this->getConditionBuilder()->add('news_entry.isDisabled = 0');
     }
     if (!WCF::getSession()->getPermission('mod.news.canViewDeletedEntry')) {
         $this->getConditionBuilder()->add('news_entry.isDeleted = 0');
     }
     if (WCF::getUser()->userID) {
         $this->getConditionBuilder()->add('(news_entry.isPublished = 1 OR news_entry.userID = ?)', array(WCF::getUser()->userID));
     } else {
         $this->getConditionBuilder()->add('news_entry.isPublished = 1');
     }
     // apply language filter
     if (LanguageFactory::getInstance()->multilingualismEnabled() && count(WCF::getUser()->getLanguageIDs())) {
         $this->getConditionBuilder()->add('(news_entry.languageID IN (?) OR news_entry.languageID IS NULL)', array(WCF::getUser()->getLanguageIDs()));
     }
 }
 /**
  * Creates a new DeletedEntryList object.
  */
 public function __construct()
 {
     parent::__construct();
     // accessible news categories
     $accessibleCategoryIDs = NewsCategory::getAccessibleCategoryIDs();
     if (!empty($accessibleCategoryIDs)) {
         $this->getConditionBuilder()->add('news_entry.entryID IN (SELECT entryID FROM cms' . WCF_N . '_news_entry_to_category WHERE categoryID IN (?))', array($accessibleCategoryIDs));
     } else {
         $this->getConditionBuilder()->add('1=0');
     }
     // load only deleted news
     $this->getConditionBuilder()->add('news_entry.isDeleted = ?', array(1));
 }
 /**
  * Creates a new TaggedNewsList object.
  * 
  * @param	\wcf\data\tag\Tag	$tag
  */
 public function __construct(Tag $tag)
 {
     ViewableEntryList::__construct();
     $this->getConditionBuilder()->add('tag_to_object.objectTypeID = ? AND tag_to_object.languageID = ? AND tag_to_object.tagID = ?', array(TagEngine::getInstance()->getObjectTypeID('de.incendium.cms.news.entry'), $tag->languageID, $tag->tagID));
     $this->getConditionBuilder()->add('news_entry.entryID = tag_to_object.objectID');
     // accessible news categories
     $accessibleCategoryIDs = NewsCategory::getAccessibleCategoryIDs();
     if (!empty($accessibleCategoryIDs)) {
         $this->getConditionBuilder()->add('news_entry.entryID IN (SELECT entryID FROM cms' . WCF_N . '_news_entry_to_category WHERE categoryID IN (?))', array(NewsCategory::getAccessibleCategoryIDs()));
     } else {
         $this->getConditionBuilder()->add('1=0');
     }
 }
 /**
  * Gets a specific entry decorated as viewable entry.
  * 
  * @param    integer        $entryID
  * @return    \cms\data\news\ViewableEntry
  */
 public static function getEntry($entryID)
 {
     $list = new ViewableEntryList();
     $list->setObjectIDs(array($entryID));
     $list->readObjects();
     $objects = $list->getObjects();
     if (isset($objects[$entryID])) {
         return $objects[$entryID];
     }
     return null;
 }