Passed
Pull Request — 4 (#200)
by
unknown
02:50
created
src/ORM/FlexSlider.php 1 patch
Indentation   +199 added lines, -199 removed lines patch added patch discarded remove patch
@@ -37,194 +37,194 @@  discard block
 block discarded – undo
37 37
  */
38 38
 class FlexSlider extends DataExtension
39 39
 {
40
-    use Configurable;
40
+	use Configurable;
41 41
 
42
-    /**
43
-     * @var array
44
-     */
45
-    private static $db = [
46
-        'Animation' => "Enum('slide, fade', 'slide')",
47
-        'Loop' => 'Boolean',
48
-        'Animate' => 'Boolean',
49
-        'ThumbnailNav' => 'Boolean',
50
-        'SliderControlNav' => 'Boolean',
51
-        'SliderDirectionNav' => 'Boolean',
52
-        'CarouselControlNav' => 'Boolean',
53
-        'CarouselDirectionNav' => 'Boolean',
54
-        'CarouselThumbnailCt' => 'Int',
55
-        'FlexSliderSpeed' => 'Double',
56
-    ];
42
+	/**
43
+	 * @var array
44
+	 */
45
+	private static $db = [
46
+		'Animation' => "Enum('slide, fade', 'slide')",
47
+		'Loop' => 'Boolean',
48
+		'Animate' => 'Boolean',
49
+		'ThumbnailNav' => 'Boolean',
50
+		'SliderControlNav' => 'Boolean',
51
+		'SliderDirectionNav' => 'Boolean',
52
+		'CarouselControlNav' => 'Boolean',
53
+		'CarouselDirectionNav' => 'Boolean',
54
+		'CarouselThumbnailCt' => 'Int',
55
+		'FlexSliderSpeed' => 'Double',
56
+	];
57 57
 
58
-    /**
59
-     * @var array
60
-     */
61
-    private static $has_many = [
62
-        'Slides' => SlideImage::class,
63
-    ];
58
+	/**
59
+	 * @var array
60
+	 */
61
+	private static $has_many = [
62
+		'Slides' => SlideImage::class,
63
+	];
64 64
 
65
-    /**
66
-     *
67
-     */
68
-    public function populateDefaults()
69
-    {
70
-        $this->owner->Loop = 1;
71
-        $this->owner->Animate = 1;
72
-        $this->owner->SliderControlNav = 0;
73
-        $this->owner->SliderDirectionNav = 1;
74
-        $this->owner->CarouselControlNav = 0;
75
-        $this->owner->CarouselDirectionNav = 1;
76
-        $this->owner->CarouselThumbnailCt = 6;
77
-        $this->owner->FlexSliderSpeed = $this->getDefaultSpeed();
65
+	/**
66
+	 *
67
+	 */
68
+	public function populateDefaults()
69
+	{
70
+		$this->owner->Loop = 1;
71
+		$this->owner->Animate = 1;
72
+		$this->owner->SliderControlNav = 0;
73
+		$this->owner->SliderDirectionNav = 1;
74
+		$this->owner->CarouselControlNav = 0;
75
+		$this->owner->CarouselDirectionNav = 1;
76
+		$this->owner->CarouselThumbnailCt = 6;
77
+		$this->owner->FlexSliderSpeed = $this->getDefaultSpeed();
78 78
 
79
-        return parent::populateDefaults();
80
-    }
79
+		return parent::populateDefaults();
80
+	}
81 81
 
82
-    /**
83
-     * @param FieldList $fields
84
-     */
85
-    public function updateCMSFields(FieldList $fields)
86
-    {
87
-        $fields->removeByName([
88
-            'Animation',
89
-            'Loop',
90
-            'Animate',
91
-            'ThumbnailNav',
92
-            'SliderControlNav',
93
-            'SliderDirectionNav',
94
-            'CarouselControlNav',
95
-            'CarouselDirectionNav',
96
-            'CarouselThumbnailCt',
97
-            'FlexSliderSpeed',
98
-            'Slides',
99
-        ]);
82
+	/**
83
+	 * @param FieldList $fields
84
+	 */
85
+	public function updateCMSFields(FieldList $fields)
86
+	{
87
+		$fields->removeByName([
88
+			'Animation',
89
+			'Loop',
90
+			'Animate',
91
+			'ThumbnailNav',
92
+			'SliderControlNav',
93
+			'SliderDirectionNav',
94
+			'CarouselControlNav',
95
+			'CarouselDirectionNav',
96
+			'CarouselThumbnailCt',
97
+			'FlexSliderSpeed',
98
+			'Slides',
99
+		]);
100 100
 
101
-        // Slides
102
-        if ($this->owner->ID) {
103
-            $config = GridFieldConfig_RecordEditor::create();
104
-            $config->addComponent(new GridFieldOrderableRows('SortOrder'));
105
-            $config->removeComponentsByType([
106
-                GridFieldAddExistingAutocompleter::class,
107
-                GridFieldDeleteAction::class,
108
-            ]);
109
-            $SlidesField = GridField::create(
110
-                'Slides',
111
-                _t(__CLASS__ . '.SLIDES', 'Slides'),
112
-                $this->owner->Slides()->sort('SortOrder'),
113
-                $config
114
-            );
101
+		// Slides
102
+		if ($this->owner->ID) {
103
+			$config = GridFieldConfig_RecordEditor::create();
104
+			$config->addComponent(new GridFieldOrderableRows('SortOrder'));
105
+			$config->removeComponentsByType([
106
+				GridFieldAddExistingAutocompleter::class,
107
+				GridFieldDeleteAction::class,
108
+			]);
109
+			$SlidesField = GridField::create(
110
+				'Slides',
111
+				_t(__CLASS__ . '.SLIDES', 'Slides'),
112
+				$this->owner->Slides()->sort('SortOrder'),
113
+				$config
114
+			);
115 115
 
116
-            $slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
116
+			$slideTitle = $this->owner->stat('slide_tab_title') ?: _t(__CLASS__ . '.SLIDES', 'Slides');
117 117
 
118
-            $animations = [];
119
-            $animationOptions = $this->owner->dbObject('Animation')->getEnum();
120
-            foreach ($animationOptions as $value) {
121
-                $animations[$value] = _t(__CLASS__ . ".$value", $value);
122
-            }
118
+			$animations = [];
119
+			$animationOptions = $this->owner->dbObject('Animation')->getEnum();
120
+			foreach ($animationOptions as $value) {
121
+				$animations[$value] = _t(__CLASS__ . ".$value", $value);
122
+			}
123 123
 
124
-            $fields->addFieldsToTab("Root.{$slideTitle}", [
125
-                $SlidesField,
126
-                ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
127
-                    DropdownField::create(
128
-                        'Animation',
129
-                        _t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
130
-                        $animations
131
-                    ),
132
-                    CheckboxField::create(
133
-                        'Animate',
134
-                        _t(__CLASS__ . '.ANIMATE', 'Animate automatically')
135
-                    ),
136
-                    CheckboxField::create(
137
-                        'Loop',
138
-                        _t(__CLASS__ . '.LOOP', 'Loop the carousel')
139
-                    ),
140
-                    CheckboxField::create(
141
-                        'SliderControlNav',
142
-                        _t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
143
-                    ),
144
-                    CheckboxField::create(
145
-                        'SliderDirectionNav',
146
-                        _t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
147
-                    ),
148
-                    CheckboxField::create(
149
-                        'ThumbnailNav',
150
-                        _t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
151
-                    ),
152
-                    //DisplayLogicWrapper::create(
153
-                    CheckboxField::create(
154
-                        'CarouselControlNav',
155
-                        _t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
156
-                    ),
157
-                    CheckboxField::create(
158
-                        'CarouselDirectionNav',
159
-                        _t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
160
-                    ),
161
-                    NumericField::create(
162
-                        'CarouselThumbnailCt',
163
-                        _t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
164
-                    ),
165
-                    NumericField::create(
166
-                        'FlexSliderSpeed',
167
-                        _t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
168
-                    )
169
-                        ->setDescription('In Seconds')
170
-                        ->setScale(2),
171
-                ]),
172
-            ]);
173
-        }
174
-    }
124
+			$fields->addFieldsToTab("Root.{$slideTitle}", [
125
+				$SlidesField,
126
+				ToggleCompositeField::create('ConfigHD', _t(__CLASS__ . '.SettingsLabel', 'Slider Settings'), [
127
+					DropdownField::create(
128
+						'Animation',
129
+						_t(__CLASS__ . '.ANIMATION_OPTION', 'Animation option'),
130
+						$animations
131
+					),
132
+					CheckboxField::create(
133
+						'Animate',
134
+						_t(__CLASS__ . '.ANIMATE', 'Animate automatically')
135
+					),
136
+					CheckboxField::create(
137
+						'Loop',
138
+						_t(__CLASS__ . '.LOOP', 'Loop the carousel')
139
+					),
140
+					CheckboxField::create(
141
+						'SliderControlNav',
142
+						_t(__CLASS__ . '.CONTROL_NAV', 'Show ControlNav')
143
+					),
144
+					CheckboxField::create(
145
+						'SliderDirectionNav',
146
+						_t(__CLASS__ . '.DIRECTION_NAV', 'Show DirectionNav')
147
+					),
148
+					CheckboxField::create(
149
+						'ThumbnailNav',
150
+						_t(__CLASS__ . '.THUMBNAIL_NAV', 'Thumbnail Navigation')
151
+					),
152
+					//DisplayLogicWrapper::create(
153
+					CheckboxField::create(
154
+						'CarouselControlNav',
155
+						_t(__CLASS__ . '.CAROUSEL_CONTROL_NAV', 'Show Carousel ControlNav')
156
+					),
157
+					CheckboxField::create(
158
+						'CarouselDirectionNav',
159
+						_t(__CLASS__ . '.CAROUSEL_DIRECTION_NAV', 'Show Carousel DirectionNav')
160
+					),
161
+					NumericField::create(
162
+						'CarouselThumbnailCt',
163
+						_t(__CLASS__ . '.CAROUSEL_THUMBNAIL_COUNT', 'Number of thumbnails')
164
+					),
165
+					NumericField::create(
166
+						'FlexSliderSpeed',
167
+						_t(__CLASS__ . '.SLIDER_SPEED', 'Slider Speed')
168
+					)
169
+						->setDescription('In Seconds')
170
+						->setScale(2),
171
+				]),
172
+			]);
173
+		}
174
+	}
175 175
 
