1 <?php
2
3 4 5 6 7 8 9
10 class AdvancedSliderHomepageWidget extends HomepageWidget {
11 static $db = array(
12 'SlideHeight' => 'Int',
13 'ShowNavigation' => 'Boolean',
14 'DelayTime' => 'Int',
15 );
16
17 static $has_many = array(
18 'Items' => 'AdvancedSliderHomepageWidget_Item'
19 );
20
21 static $defaults = array(
22 'SlideHeight' => 300,
23 'ShowNavigation' => 1,
24 'DelayTime' => 5,
25 );
26
27 28 29 30 31
32 static function set_animation_types($types = array()) {
33 if (!is_array($types)) $types = array($types);
34 self::$animation_types = $types;
35 }
36
37 function getCMSFields() {
38 $fields = parent::getCMSFields();
39
40 $dom = new ImageDataObjectManager(
41 $this,
42 'Items',
43 'AdvancedSliderHomepageWidget_Item',
44 null,
45 null,
46 null,
47 "WidgetID = {$this->ID}"
48 );
49 $dom->setRelationAutoSetting(true);
50
51 $previewFields = new LiteralField("css", "<style>div#Root_Main.tab {height: 80%}</style>");
52 $dom->setPreviewFieldFor($previewFields);
53
54 $fields->replaceField('Items', $dom);
55 return $fields;
56 }
57
58 59 60 61 62
63 function ActiveItems() {
64 return $this->Items('Active = 1');
65 }
66
67 68 69 70 71
72 function DelayTimeMS() {
73 return $this->DelayTime * 1000;
74 }
75 }
76
77 class AdvancedSliderHomepageWidget_Item extends WebylonWidget_Item {
78 static $db = array(
79 'Text' => 'Text',
80 'ButtonText' => 'Varchar(255)',
81 'TextPlace' => "Enum('left,right')",
82 );
83
84 static $has_one = array(
85 'Image' => 'Image',
86 'MobImage' => 'Image',
87 );
88
89 static function get_text_places() {
90 $rs = array();
91 foreach(singleton('AdvancedSliderHomepageWidget_Item')->dbObject('TextPlace')->enumValues() as $value) {
92 $rs[$value] = _t("AdvancedSliderHomepageWidget_Item.TextPlace_{$value}");
93 }
94 return $rs;
95 }
96
97 function getCMSFields() {
98 $fields = parent::getCMSFields();
99
100 $fields->removeByName('Image');
101 $tab = $fields->findOrMakeTab('Root.Image', $this->fieldLabel('Image'));
102 if ($this->ImageID && $this->Image()->ID) {
103 $URL = $this->Image()->SetWidth(450)->URL;
104 $tab->push(new LiteralField("icon", "<div class='current-image'><img src='$URL' alt='".$this->Image()->Filename."' title='".$this->Image()->Filename."' /></div>"));
105 }
106
107 $mobImage = $fields->dataFieldByName('MobImage');
108 $fields->removeByName('MobImage');
109 $tab->push($mobImage);
110
111 $fields->replaceField('TextPlace', new DropdownField('TextPlace', $this->fieldLabel('TextPlace'), self::get_text_places()));
112
113 return $fields;
114 }
115
116 function MobileImage() {
117 if ($this->MobImageID && $this->MobImage()->ID) {
118 return $this->MobImage();
119 }
120 return $this->Image();
121 }
122
123 function AutoresizeMaxWidth() {
124 return WebylonWidget::$max_image_width;
125 }
126
127 function AutoresizeMaxHeight() {
128 return WebylonWidget::$max_image_heigth;
129 }
130 }
131
[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.
-