1 <?php
2
3 class GuestbookWidget extends SidebarWidget {
4
5 static $db = array(
6 'ShowType' => 'Varchar',
7 );
8
9 static $has_one = array(
10 'Holder' => 'Guestbook'
11 );
12
13 static $show_types = array(
14 'last',
15 'random',
16 );
17
18 static function set_show_types($types) {
19 self::$show_types = $types;
20 }
21
22 public $needObjects = array(
23 'Guestbook' => 'Page'
24 );
25
26 function getCMSFields() {
27 if (!$this->canCreate()) {
28 return $this->getFailCMSFields();
29 }
30
31 $fields = parent::getCMSFields();
32 $holders = DataObject::get('Guestbook');
33 if ($holders) {
34 $holders = $holders->map();
35 } else {
36 $holders = array();
37 }
38
39 $fields->addFieldToTab('Root.Main', new DropdownField("HolderID", $this->fieldLabel('Holder'), $holders, "", null, _t('Widgets.All', 'All')));
40 $fields->replaceField('ShowType', new DropdownField('ShowType', $this->fieldLabel('ShowType'), WebylonWidget::get_array_localization($this->class, 'ShowType', self::$show_types)));
41
42 return $fields;
43 }
44
45 function GuestbookList() {
46 $arrParam = array(
47 'filter' => "Status = 'published'",
48 'sort' => ($this->ShowType == 'last') ? 'ID DESC' : 'RAND()',
49 'limit_start' => '0',
50 'limit_end' => '1',
51 );
52
53 if ($this->HolderID && ($guestbook = $this->Holder())) {
54 if (!$guestbook->NeedsActivation) {
55 $arrParam['filter'] = "(Status = 'published' OR Status = 'new')";
56 }
57 $arrParam['filter'] .= ' AND GuestbookID=' . $guestbook->ID;
58 }
59
60 return GuestbookEntry::get_entry_list($arrParam);
61 }
62
63 function hasContent() {
64 if ($this->GuestbookList()) {
65 return true;
66 }
67 return false;
68 }
69
70 function getMoreLink() {
71 if ($this->HolderID && $this->Holder()) {
72 return $this->Holder()->Link();
73 }
74 if ($entries = $this->GuestbookList()) {
75 return $entries->First()->Guestbook()->Link();
76 }
77 return false;
78 }
79 }
80
81
[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.
-