HeaderGalleryImage::canDelete()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
4
5
/**
6
 * StartGeneratedWithDataObjectAnnotator
7
 * @property string Title
8
 * @property string Copyright
9
 * @property string Caption
10
 * @property int SortOrder
11
 * @property int AttachmentID
12
 * @property int ResourcePageID
13
 * @property int SiteConfigID
14
 * @method Image Attachment
15
 * @method Page ResourcePage
16
 * @method SiteConfig SiteConfig
17
 * EndGeneratedWithDataObjectAnnotator
18
 */
19
class HeaderGalleryImage extends DataObject
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
20
{
21
22
23
    private static $db = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $db is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
24
        'Title' => 'Text',
25
        'Copyright' => 'Text',
26
        'Caption' => 'Text',
27
        'SortOrder' => 'Int'
28
    );
29
30
    private static $has_one = array(
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $has_one is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
31
        'Attachment' => 'Image',
32
        'ResourcePage' => 'Page',
33
        'SiteConfig' => 'SiteConfig'
34
    );
35
36
37
    private static $default_sort = 'SortOrder ASC';
0 ignored issues
show
Comprehensibility introduced by
Consider using a different property name as you override a private property of the parent class.
Loading history...
Unused Code introduced by
The property $default_sort is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
38
39
    private static $delete_permission = "CMS_ACCESS_CMSMain";
0 ignored issues
show
Unused Code introduced by
The property $delete_permission is not used and could be removed.

This check marks private properties in classes that are never used. Those properties can be removed.

Loading history...
40
41
    public function getCMSFields()
42
    {
43
        $fields = FieldList::create(
44
            TextField::create('Title'),
45
            TextField::create('Copyright'),
46
            TextareaField::create('Caption'),
47
            $imageField = UploadField::create('Attachment')
48
        );
49
        $imageField->setAllowedFileCategories('image');
50
        $imageField->setAllowedMaxFileNumber(1);
51
52
        return $fields;
53
    }
54
55
    /**
56
     * Show delete Button in ImageGalleryManager
57
     */
58
59
    public function canDelete($member = null)
60
    {
61
        return Permission::check($this->stat('delete_permission'));
62
    }
63
64
    public function canView($member = null)
65
    {
66
        return true;
67
    }
68
69
    public function canCreate($member = null)
70
    {
71
        return Permission::check($this->stat('delete_permission'));
72
    }
73
74
    public function canEdit($member = null)
75
    {
76
        return Permission::check($this->stat('delete_permission'));
77
    }
78
79
    /**
80
     * shortcut for displaying copyright information and caption
81
     * @return string
82
     */
83
    public function getDescription()
84
    {
85
        return join(' - ', array_filter([$this->Caption, $this->getCopy()]));
86
    }
87
88
    /**
89
     * replaces "(c)" with html copyright sign
90
     * @return mixed
91
     */
92
    public function getCopy()
93
    {
94
        return str_replace('(c)', '&copy;', $this->Copyright);
95
    }
96
}
97