|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class NewsHolder extends Page |
|
|
|
|
|
|
4
|
|
|
{ |
|
5
|
|
|
|
|
6
|
|
|
public function getCMSFields() |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
$intro = null; |
|
9
|
|
|
|
|
10
|
|
|
$this->beforeUpdateCMSFields(function ($fields) { |
|
11
|
|
|
$fields->renameField("Content", "Intro Content"); |
|
12
|
|
|
$fields->insertBefore(new Tab($this->getLumberjackTitle()), 'Main'); |
|
13
|
|
|
}); |
|
14
|
|
|
|
|
15
|
|
|
$fields = parent::getCMSFields(); |
|
16
|
|
|
|
|
17
|
|
|
if ($intro) { |
|
18
|
|
|
$intro->setRightTitle("Appears at the top of the main ".$this->Title." page, above the list of articles."); |
|
19
|
|
|
} |
|
20
|
|
|
|
|
21
|
|
|
return $fields; |
|
22
|
|
|
} |
|
23
|
|
|
|
|
24
|
|
|
public function getLumberjackTitle() |
|
25
|
|
|
{ |
|
26
|
|
|
return "News Articles"; |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
public function getLumberjackPagesForGridfield($excluded = array()) |
|
|
|
|
|
|
30
|
|
|
{ |
|
31
|
|
|
return NewsArticle::get()->filter(array( |
|
32
|
|
|
'ParentID' => $this->ID, |
|
33
|
|
|
'ClassName' => $excluded, |
|
34
|
|
|
)); |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
// Only allows certain children to be created |
|
38
|
|
|
private static $allowed_children = array('NewsArticle'); |
|
|
|
|
|
|
39
|
|
|
private static $description = 'Holds News Article pages'; |
|
|
|
|
|
|
40
|
|
|
private static $icon = "basic-news/images/newspaper-page"; |
|
|
|
|
|
|
41
|
|
|
|
|
42
|
|
|
public function stageChildren($showAll = false) |
|
|
|
|
|
|
43
|
|
|
{ |
|
44
|
|
|
return $this->__call('stageChildren', array($showAll))->sort(array('MenuTitle'=>'DESC', "Created"=>'DESC')); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function init() |
|
48
|
|
|
{ |
|
49
|
|
|
RSSFeed::linkToFeed($this->Link("rss"), "News RSS Feed"); |
|
50
|
|
|
parent::init(); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
class NewsHolder_Controller extends Page_Controller |
|
|
|
|
|
|
56
|
|
|
{ |
|
57
|
|
|
|
|
58
|
|
|
private static $allowed_actions = array( |
|
|
|
|
|
|
59
|
|
|
"rss" |
|
60
|
|
|
); |
|
61
|
|
|
|
|
62
|
|
View Code Duplication |
public function init() |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
RSSFeed::linkToFeed($this->Link() . "rss"); |
|
65
|
|
|
if (Director::fileExists(project() . "/css/news.css")) { |
|
66
|
|
|
Requirements::css(project() . "/css/news.css"); |
|
67
|
|
|
} else { |
|
68
|
|
|
Requirements::css("basic-news/css/news.css"); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
parent::init(); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function rss() |
|
75
|
|
|
{ |
|
76
|
|
|
$config = SiteConfig::current_site_config(); |
|
77
|
|
|
// Creates a new RSS Feed list |
|
78
|
|
|
$rss = new RSSFeed( |
|
79
|
|
|
$list = NewsArticle::get(), // an SS_List containing your feed items |
|
80
|
|
|
$link = $this->Link("rss"), // a HTTP link to this feed |
|
81
|
|
|
$title = $config->Title . " News", // title for this feed, displayed in RSS readers |
|
82
|
|
|
$description = "All the latest news from ". $config->Title . "." // description |
|
83
|
|
|
); |
|
84
|
|
|
// Outputs the RSS feed to the user. |
|
85
|
|
|
return $rss->outputToBrowser(); |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
// Provides Paginated List of NewsArticles |
|
89
|
|
|
public function PaginatedPages() |
|
90
|
|
|
{ |
|
91
|
|
|
$list = new PaginatedList(NewsArticle::get()->filter("ParentID", $this->ID), $this->request); |
|
92
|
|
|
$list->setPageLength(10); |
|
93
|
|
|
return $list; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.