176
-    /**
177
-     * @return mixed
178
-     */
179
-    public function getSlideShow()
180
-    {
181
-        $owner = $this->owner;
176
+	/**
177
+	 * @return mixed
178
+	 */
179
+	public function getSlideShow()
180
+	{
181
+		$owner = $this->owner;
182 182
 
183
-        if (!($owner instanceof SiteTree)) {
184
-            $this->getCustomScript();
185
-        }
183
+		if (!($owner instanceof SiteTree)) {
184
+			$this->getCustomScript();
185
+		}
186 186
 
187
-        return $this->owner->Slides()->sort('SortOrder');
188
-    }
187
+		return $this->owner->Slides()->sort('SortOrder');
188
+	}
189 189
 
190
-    /**
191
-     * add requirements to PageController init()
192
-     */
193
-    public function contentcontrollerInit()
194
-    {
195
-        // only call custom script if page has Slides and DataExtension
196
-        if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) {
197
-            if ($this->owner->getSlideShow()->exists()) {
198
-                $this->getCustomScript();
199
-            }
200
-        }
201
-    }
190
+	/**
191
+	 * add requirements to PageController init()
192
+	 */
193
+	public function contentcontrollerInit()
194
+	{
195
+		// only call custom script if page has Slides and DataExtension
196
+		if (DataObject::has_extension($this->owner->Classname, FlexSlider::class)) {
197
+			if ($this->owner->getSlideShow()->exists()) {
198
+				$this->getCustomScript();
199
+			}
200
+		}
201
+	}
202 202
 
