FileListObject::fieldLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 1
dl 0
loc 9
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Dynamic\Elements\FileList\Model;
4
5
use Dynamic\Elements\FileList\Elements\ElementFileList;
6
use SilverStripe\Assets\File;
7
use SilverStripe\ORM\DataObject;
8
use SilverStripe\Security\Permission;
9
10
class FileListObject extends DataObject
11
{
12
    /**
13
     * @var string
14
     */
15
    private static $singular_name = 'File';
0 ignored issues
show
introduced by
The private property $singular_name is not used, and could be removed.
Loading history...
16
17
    /**
18
     * @var string
19
     */
20
    private static $plural_name = 'Files';
0 ignored issues
show
introduced by
The private property $plural_name is not used, and could be removed.
Loading history...
21
22
    /**
23
     * @var array
24
     */
25
    private static $db = [
0 ignored issues
show
introduced by
The private property $db is not used, and could be removed.
Loading history...
26
        'Title' => 'Varchar(255)',
27
        'SortOrder' => "Int",
28
    ];
29
30
    /**
31
     * @var array
32
     */
33
    private static $has_one = [
0 ignored issues
show
introduced by
The private property $has_one is not used, and could be removed.
Loading history...
34
        'FileList' => ElementFileList::class,
35
        'File' => File::class,
36
    ];
37
38
    /**
39
     * @var array
40
     */
41
    private static $owns = [
0 ignored issues
show
introduced by
The private property $owns is not used, and could be removed.
Loading history...
42
        'File',
43
    ];
44
45
    /**
46
     * @var array
47
     */
48 1
    private static $summary_fields = [
0 ignored issues
show
introduced by
The private property $summary_fields is not used, and could be removed.
Loading history...
49
        'File.Name',
50 1
        'Title',
51
    ];
52 1
53 1
    /**
54
     * @param bool $includerelations
55
     * @return array
56 1
     */
57
    public function fieldLabels($includerelations = true)
58
    {
59
        $labels = parent::fieldLabels($includerelations);
60
61
        $labels['Title'] = _t(__CLASS__.'.TitleLabel', 'Title');
62
        $labels['File.Name'] = _t(__CLASS__.'.FileNameLabel', 'File');
63
        $labels['File'] = _t(__CLASS__.'.FileLabel', 'File');
64
65
        return $labels;
66
    }
67
68
    /**
69
     * @var string
70
     */
71
    private static $table_name = 'FileListObject';
0 ignored issues
show
introduced by
The private property $table_name is not used, and could be removed.
Loading history...
72
73
    /**
74
     * @return \SilverStripe\Forms\FieldList
75
     */
76
    public function getCMSFields()
77
    {
78
        $fields = parent::getCMSFields();
79
80
        $fields->dataFieldByName('File')
81
            ->setTitle($this->fieldLabel('File'))
82
            ->setFolderName('Uploads/Elements/FileList/');
83
84
        $fields->removeByName([
85
            'FileListID',
86
            'SortOrder',
87
        ]);
88
89
        return $fields;
90
    }
91
92
    /**
93
     * Basic permissions, defaults to page perms where possible.
94
     *
95
     * @param \SilverStripe\Security\Member|null $member
96
     * @return boolean
97
     */
98
    public function canView($member = null)
99
    {
100
        $extended = $this->extendedCan(__FUNCTION__, $member);
101
        if ($extended !== null) {
102
            return $extended;
103
        }
104
105
        if ($page = $this->FileList()->getPage()) {
0 ignored issues
show
Bug introduced by
The method FileList() does not exist on Dynamic\Elements\FileList\Model\FileListObject. 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

105
        if ($page = $this->/** @scrutinizer ignore-call */ FileList()->getPage()) {
Loading history...
106
            return $page->canView($member);
107
        }
108
109
        return Permission::check('CMS_ACCESS', 'any', $member);
110
    }
111
112
    /**
113
     * Basic permissions, defaults to page perms where possible.
114
     *
115
     * @param \SilverStripe\Security\Member|null $member
116
     *
117
     * @return boolean
118
     */
119
    public function canEdit($member = null)
120
    {
121
        $extended = $this->extendedCan(__FUNCTION__, $member);
122
        if ($extended !== null) {
123
            return $extended;
124
        }
125
126
        if ($page = $this->FileList()->getPage()) {
127
            return $page->canEdit($member);
128
        }
129
130
        return Permission::check('CMS_ACCESS', 'any', $member);
131
    }
132
133
    /**
134
     * Basic permissions, defaults to page perms where possible.
135
     *
136
     * Uses archive not delete so that current stage is respected i.e if a
137
     * element is not published, then it can be deleted by someone who doesn't
138
     * have publishing permissions.
139
     *
140
     * @param \SilverStripe\Security\Member|null $member
141
     *
142
     * @return boolean
143
     */
144
    public function canDelete($member = null)
145
    {
146
        $extended = $this->extendedCan(__FUNCTION__, $member);
147
        if ($extended !== null) {
148
            return $extended;
149
        }
150
151
        if ($page = $this->FileList()->getPage()) {
152
            return $page->canArchive($member);
153
        }
154
155
        return Permission::check('CMS_ACCESS', 'any', $member);
156
    }
157
158
    /**
159
     * Basic permissions, defaults to page perms where possible.
160
     *
161
     * @param \SilverStripe\Security\Member|null $member
162
     * @param array $context
163
     *
164
     * @return boolean
165
     */
166
    public function canCreate($member = null, $context = array())
167
    {
168
        $extended = $this->extendedCan(__FUNCTION__, $member);
169
        if ($extended !== null) {
170
            return $extended;
171
        }
172
173
        return Permission::check('CMS_ACCESS', 'any', $member);
174
    }
175
}
176