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 |
|
|
|
|
20
|
|
|
{ |
21
|
|
|
|
22
|
|
|
|
23
|
|
|
private static $db = array( |
|
|
|
|
24
|
|
|
'Title' => 'Text', |
25
|
|
|
'Copyright' => 'Text', |
26
|
|
|
'Caption' => 'Text', |
27
|
|
|
'SortOrder' => 'Int' |
28
|
|
|
); |
29
|
|
|
|
30
|
|
|
private static $has_one = array( |
|
|
|
|
31
|
|
|
'Attachment' => 'Image', |
32
|
|
|
'ResourcePage' => 'Page', |
33
|
|
|
'SiteConfig' => 'SiteConfig' |
34
|
|
|
); |
35
|
|
|
|
36
|
|
|
|
37
|
|
|
private static $default_sort = 'SortOrder ASC'; |
|
|
|
|
38
|
|
|
|
39
|
|
|
private static $delete_permission = "CMS_ACCESS_CMSMain"; |
|
|
|
|
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)', '©', $this->Copyright); |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.