public function getLink()
 {
     $newsHolder = NewsHolder::get_one('NewsHolder');
     if ($newsHolder) {
         return $newsHolder->Link() . '?category=' . $this->ID;
     }
 }
 /**
  * @param int $amount The amount of items to provide.
  */
 public function getNewsItems($amount = 2)
 {
     $newsHolder = NewsHolder::get_one('NewsHolder');
     if ($newsHolder) {
         $controller = new NewsHolder_Controller($newsHolder);
         return $controller->getNewsItems($amount);
     }
 }
 function onBeforeWrite()
 {
     // Change MenuTitle, so date appears in CMS SiteTree
     $this->MenuTitle = $this->Date . ": " . $this->Title;
     // Move to News holder if created under something else
     if ($this->Parent()->ClassName != "NewsHolder") {
         $this->ParentID = NewsHolder::get()->first()->ID;
     }
     // Add Today's Date if None
     if (!$this->Date) {
         $this->Date = date('Y-m-d');
     }
     parent::onBeforeWrite();
 }
 /**
  * Create default news setup
  */
 function requireDefaultRecords()
 {
     parent::requireDefaultRecords();
     if (!DataObject::get_one('NewsHolder')) {
         $newsHolder = new NewsHolder();
         $newsHolder->Title = 'News';
         $newsHolder->Namespace = 'global';
         $newsHolder->URLSegment = 'news';
         $newsHolder->Status = 'Published';
         $newsHolder->write();
         $newsHolder->publish('Stage', 'Live');
         $newsItem = new NewsItem();
         $newsItem->Title = _t('NewsHolder.SUCTITLE', 'SilverStripe news module successfully installed');
         $newsItem->Date = date('Y-m-d');
         $newsItem->URLSegment = 'sample-news-item';
         $newsItem->Content = _t('NewsHolder.SUCCONTENT', 'Congratulations, the SilverStripe news module has been successfully installed. This news item can be safely deleted.');
         $newsItem->Status = 'Published';
         $newsItem->ParentID = $newsHolder->ID;
         $newsItem->write();
         $newsItem->publish('Stage', 'Live');
         DB::alteration_message('News item created', 'created');
     }
 }
 /**
  * getCMSFields
  * @return FieldList
  **/
 public function getCMSFields()
 {
     $fields = parent::getCMSFields();
     $fields->dataFieldByName('Title')->setTitle('Article Title');
     $fields->dataFieldByName('Content')->setTitle('Article Content');
     $config = $this->config();
     // publish date
     $fields->addFieldToTab('Root.Main', DateField::create('PublishDate')->setAttribute('placeholder', $this->dbObject('Created')->Format('M d, Y')), 'Content');
     // tags
     if ($config->enable_tags) {
         $tagSource = function () {
             return NewsTag::get()->map()->toArray();
         };
         $fields->addFieldToTab('Root.Main', ListboxField::create('Tags', 'Tags', $tagSource(), null, null, true)->useAddnew('NewsTag', $tagSource), 'Content');
     }
     // author
     if ($config->author_mode == 'string') {
         $fields->addFieldToTab('Root.Main', TextField::create('Author', 'Author'), 'Content');
     }
     if ($config->author_mode == 'object') {
         $authorSource = function () {
             return NewsAuthor::get()->map('ID', 'Name')->toArray();
         };
         $fields->addFieldToTab('Root.Main', DropdownField::create('NewsAuthorID', 'Author', $authorSource())->useAddNew('NewsAuthor', $authorSource)->setHasEmptyDefault(true), 'Content');
     }
     // featured
     if ($config->enable_featured_articles) {
         $fields->addFieldToTab('Root.Main', CheckboxField::create('Featured', _t('NewsArticle.FEATURED', 'Feature this article')), 'Content');
     }
     // images
     if ($config->enable_images) {
         $fields->addFieldToTab('Root.FilesAndImages', UploadField::create('Image')->setAllowedFileCategories('image')->setAllowedMaxFileNumber(1)->setFolderName($config->get('image_folder')));
     }
     // attachments
     if ($config->enable_attachments) {
         $fields->addFieldToTab('Root.FilesAndImages', UploadField::create('Attachment')->setAllowedFileCategories('doc')->setAllowedMaxFileNumber(1)->setFolderName($config->get('attachment_folder')));
     }
     // summary
     if ($config->enable_summary) {
         $fields->addFieldToTab('Root.Main', HTMLEditorField::create('Summary', 'Article Summary'), 'Content');
     }
     // parent
     $holders = NewsHolder::get();
     if ($holders->count() > 1) {
         $fields->addFieldToTab('Root.Main', DropdownField::create('ParentID', 'News Section', $holders->map()->toArray()), 'Title');
     } else {
         $fields->addFieldToTab('Root.Main', HiddenField::create('ParentID', 'News Section', $holders->first()->ID), 'Title');
     }
     $this->extend('updateArticleCMSFields', $fields);
     return $fields;
 }
 /**
  * Returns a list of sub news sections, if available
  *
  * @return DataObjectSet
  */
 public function SubSections($allChildren = true)
 {
     $subs = null;
     $childHolders = NewsHolder::get()->filter('ParentID', $this->ID);
     if ($childHolders && $childHolders->count()) {
         $subs = new ArrayList();
         foreach ($childHolders as $holder) {
             $subs->push($holder);
             if ($allChildren === true) {
                 // see if there's any children to include
                 $subSub = $holder->SubSections();
                 if ($subSub) {
                     $subs->merge($subSub);
                 }
             }
         }
     }
     return $subs;
 }
 /**
  * Used by templates to access and iterate over articles
  * @var $limit - number of articles per page (defaults to articles_per_page config value)
  * @return PaginatedList
  **/
 public function Articles($limit = null)
 {
     $tag = $this->getCurrentTag();
     $year = $this->getCurrentYear();
     $month = $this->getCurrentMonth();
     $start = (int) $this->request->requestVar('start') ?: null;
     $limit = $limit ? $limit : NewsHolder::config()->get('articles_per_page');
     $list = $this->data()->getArticleList($tag, $year, $month);
     $paged = new PaginatedList($list, $this->request);
     $paged->setPageLength($limit);
     return $paged;
 }