/**
  * @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\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\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);
 }