Completed
Pull Request — 1.0 (#95)
by Jason
04:49
created

defaultSliderSettings()   C

Complexity

Conditions 7
Paths 2

Size

Total Lines 30
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 6.7272
c 0
b 0
f 0
cc 7
eloc 22
nc 2
nop 0
1
<?php
2
3
class SlideThumbnailNavMigrationTask extends BuildTask
4
{
5
    /**
6
     * @var string
7
     */
8
    protected $title = 'FlexSlider Default Values';
9
    /**
10
     * @var string
11
     */
12
    protected $description = 'Set default values for slider after the thumbnail nav update';
13
    /**
14
     * @var bool
15
     */
16
    protected $enabled = true;
17
    /**
18
     * @param $request
19
     */
20
    public function run($request)
21
    {
22
        $this->defaultSliderSettings();
23
    }
24
    /**
25
     *
26
     */
27
    public function defaultSliderSettings()
28
    {
29
        $ct = 0;
30
31
        $objects = ClassInfo::subclassesFor('DataObject');
32
        if ($objects) {
33
            unset($objects['DataObject']);
34
            foreach ($objects as $object) {
35
                if (singleton($object)->hasExtension('FlexSlider')) {
36
                    foreach ($object::get() as $result) {
37
                        $result->Loop = 1;
38
                        $result->Animate = 1;
39
                        $result->SliderControlNav = 1;
40
                        $result->SliderDirectionNav = 1;
41
                        $result->CarouselControlNav = 0;
42
                        $result->CarouselDirectionNav = 1;
43
                        $result->CarouselThumbnailCt = 6;
44
                        if ($result InstanceOf SiteTree || singleton($object)->hasExtension('VersionedDataobject')) {
45
                            $result->writeToStage('Stage');
46
                            $result->publish('Stage', 'Live');
47
                        } else {
48
                            $result->write();
49
                        }
50
                        $ct++;
51
                    }
52
                }
53
            }
54
        }
55
        echo '<p>'.$ct.' Sliders updated.</p>';
56
    }
57
}