Source of file NewsPost.php
Size: 3,738 Bytes - Last Modified: 2021-12-23T10:36:34+00:00
/var/www/docs.ssmods.com/process/src/code/Control/NewsPost.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 | <?php /** * Created by Nivanka Fonseka (nivanka@silverstripers.com). * User: nivankafonseka * Date: 4/6/15 * Time: 2:00 PM * To change this template use File | Settings | File Templates. */ class NewsPost extends Page { private static $pages_admin = true; private static $db = array( 'DateTime' => 'SS_Datetime', 'Tags' => 'Varchar(500)', 'Author' => 'Varchar(100)', 'Summary' => 'HTMLText' ); private static $many_many = array( 'Categories' => 'NewsCategory', 'RelatedArticles' => 'NewsPost' ); private static $icon = 'silverstripe-news/images/NewsPost.png'; public function getCMSFields() { $fields = parent::getCMSFields(); if (!Config::inst()->get('NewsPost', 'pages_admin')) { $arrTypes = NewsPost::GetNewsTypes(); if (count($arrTypes) > 1) { $arrDropDownSource = array(); foreach ($arrTypes as $strType) { $arrDropDownSource[$strType] = $strType; } $fields->addFieldToTab('Root.Main', DropdownField::create('ClassName')->setSource($arrDropDownSource) ->setTitle('Type'), 'Content'); } } $fields->addFieldsToTab('Root.Main', array( DropdownField::create('ParentID')->setSource(NewsIndex::get()->map()->toArray())->setTitle('Parent Page'), DatetimeField::create('DateTime'), TextField::create('Tags'), TextField::create('Author'), HtmlEditorField::create('Summary')->setRows(5) ), 'Content'); if ($this->ID) { $fields->addFieldToTab('Root.Main', CheckboxSetField::create('Categories')->setSource(NewsCategory::get()->map('ID', 'Title')->toArray()), 'Content'); $fields->addFieldToTab('Root.RelatedArticles', GridField::create('RelatedArticles', 'Related Articles')->setList($this->RelatedArticles()) ->setConfig($relatedArticlesConfig = new GridFieldConfig_RelationEditor())); } $this->extend('updateNewsPostCMSFields', $fields); return $fields; } public static function GetNewsTypes() { return ClassInfo::subclassesFor('NewsPost'); } /** * @return ArrayList * return a list of tags as a list of ArrayData's */ public function TagList() { $list = new ArrayList(); $newsIndex = $this->Parent(); $tags = trim($this->Tags); if($tags) { foreach (explode(',', $tags) as $tag) { $tag = trim($tag); $list->push(new ArrayData(array( 'Tag' => $tag, 'Link' => $newsIndex->Link('tag/' . urlencode($tag)) ))); } } return $list; } public function ExportContent() { if(method_exists($this, 'customExportContent')) { return $this->customExportContent(); } return $this->Content; } public function PrevNewsItem() { return NewsPost::get()->filter(array( 'DateTime:LessThanOrEqual' => $this->DateTime ))->exclude('ID', $this->ID)->sort('DateTime DESC')->first(); } public function NextNewsItem() { return NewsPost::get()->filter(array( 'DateTime:GreaterThanOrEqual' => $this->DateTime ))->exclude('ID', $this->ID)->sort('DateTime')->first(); } } class NewsPost_Controller extends Page_Controller { } |