203
-    /**
204
-     *
205
-     */
206
-    public function getCustomScript()
207
-    {
203
+	/**
204
+	 *
205
+	 */
206
+	public function getCustomScript()
207
+	{
208 208
 
209
-        if ($this->owner()->config('clear_requirements')) {
210
-            return;
211
-        }
209
+		if ($this->owner()->config('clear_requirements')) {
210
+			return;
211
+		}
212 212
 
213
-        // Flexslider options
214
-        $sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
213
+		// Flexslider options
214
+		$sync = ($this->owner->ThumbnailNav == true) ? "sync: '.fs-carousel:eq('+index+')'," : '';
215 215
 
216
-        $before = $this->owner->hasMethod('flexSliderBeforeAction')
217
-            ? $this->owner->flexSliderBeforeAction()
218
-            : 'function(){}';
216
+		$before = $this->owner->hasMethod('flexSliderBeforeAction')
217
+			? $this->owner->flexSliderBeforeAction()
218
+			: 'function(){}';
219 219
 
220
-        $after = $this->owner->hasMethod('flexSliderAfterAction')
221
-            ? $this->owner->flexSliderAfterAction()
222
-            : 'function(){}';
220
+		$after = $this->owner->hasMethod('flexSliderAfterAction')
221
+			? $this->owner->flexSliderAfterAction()
222
+			: 'function(){}';
223 223
 
224
-        $speed = $this->getSlideshowSpeed();
224
+		$speed = $this->getSlideshowSpeed();
225 225
 
226
-        Requirements::customScript(
227
-            "(function($) {
226
+		Requirements::customScript(
227
+			"(function($) {
228 228
                 $(document).ready(function(){
229 229
                     jQuery('.flexslider').each(function(index){
230 230
 
@@ -270,40 +270,40 @@  discard block
 block discarded – undo
270 270
                     })
271 271
                 });
272 272
             }(jQuery));',
273
-            'flexsliderjquery'
274
-        );
275
-    }
273
+			'flexsliderjquery'
274
+		);
275
+	}
276 276
 
