1 <?php
2
3 4 5 6 7
8 class AnnouncementHolder extends Page {
9
10 static $icon = "anons/img/anonsholder";
11
12 static $db = array(
13 'ShowTypeBlock' => 'Int',
14 'ShowTypePage' => 'Int',
15 'PerBlock' => 'Int',
16 'PerPage' => 'Int',
17 'Template' => 'Text'
18 );
19
20 static $defaults = array(
21 'ShowTypeBlock' => 1,
22 'ShowTypePage' => 1,
23 'PerBlock' => 3,
24 'PerPage' => 20,
25 'AutoChild' => 0,
26 'ShowInMenus' => 0,
27 'ShowInSearch' => 0,
28 'ShowInSiteMap' => 0,
29 'DevEditType' => 'Fixed',
30 );
31
32 static $subpage_children = 'Announcement';
33
34 static $allowed_children = array('Announcement');
35
36 37 38 39 40
41 static $max_slider_width = 1920;
42
43 44 45 46 47
48 static $slider_holder_ids = array();
49
50 51 52 53 54
55 static function set_max_slider_width($val) {
56 self::$max_slider_width = $val;
57 }
58
59 60 61 62 63
64 static function set_slider_holder_ids($val) {
65 self::$slider_holder_ids = (is_array($val)) ? $val : array($val);
66 }
67
68 69 70 71 72 73
74 static function is_slider_holder($id) {
75 return (array_search($id, self::$slider_holder_ids) !== false);
76 }
77
78 function getCMSFields() {
79 $fields = parent::getCMSFields();
80 $fields->removeFieldFromTab('Root.Content.Main', 'Content');
81 $fields->addFieldToTab('Root.Content.Main', new HeaderField('hdrBlock', _t('AnnouncementHolder.hdrBlock', 'Block Settings')));
82 $fields->addFieldToTab('Root.Content.Main',
83 new OptionsetField('ShowTypeBlock', $this->fieldLabel('ShowTypeBlock'), array(
84 1 => _t('AnnouncementHolder.BLOCKTYPE_LAST', "Last N"),
85 2 => _t('AnnouncementHolder.BLOCKTYPE_RANDOM', "Random N"),
86 3 => _t('AnnouncementHolder.BLOCKTYPE_ALL', "All")
87 ))
88 );
89 $fields->addFieldToTab('Root.Content.Main', $f = new NumericField("PerBlock", _t('AnnouncementHolder.PERBLOCK', "Announcement per block")));
90
91 $fields->addFieldToTab('Root.Content.Main', new HeaderField('hdrPage', _t('AnnouncementHolder.hdrPage', 'Page Settings')));
92 $fields->addFieldToTab('Root.Content.Main',
93 new OptionsetField('ShowTypePage', $this->fieldLabel('ShowTypePage'), array(
94 1 => _t('AnnouncementHolder.PAGETYPE_LAST', "Date desc"),
95 3 => _t('AnnouncementHolder.PAGETYPE_ALL', "Manual")
96 ))
97 );
98 $fields->addFieldToTab('Root.Content.Main', new NumericField("PerPage", _t('AnnouncementHolder.PERPAGE', "Announcement per page")));
99
100 if (Director::isDev())
101 $fields->addFieldToTab('Root.Content.Main', new TextField("Template", _t('AnnouncementHolder.TEMPLATE', "Template")));
102
103 $fields->addFieldToTab('Root.Content', new Tab('tabSubPages', _t('AnnouncementHolder.TABLABEL', "Announcements")), 'Metadata');
104
105
106
107 $subClass = 'Announcement';
108 $sp = new SubpageListField('Subpages', $this, $subClass);
109 $sp->Sortable = true;
110 $url = '<a href=\"admin/show/$ID\">$value</a>';
111 $sp->setFieldFormatting(array_combine(array_keys(singleton($subClass)->summaryFields()), array_fill(0, count(singleton($subClass)->summaryFields()), $url)));
112 $fields->addFieldToTab('Root.Content.tabSubPages', $sp);
113
114 $this->extend('hideCMSFields', $fields);
115 return $fields;
116 }
117
118 function populateDefaults() {
119 parent::populateDefaults();
120 $this->DevEditType = (Director::isDev()) ? 'Fixed' : 'Open';
121 }
122
123 public function Entries($start = '', $limit = '') {
124 if ($limit != '') {
125 if ($start != '') {
126 $limit = "$start,$limit";
127 }
128 }
129
130 if ($this->ShowTypePage == 1) {
131 $sort = "`Announcement`.Date DESC, `Announcement`.ID DESC";
132 }
133 elseif ($this->ShowTypePage == 2) {
134 $sort = "rand()";
135 }
136 else {
137 $sort = "Sort ";
138 }
139
140 return DataObject::get("Announcement", "`ParentID` = $this->ID AND `Status` LIKE '%Published%'", $sort, "", "$limit");
141 }
142
143 }
144
145 class AnnouncementHolder_Controller extends Page_Controller {
146
147 public static $url_handlers = array(
148 '$Contoller//$Action' => 'index'
149 );
150
151 function index() {
152 $start = isset($_GET['start']) ? (int) $_GET['start'] : 0;
153 $limit = intval($this->PerPage);
154 $limit = ($limit > 0) ? $limit : AnnouncementHolder::$defaults['PerPage'];
155
156 $data = $this->Entries($start, $limit);
157 return ($this->Template) ? $this->renderWith($this->Template, array('Items' => $data)) : $this->render(array('Items' => $data));
158 }
159
160 }
161
[Raise a SilverStripe Framework issue/bug](https://github.com/silverstripe/silverstripe-framework/issues/new)
- [Raise a SilverStripe CMS issue/bug](https://github.com/silverstripe/silverstripe-cms/issues/new)
- Please use the
Silverstripe Forums to ask development related questions.
-