Source of file NewsIndex.php
Size: 4,313 Bytes - Last Modified: 2021-12-23T10:36:34+00:00
/var/www/docs.ssmods.com/process/src/code/Control/NewsIndex.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 | <?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 NewsIndex extends Page { private static $db = array( 'ItemsPerPage' => 'Int', ); public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName('Content'); $fields->addFieldToTab('Root.Main', TextField::create('ItemsPerPage') ->setTitle('Number of items per page'), 'Metadata' ); return $fields; } public function getNewsItemsEditLink() { return Director::baseURL() . '/admin/news?ParentID=' . $this->ID; } public function getTreeEditLinkText() { return 'Use News admin to manage pages of this tree'; } } class NewsIndex_Controller extends Page_Controller { private static $allowed_actions = array( 'tag', 'archive', 'rss', 'category' ); public function tag() { return $this; } public function archive() { return $this; } public function category() { return $this; } /** * @return bool */ public function IsTag() { return $this->request->param('Action') == 'tag'; } /** * @return bool */ public function IsArchive() { return $this->request->param('Action') == 'archive'; } /** * @return bool */ public function IsCategory() { return $this->request->param('Action') == 'category'; } /** * @return array|string */ public function GetFilterText() { return Convert::raw2xml($this->request->param('ID')); } /** * @param int $iOffset * @return PaginatedList */ public function Items($iOffset = 0) { $request = $this->GetRequestForItems($iOffset); $items = NewsPost::get()->filter('ParentID', $this->ID); if ($this->IsTag()) { $items = $items->filter('Tags:PartialMatch', $this->request->param('ID')); } if ($this->IsCategory()) { $items = $items->where('EXISTS ( SELECT 1 FROM "NewsPost_Categories" WHERE "NewsPost_Categories"."NewsPostID" = "NewsPost"."ID" AND "NewsPost_Categories"."NewsCategoryID" = ' . ((int)$this->request->param('ID')) . ')'); } if ($this->IsArchive()) { $strPattern = SiteConfig::current_site_config()->ArchivePattern ? : '%Y, %M'; $items = $items->where('DATE_FORMAT("DateTime", \'' . $strPattern . '\') = \'' . Convert::raw2sql($this->request->param('ID')) . '\''); } $items = $items->Sort('DateTime DESC'); $this->extend('updateItemsList', $items); $paginatedList = new PaginatedList($items, $request); $paginatedList->setPageLength($this->ItemsPerPage ? : SiteConfig::current_site_config()->ItemsPerPage ? : 10); return $paginatedList; } /** * @param int $iOffset * @return NullHTTPRequest|SS_HTTPRequest */ public function GetRequestForItems($iOffset = 0) { if ($iOffset == 0) { return $this->request; } $iStart = 0; $request = Controller::curr()->request; if ($request->getVar('start')) { $iStart = $request->getVar('start'); } $iStart += $iOffset; return new SS_HTTPRequest("get", "/", array( "start" => $iStart, )); } /** * @return int */ public function NewsItemsPerPage() { return $this->ItemsPerPage ? : SiteConfig::current_site_config()->ItemsPerPage ? : 10; } /** * RSS feed */ public function rss() { $list = NewsPost::get()->filter('ParentID', $this->ID); $list = $list->Sort('DateTime DESC'); $this->extend('updateRSSItems', $list); $feed = new RSSFeed( $list, $this->AbsoluteLink(), $this->Title ); return $feed->outputToBrowser(); } /** * @return DataList */ public function NewsCategories() { return NewsCategory::get(); } } |