/**
  * Free guess on what this button does.
  * @param string $action
  * @return string Link to this object.
  */
 public function Link($action = 'author/')
 {
     if ($siteConfigAction = SiteConfig::current_site_config()->AuthorAction) {
         $action = $siteConfigAction . '/';
     }
     if ($Page = NewsHolderPage::get()->first()) {
         return $Page->Link($action . $this->URLSegment);
     }
     return false;
 }
 /**
  * List only newsitems from current subsite.
  *
  * @author Marcio Barrientos
  * @return ArrayList $list
  */
 public function getList()
 {
     /** @var DataList $list */
     $list = parent::getList();
     if ($this->modelClass === 'News' && class_exists('Subsite') && Subsite::currentSubsiteID() > 0) {
         $pages = NewsHolderPage::get()->filter(array('SubsiteID' => (int) Subsite::currentSubsiteID()));
         $filter = $pages->column('ID');
         /* Manual join needed because otherwise no items are found. Unknown why. */
         $list = $list->innerJoin('NewsHolderPage_Newsitems', 'NewsHolderPage_Newsitems.NewsID = News.ID')->filter(array('NewsHolderPage_Newsitems.NewsHolderPageID' => $filter));
     }
     return $list;
 }
 /**
  * This is to migrate existing newsitems to the new release with the new relational method.
  * It is forward-non-destructive.
  * Only run if there is a column NewsHolderPageID
  * @todo This needs a rewrite, could be done with less queries with an add Items to Page instead of the current situation.
  */
 private function migratePages()
 {
     $existquery = "SHOW COLUMNS FROM `News` LIKE 'NewsHolderPageID';";
     /** @var DB $exists */
     $exists = DB::query($existquery);
     if ($count = $exists->numRecords()) {
         /** @var SQLQuery $query */
         $query = new SQLQuery();
         $query->setSelect(array('ID', 'NewsHolderPageID'))->setFrom('News');
         $newsitems = $query->execute();
         foreach ($newsitems as $newsitem) {
             if ($newsitem['NewsHolderPageID'] && NewsHolderPage::get()->byID($newsitem['NewsHolderPageID'])) {
                 News::get()->byID($newsitem['ID'])->NewsHolderPages()->add($newsitem['NewsHolderPageID']);
             }
         }
     }
 }
 /**
  * The holder-page ID should be set if translatable, otherwise, we just select the first available one.
  * The NewsHolderPage should NEVER be doubled.
  */
 public function onBeforeWrite()
 {
     parent::onBeforeWrite();
     /** Check if we have translatable and a NewsHolderPage. If no HolderPage available, skip (Create an orphan) */
     if (!$this->NewsHolderPages()->count()) {
         if (!class_exists('Translatable') && ($page = NewsHolderPage::get()->first())) {
             $this->NewsHolderPages()->add($page);
         }
     }
     if (!$this->Type || $this->Type == '') {
         $this->Type = 'news';
     }
     /** Set PublishFrom to today to prevent errors with sorting. New since 2.0, backward compatible. */
     if (!$this->PublishFrom) {
         $this->PublishFrom = SS_Datetime::now()->Rfc2822();
     }
     /**
      * Make sure the link is valid.
      */
     if (substr($this->External, 0, 4) != 'http' && $this->External != '') {
         $this->External = 'http://' . $this->External;
     }
     $this->setURLValue();
     $this->setAuthorData();
 }
Esempio n. 5
0
 /**
  * Free guess on what this button does.
  *
  * @param string $action The required action
  *
  * @return string|boolean Link to this object or false if no holderpage is found..
  */
 public function Link($action = 'tag/')
 {
     if ($config = SiteConfig::current_site_config()->TagAction) {
         $action = $config . '/';
     }
     /** @var NewsHolderPage $Page */
     if ($Page = NewsHolderPage::get()->first()) {
         return $Page->Link($action . $this->URLSegment);
     }
     return false;
 }