1 <?php
2 3 4 5 6 7 8
9 class PublicationWidget extends SidebarWidget {
10 static $db = array(
11 'ShowType' => 'Varchar',
12 );
13
14 static $has_one = array(
15 'Holder' => 'PublHolder'
16 );
17
18 static $show_types = array(
19 'last',
20 'random',
21 );
22
23 static function set_show_types($types) {
24 self::$show_types = $types;
25 }
26
27 public $needObjects = array(
28 'PublHolder' => 'Page'
29 );
30
31 function getCMSFields() {
32 if (!$this->canCreate()) {
33 return $this->getFailCMSFields();
34 }
35
36 $fields = parent::getCMSFields();
37 $holders = DataObject::get('PublHolder');
38 if ($holders) {
39 $holders = $holders->map();
40 } else {
41 $holders = array();
42 }
43
44 $fields->replaceField('HolderID', new DropdownField('HolderID', $this->fieldLabel('Holder'), $holders, "", null, _t('Widgets.All', 'All')));
45 $fields->replaceField('ShowType', new DropdownField('ShowType', $this->fieldLabel('ShowType'), WebylonWidget::get_array_localization($this->class, 'ShowType', self::$show_types)));
46
47 return $fields;
48 }
49
50 function PublicationList() {
51 return Publication::get_publications(1, false, $this->HolderID, ($this->ShowType == 'last') ? false : true);
52 }
53
54 function hasContent() {
55 if ($this->PublicationList()) {
56 return true;
57 }
58 return false;
59 }
60
61 function getMoreLink() {
62 if ($this->HolderID && $this->Holder()) {
63 return $this->Holder()->Link();
64 }
65 if ($holder = DataObject::get_one('PublHolder')) {
66 return $holder->Link();
67 }
68 return false;
69 }
70 }
71
72
[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.
-