1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Class PageSectionObject |
5
|
|
|
* |
6
|
|
|
* @property string $Name |
7
|
|
|
* @property string $Title |
8
|
|
|
* @property HTMLText $Content |
9
|
|
|
* @property int $SortOrder |
10
|
|
|
* @property int $ImageID |
11
|
|
|
* @property int $PageSectionBlockID |
12
|
|
|
*/ |
13
|
|
|
class PageSectionObject extends DataObject |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @return string |
17
|
|
|
*/ |
18
|
|
|
private static $singular_name = 'Page Section'; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @return string |
22
|
|
|
*/ |
23
|
|
|
private static $plural_name = 'Page Sections'; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var array |
27
|
|
|
*/ |
28
|
|
|
private static $db = array( |
29
|
|
|
'Name' => 'Varchar(255)', |
30
|
|
|
'Title' => 'Varchar(255)', |
31
|
|
|
'Content' => 'HTMLText', |
32
|
|
|
'SortOrder' => 'Int', |
33
|
|
|
); |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @var array |
37
|
|
|
*/ |
38
|
|
|
private static $has_one = array( |
39
|
|
|
'Image' => 'Image', |
40
|
|
|
'PageSectionBlock' => 'PageSectionBlock', |
41
|
|
|
); |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @var string |
45
|
|
|
*/ |
46
|
|
|
private static $default_sort = 'Name ASC'; |
|
|
|
|
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var array |
50
|
|
|
*/ |
51
|
|
|
private static $summary_fields = array( |
52
|
|
|
'Image.CMSThumbnail' => 'Image', |
53
|
|
|
'Name' => 'Name', |
54
|
|
|
'Title' => 'Title', |
55
|
|
|
); |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @var array |
59
|
|
|
*/ |
60
|
|
|
private static $searchable_fields = array( |
61
|
|
|
'Name' => 'Name', |
62
|
|
|
'Title' => 'Title', |
63
|
|
|
); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* @return FieldList |
67
|
|
|
*/ |
68
|
|
|
public function getCMSFields() |
69
|
|
|
{ |
70
|
|
|
$fields = parent::getCMSFields(); |
71
|
|
|
|
72
|
|
|
$fields->removeByName(array( |
73
|
|
|
'PageSectionBlockID', |
74
|
|
|
'SortOrder', |
75
|
|
|
)); |
76
|
|
|
|
77
|
|
|
$fields->dataFieldByName('Name')->setDescription('For internal reference only'); |
78
|
|
|
|
79
|
|
|
$image = $fields->dataFieldByName('Image'); |
80
|
|
|
$image->setFolderName('Uploads/PageSections'); |
81
|
|
|
$fields->insertBefore($image, 'Content'); |
|
|
|
|
82
|
|
|
|
83
|
|
|
return $fields; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* @return ValidationResult |
88
|
|
|
*/ |
89
|
|
|
public function validate() |
90
|
|
|
{ |
91
|
|
|
$result = parent::validate(); |
92
|
|
|
|
93
|
|
|
if (!$this->Name) { |
94
|
|
|
$result->error('Name is requied before you can save'); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $result; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Set permissions, allow all users to access by default. |
102
|
|
|
* Override in descendant classes, or use PermissionProvider. |
103
|
|
|
*/ |
104
|
|
|
|
105
|
|
|
/** |
106
|
|
|
* @param null $member |
107
|
|
|
* |
108
|
|
|
* @return bool |
109
|
|
|
*/ |
110
|
|
|
public function canCreate($member = null) |
111
|
|
|
{ |
112
|
|
|
return true; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @param null $member |
117
|
|
|
* |
118
|
|
|
* @return bool |
119
|
|
|
*/ |
120
|
|
|
public function canView($member = null) |
121
|
|
|
{ |
122
|
|
|
return true; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param null $member |
127
|
|
|
* |
128
|
|
|
* @return bool |
129
|
|
|
*/ |
130
|
|
|
public function canEdit($member = null) |
131
|
|
|
{ |
132
|
|
|
return true; |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* @param null $member |
137
|
|
|
* |
138
|
|
|
* @return bool |
139
|
|
|
*/ |
140
|
|
|
public function canDelete($member = null) |
141
|
|
|
{ |
142
|
|
|
return true; |
143
|
|
|
} |
144
|
|
|
} |
This check marks private properties in classes that are never used. Those properties can be removed.