Passed
Push — 2 ( 020ae5...a86f0f )
by
unknown
03:52
created

CarouselSlide::canView()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

99
        /** @scrutinizer ignore-call */ 
100
        $parent = $this->Parent(); 
Loading history...
100
        $profile = $parent->CarouselProfile;
101
102
        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...
103
    }
104
105
    public function getCMSFields()
106
    {
107
        $fields = parent::getCMSFields();
108
109
        $fields->removeByName('ParentID');
110
        $fields->removeByName('Sort');
111
		/*$fields->addFieldToTab(
112
			'Root.Main', 
113
			LinkField::create('LinkID', 'Link to page or file')
114
		);*/
115
116
        return $fields;
117
    }
118
119
    public function getThumbnail()
120
    {
121
        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

121
        if($this->/** @scrutinizer ignore-call */ Image()) {
Loading history...
122
            return $this->Image()->CMSThumbnail();
123
        } else {
124
            return '(No Image)';
125
        }
126
    }
127
    
128
    /**
129
     * Check parent permissions
130
     *
131
     * @return Boolean
132
     */
133
    public function canView($member = null) {
134
        $extended = $this->extend('canView', $member);
135
        if($extended && $extended !== null) return $extended;
136
137
        return $this->Parent()->canView($member);
138
    }
139
140
    /**
141
     * Anyone can create a carousel slide
142
     *
143
     * @return Boolean
144
     */
145
    public function canCreate($member = null, $context = []) {
146
        $extended = $this->extend('canCreate', $member, $context);
147
        if($extended && $extended !== null) return $extended;
148
149
        return true;
150
    }
151
152
    /**
153
     * Check parent permissions
154
     *
155
     * @return Boolean
156
     */
157
    public function canEdit($member = null) {
158
        $extended = $this->extend('canEdit', $member);
159
        if($extended && $extended !== null) return $extended;
160
161
        return $this->Parent()->canEdit($member);
162
    }
163
164
    /**
165
     * Check parent permissions
166
     *
167
     * @return Boolean
168
     */
169
    public function canDelete($member = null) {
170
        $extended = $this->extend('canDelete', $member);
171
        if($extended && $extended !== null) return $extended;
172
173
        return $this->Parent()->canEdit($member);
174
    }
175
}
176