CarouselSlide::getCMSFields()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 12
c 2
b 0
f 0
nc 1
nop 0
dl 0
loc 20
rs 9.8666
1
<?php
2
3
namespace ilateral\SilverStripe\Carousel\Model;
4
5
use SilverStripe\Assets\Image;
6
use gorriecoe\Link\Models\Link;
7
use SilverStripe\ORM\DataObject;
8
use gorriecoe\LinkField\LinkField;
9
use SilverStripe\CMS\Model\SiteTree;
10
11
/**
12
 * Representation of a slide object that can be extended to add extra
13
 * data (such as links, additional content, etc)
14
 * 
15
 * @author i-lateral (http://www.i-lateral.com)
16
 * @package carousel
17
 */
18
class CarouselSlide extends DataObject
19
{
20
21
    private static $table_name = 'CarouselSlide';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
22
23
    /**
24
     * DB Columns
25
     * 
26
     * @var array
27
     * @config
28
     */
29
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
30
        'Title'     => 'Varchar(99)',
31
        'Sort'      => 'Int'
32
    ];
33
34
    /**
35
     * Has One relations
36
     * 
37
     * @var array
38
     * @config
39
     */
40
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
41
        'Parent'    => SiteTree::class,
42
        'Image'     => Image::class,
43
        'Link'		=> Link::class
44
    ];
45
46
    /**
47
     * Ownership of relations
48
     *
49
     * @var array
50
     */
51
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
52
        'Image',
53
        'Link'
54
    ];
55
56
    /**
57
     * Default casting for functions to templates
58
     * 
59
     * @var array
60
     * @config
61
     */
62
    private static $casting = array(
0 ignored issues
show
introduced by
The private property $casting is not used, and could be removed.
Loading history...
63
        'Thumbnail' => 'Varchar'
64
    );
65
66
    /**
67
     * Summary columns/fields for this object
68
     * 
69
     * @var array
70
     * @config
71
     */
72
    private static $summary_fields = array(
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
73
        'Thumbnail' => 'Image',
74
        'Title'     => 'Title',
75
        'Link.Title'=> 'Link'
76
    );
77
78
    /**
79
     * Default sorting of this object
80
     * 
81
     * @var string
82
     * @config
83
     */
84
    private static $default_sort = "Sort ASC";
0 ignored issues
show
introduced by
The private property $default_sort is not used, and could be removed.
Loading history...
85
86
    /**
87
     * Default image profile to use
88
     *
89
     * @var string
90
     * @config
91
     */
92
    private static $default_proile = 'ShortCarousel';
93
    
94
    /**
95
     * Get fully rendered image for template
96
     *
97
     * @return HTMLText
0 ignored issues
show
Bug introduced by
The type ilateral\SilverStripe\Carousel\Model\HTMLText was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
98
     */
99
    public function getRenderedImage()
100
    {
101
        $parent = $this->Parent(); 
0 ignored issues
show
Bug introduced by
The method Parent() does not exist on ilateral\SilverStripe\Carousel\Model\CarouselSlide. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

101
        /** @scrutinizer ignore-call */ 
102
        $parent = $this->Parent(); 
Loading history...
102
        $profile = $parent->CarouselProfile;
103
        if ($profile) {
104
            return $this->Image->{$profile}();
0 ignored issues
show
Bug Best Practice introduced by
The property Image does not exist on ilateral\SilverStripe\Carousel\Model\CarouselSlide. Since you implemented __get, consider adding a @property annotation.
Loading history...
105
        } else {
106
            $profile = $this->config()->default_proile;
107
        }
108
109
        return $this->Image->{$profile}();
110
    }
111
112
    public function getCMSFields()
113
    {
114
        $fields = parent::getCMSFields();
115
116
        $fields->removeByName([
117
            'ParentID',
118
            'Sort',
119
            'LinkID'
120
        ]);
121
122
		$fields->addFieldToTab(
123
			'Root.Main', 
124
			LinkField::create(
125
                'Link',
126
                $this->fieldLabel('Link'),
127
                $this
128
            )
129
		);
130
131
        return $fields;
132
    }
133
134
    public function getThumbnail()
135
    {
136
        if($this->Image()) {
0 ignored issues
show
Bug introduced by
The method Image() does not exist on ilateral\SilverStripe\Carousel\Model\CarouselSlide. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

136
        if($this->/** @scrutinizer ignore-call */ Image()) {
Loading history...
137
            return $this->Image()->CMSThumbnail();
138
        } else {
139
            return '(No Image)';
140
        }
141
    }
142
    
143
    /**
144
     * Check parent permissions
145
     *
146
     * @return Boolean
147
     */
148
    public function canView($member = null) {
149
        $extended = $this->extend('canView', $member);
150
        if($extended && $extended !== null) return $extended;
151
152
        return $this->Parent()->canView($member);
153
    }
154
155
    /**
156
     * Anyone can create a carousel slide
157
     *
158
     * @return Boolean
159
     */
160
    public function canCreate($member = null, $context = []) {
161
        $extended = $this->extend('canCreate', $member, $context);
162
        if($extended && $extended !== null) return $extended;
163
164
        return true;
165
    }
166
167
    /**
168
     * Check parent permissions
169
     *
170
     * @return Boolean
171
     */
172
    public function canEdit($member = null) {
173
        $extended = $this->extend('canEdit', $member);
174
        if($extended && $extended !== null) return $extended;
175
176
        return $this->Parent()->canEdit($member);
177
    }
178
179
    /**
180
     * Check parent permissions
181
     *
182
     * @return Boolean
183
     */
184
    public function canDelete($member = null) {
185
        $extended = $this->extend('canDelete', $member);
186
        if($extended && $extended !== null) return $extended;
187
188
        return $this->Parent()->canEdit($member);
189
    }
190
}
191