/**
  * @see	\wcf\system\comment\manager\ICommentManager::updateCounter()
  */
 public function updateCounter($objectID, $value)
 {
     $news = new News($objectID);
     $editor = new NewsEditor($news);
     // update counter for news comments
     $editor->updateCounters(array('comments' => $value));
 }
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     // get user id
     $data['userID'] = ImportHandler::getInstance()->getNewID('com.woltlab.wcf.user', $data['userID']);
     // get news id
     if (is_numeric($oldID)) {
         $news = new News($oldID);
         if (!$news->newsID) {
             $data['newsID'] = $oldID;
         }
     }
     // get news categories
     $categoryIDs = array();
     if (!empty($additionalData['categories'])) {
         foreach ($additionalData['categories'] as $oldCategoryID) {
             $newCategoryID = ImportHandler::getInstance()->getNewID('de.voolia.news.category', $oldCategoryID);
             if ($newCategoryID) {
                 $categoryIDs[] = $newCategoryID;
             }
         }
     }
     // work-around for unknown username
     if (empty($data['username'])) {
         $user = new User($data['userID']);
         $data['username'] = $user->username;
     }
     // get language by languageCode
     if (!empty($additionalData['languageCode'])) {
         if (($language = LanguageFactory::getInstance()->getLanguageByCode($additionalData['languageCode'])) !== null) {
             $data['languageID'] = $language->languageID;
         }
     }
     // create news
     $news = NewsEditor::create($data);
     $newsEditor = new NewsEditor($news);
     // save the tags from news entry
     if (!empty($additionalData['tags'])) {
         TagEngine::getInstance()->addObjectTags('de.voolia.news.entry', $news->newsID, $additionalData['tags'], $news->languageID ?: LanguageFactory::getInstance()->getDefaultLanguageID());
     }
     // update news categories
     $newsEditor->updateCategoryIDs($categoryIDs);
     ImportHandler::getInstance()->saveNewID('de.voolia.news.entry', $oldID, $news->newsID);
     return $news->newsID;
 }
 /**
  * @see	\wcf\system\importer\IImporter::import()
  */
 public function import($oldID, array $data, array $additionalData = array())
 {
     // get news id
     $data['objectID'] = ImportHandler::getInstance()->getNewID('de.voolia.news.entry', $data['objectID']);
     if (!$data['objectID']) {
         return 0;
     }
     $attachmentID = parent::import($oldID, $data, $additionalData);
     if ($attachmentID && $attachmentID != $oldID) {
         // get the news
         $news = new News($data['objectID']);
         // update news text with the new attachment id
         if (($newText = $this->fixEmbeddedAttachments($news->text, $oldID, $attachmentID)) !== false) {
             $newsEditor = new NewsEditor($news);
             $newsEditor->update(array('text' => $newText));
         }
     }
     return $attachmentID;
 }
 /**
  * @see	\wcf\system\worker\IWorker::execute()
  */
 public function execute()
 {
     parent::execute();
     if (!count($this->objectList)) {
         return;
     }
     if (!$this->loopCount) {
         // remove the activity points
         UserActivityPointHandler::getInstance()->reset('de.voolia.news.activityPointEvent.news');
         // remove the entry from search index
         SearchIndexManager::getInstance()->reset('de.voolia.news.entry');
     }
     // get news attachments
     $attachmentObjectType = ObjectTypeCache::getInstance()->getObjectTypeByName('com.woltlab.wcf.attachment.objectType', 'de.voolia.news.entry');
     $sql = "SELECT\t\tCOUNT(*) AS attachments\n\t\t\tFROM\t\twcf" . WCF_N . "_attachment\n\t\t\tWHERE\t\tobjectTypeID = ?\n\t\t\tAND\t\tobjectID = ?";
     $attachments = WCF::getDB()->prepareStatement($sql);
     // calculate the cumulative likes
     $conditions = new PreparedStatementConditionBuilder();
     $conditions->add("objectID IN (?)", array($this->objectList->getObjectIDs()));
     $conditions->add("objectTypeID = ?", array(ObjectTypeCache::getInstance()->getObjectTypeIDByName('com.woltlab.wcf.like.likeableObject', 'de.voolia.news.likeableNews')));
     $sql = "SELECT\tobjectID,\n\t\t\t\tcumulativeLikes\n\t\t\tFROM\twcf" . WCF_N . "_like_object\n\t\t\t" . $conditions;
     $statement = WCF::getDB()->prepareStatement($sql);
     $statement->execute($conditions->getParameters());
     $likes = array();
     while ($row = $statement->fetchArray()) {
         $likes[$row['objectID']] = $row['cumulativeLikes'];
     }
     // update the news entries
     $userItems = array();
     foreach ($this->objectList as $news) {
         // new EntryEditor
         $editor = new NewsEditor($news);
         // update search index
         SearchIndexManager::getInstance()->add('de.voolia.news.entry', $news->newsID, $news->message, $news->subject, $news->time, $news->userID, $news->username, $news->languageID);
         // news data
         $newsData = array();
         // likes
         $newsData['cumulativeLikes'] = isset($likes[$news->newsID]) ? $likes[$news->newsID] : 0;
         // attachments
         $attachments->execute(array($attachmentObjectType->objectTypeID, $news->newsID));
         $row = $attachments->fetchArray();
         $newsData['attachments'] = $row['attachments'];
         if ($news->userID) {
             if (!isset($userItems[$news->userID])) {
                 $userItems[$news->userID] = 0;
             }
             $userItems[$news->userID]++;
         }
         $editor->update($newsData);
     }
     // update activity points
     UserActivityPointHandler::getInstance()->fireEvents('de.voolia.news.activityPointEvent.news', $userItems, false);
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     parent::save();
     $data = array('subject' => $this->subject, 'time' => TIME_NOW, 'text' => $this->text, 'teaser' => $this->teaser, 'userID' => WCF::getUser()->userID ?: null, 'username' => WCF::getUser()->userID ? WCF::getUser()->username : $this->username, 'languageID' => $this->languageID, 'enableBBCodes' => $this->enableBBCodes, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'isActive' => 1, 'isDeleted' => 0, 'isHot' => $this->isHot, 'views' => 0);
     // delayed publication
     if ($this->enableDelayedPublication) {
         $data['isPublished'] = 0;
         $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->publicationDate, WCF::getUser()->getTimeZone());
         $data['publicationDate'] = $dateTime->getTimestamp();
     }
     // automatic archivation
     if ($this->enableAutomaticArchiving) {
         $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->archivingDate, WCF::getUser()->getTimeZone());
         $data['archivingDate'] = $dateTime->getTimestamp();
     }
     // news picture
     if (NEWS_ENABLE_NEWSPICTURE && $this->pictureID) {
         $data['pictureID'] = $this->pictureID;
     }
     $newsData = array('attachmentHandler' => $this->attachmentHandler, 'categoryIDs' => $this->categoryIDs, 'data' => $data);
     if (NEWS_ENTRY_ENABLE_SOURCES) {
         $newsData['sources'] = $this->sources;
     }
     if (MODULE_TAGGING) {
         $newsData['tags'] = $this->tags;
     }
     $this->objectAction = new NewsAction(array(), 'create', $newsData);
     $resultvalues = $this->objectAction->executeAction();
     $this->news = $resultvalues['returnValues'];
     // quotes
     MessageQuoteManager::getInstance()->saved();
     // polls
     if ($this->canCreatePoll()) {
         $pollID = PollManager::getInstance()->save($this->news->newsID);
         if ($pollID) {
             $newsEditor = new NewsEditor($this->news);
             $newsEditor->update(array('pollID' => $pollID));
         }
     }
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('News', array('application' => 'news', 'object' => $this->news)));
     exit;
 }
 /**
  * @see	\wcf\form\IForm::save()
  */
 public function save()
 {
     MessageForm::save();
     if (WCF::getSession()->getPermission('mod.news.canEditNewsWithoutNote') && $this->editNoteSuppress == 1) {
         $this->news->editCount = 0;
         $this->editReason = '';
         $this->news->editTime = 0;
     }
     // save the news entry
     $data = array('subject' => $this->subject, 'text' => $this->text, 'teaser' => $this->teaser, 'languageID' => $this->languageID, 'enableBBCodes' => $this->enableBBCodes, 'enableHtml' => $this->enableHtml, 'enableSmilies' => $this->enableSmilies, 'editCount' => $this->news->editCount + 1, 'editReason' => $this->editReason, 'editTime' => TIME_NOW, 'editUser' => WCF::getUser()->username, 'editReason' => $this->editReason, 'editNoteSuppress' => $this->editNoteSuppress, 'isHot' => $this->isHot);
     // delayed publication
     if ($this->enableDelayedPublication) {
         $data['isPublished'] = 0;
         $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->publicationDate, WCF::getUser()->getTimeZone());
         $data['publicationDate'] = $dateTime->getTimestamp();
     } else {
         $data['isPublished'] = 1;
         $data['publicationDate'] = 0;
     }
     // automatic archivation
     if ($this->enableAutomaticArchiving) {
         $dateTime = \DateTime::createFromFormat('Y-m-d H:i', $this->archivingDate, WCF::getUser()->getTimeZone());
         $data['archivingDate'] = $dateTime->getTimestamp();
     } else {
         $data['archivingDate'] = 0;
     }
     // news picture
     if (NEWS_ENABLE_NEWSPICTURE && $this->pictureID) {
         $data['pictureID'] = $this->pictureID;
     }
     $newsData = array('attachmentHandler' => $this->attachmentHandler, 'categoryIDs' => $this->categoryIDs, 'data' => $data);
     if (NEWS_ENTRY_ENABLE_SOURCES) {
         $newsData['sources'] = $this->sources;
     }
     if (MODULE_TAGGING) {
         $newsData['tags'] = $this->tags;
     }
     // save poll
     if ($this->canCreatePoll()) {
         $pollID = PollManager::getInstance()->save($this->news->newsID);
         if ($pollID) {
             $newsEditor = new NewsEditor($this->news);
             $newsEditor->update(array('pollID' => $pollID));
         }
     }
     $this->objectAction = new NewsAction(array($this->news), 'update', $newsData);
     $this->objectAction->executeAction();
     $this->saved();
     HeaderUtil::redirect(LinkHandler::getInstance()->getLink('News', array('application' => 'news', 'object' => $this->news)));
     exit;
 }
 /**
  * @see	\wcf\data\like\object\ILikeObject::updateLikeCounter()
  */
 public function updateLikeCounter($cumulativeLikes)
 {
     // update cumulative likes
     $entryEditor = new NewsEditor($this->getDecoratedObject());
     $entryEditor->update(array('cumulativeLikes' => $cumulativeLikes));
 }
 /**
  * @see	\wcf\data\IDeleteAction::delete()
  */
 public function delete()
 {
     // delete news entries
     parent::delete();
     // collect data
     $newsIDs = $perUserCount = $pollIDs = array();
     foreach ($this->objects as $news) {
         $newsIDs[] = $news->newsID;
         if ($news->pollID) {
             $pollIDs[] = $news->pollID;
         }
         if (!$news->isDisabled) {
             if (!isset($perUserCount[$news->userID])) {
                 $perUserCount[$news->userID] = 0;
             }
             $perUserCount[$news->userID]++;
         }
     }
     if (!empty($newsIDs)) {
         // delete like data
         LikeHandler::getInstance()->removeLikes('de.voolia.news.likeableNews', $newsIDs);
         // delete comments
         CommentHandler::getInstance()->deleteObjects('de.voolia.news.comment', $newsIDs);
         // delete tag to object entries
         TagEngine::getInstance()->deleteObjects('de.voolia.news.entry', $newsIDs);
         // delete entry activity events
         UserActivityEventHandler::getInstance()->removeEvents('de.voolia.news.recentActivityEvent.news', $newsIDs);
         UserActivityPointHandler::getInstance()->removeEvents('de.voolia.news.activityPointEvent.news', $perUserCount);
         // delete entry from search index
         SearchIndexManager::getInstance()->delete('de.voolia.news.entry', $newsIDs);
         // remove object from moderation queue
         ModerationQueueActivationManager::getInstance()->removeModeratedContent('de.voolia.news.entry', $newsIDs);
     }
     // delete a poll
     if (!empty($pollIDs)) {
         PollManager::getInstance()->removePolls($pollIDs);
     }
     // reset the user storage data
     UserStorageHandler::getInstance()->resetAll('newsUnreadEntries');
     UserStorageHandler::getInstance()->resetAll('newsUnreadWatchedEntries');
     // reset the news cache
     NewsEditor::resetNewsStatsCache();
 }