277
-    /**
278
-     * @return int
279
-     */
280
-    public function getSlideshowSpeed()
281
-    {
282
-        $speed = $this->owner->FlexSliderSpeed > 0
283
-            ? $this->owner->FlexSliderSpeed
284
-            : $this->getDefaultSpeed();
277
+	/**
278
+	 * @return int
279
+	 */
280
+	public function getSlideshowSpeed()
281
+	{
282
+		$speed = $this->owner->FlexSliderSpeed > 0
283
+			? $this->owner->FlexSliderSpeed
284
+			: $this->getDefaultSpeed();
285 285
 
286
-        return $speed * 1000;
287
-    }
286
+		return $speed * 1000;
287
+	}
288 288
 
289
-    /**
290
-     * @return mixed
291
-     */
292
-    protected function getDefaultSpeed()
293
-    {
294
-        return $this->owner->config()->get('flex_slider_speed')
295
-            ?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed');
296
-    }
289
+	/**
290
+	 * @return mixed
291
+	 */
292
+	protected function getDefaultSpeed()
293
+	{
294
+		return $this->owner->config()->get('flex_slider_speed')
295
+			?: Config::inst()->get(FlexSlider::class, 'flex_slider_speed');
296
+	}
297 297
 
298
-    /**
299
-     *
300
-     */
301
-    public function onBeforeWrite()
302
-    {
303
-        parent::onBeforeWrite();
298
+	/**
299
+	 *
300
+	 */
301
+	public function onBeforeWrite()
302
+	{
303
+		parent::onBeforeWrite();
304 304
 
305
-        if (!$this->owner->CarouselThumbnailCt) {
306
-            $this->owner->CarouselThumbnailCt = 6;
307
-        }
308
-    }
305
+		if (!$this->owner->CarouselThumbnailCt) {
306
+			$this->owner->CarouselThumbnailCt = 6;
307
+		}
308
+	}
309 309
 }
Please login to merge, or discard this patch.