|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
class Location extends DataObject implements PermissionProvider |
|
4
|
|
|
{ |
|
5
|
|
|
private static $db = array( |
|
|
|
|
|
|
6
|
|
|
'Title' => 'Varchar(255)', |
|
7
|
|
|
'Featured' => 'Boolean', |
|
8
|
|
|
'Website' => 'Varchar(255)', |
|
9
|
|
|
'Phone' => 'Varchar(40)', |
|
10
|
|
|
'Email' => 'Varchar(255)', |
|
11
|
|
|
'EmailAddress' => 'Varchar(255)', |
|
12
|
|
|
'ShowInLocator' => 'Boolean', |
|
13
|
|
|
); |
|
14
|
|
|
|
|
15
|
|
|
private static $has_one = array( |
|
|
|
|
|
|
16
|
|
|
'Category' => 'LocationCategory', |
|
17
|
|
|
); |
|
18
|
|
|
|
|
19
|
|
|
private static $casting = array( |
|
|
|
|
|
|
20
|
|
|
'distance' => 'Int', |
|
21
|
|
|
); |
|
22
|
|
|
|
|
23
|
|
|
private static $default_sort = 'Title'; |
|
|
|
|
|
|
24
|
|
|
|
|
25
|
|
|
private static $defaults = array( |
|
|
|
|
|
|
26
|
|
|
'ShowInLocator' => true, |
|
27
|
|
|
); |
|
28
|
|
|
|
|
29
|
|
|
private static $singular_name = 'Location'; |
|
|
|
|
|
|
30
|
|
|
private static $plural_name = 'Locations'; |
|
|
|
|
|
|
31
|
|
|
|
|
32
|
|
|
// api access via Restful Server module |
|
33
|
|
|
private static $api_access = true; |
|
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
// search fields for Model Admin |
|
36
|
|
|
private static $searchable_fields = array( |
|
|
|
|
|
|
37
|
|
|
'Title', |
|
38
|
|
|
'Address', |
|
39
|
|
|
'Suburb', |
|
40
|
|
|
'State', |
|
41
|
|
|
'Postcode', |
|
42
|
|
|
'Country', |
|
43
|
|
|
'Website', |
|
44
|
|
|
'Phone', |
|
45
|
|
|
'Email', |
|
46
|
|
|
'Category.ID', |
|
47
|
|
|
'ShowInLocator', |
|
48
|
|
|
'Featured', |
|
49
|
|
|
); |
|
50
|
|
|
|
|
51
|
|
|
// columns for grid field |
|
52
|
|
|
private static $summary_fields = array( |
|
|
|
|
|
|
53
|
|
|
'Title', |
|
54
|
|
|
'Address', |
|
55
|
|
|
'Suburb', |
|
56
|
|
|
'State', |
|
57
|
|
|
'Postcode', |
|
58
|
|
|
'Country', |
|
59
|
|
|
'Category.Name', |
|
60
|
|
|
'ShowInLocator.NiceAsBoolean', |
|
61
|
|
|
'Featured.NiceAsBoolean', |
|
62
|
|
|
'Coords', |
|
63
|
|
|
); |
|
64
|
|
|
|
|
65
|
|
|
// Coords status for $summary_fields |
|
66
|
1 |
|
public function getCoords() |
|
67
|
|
|
{ |
|
68
|
1 |
|
return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
// custom labels for fields |
|
72
|
1 |
|
public function fieldLabels($includerelations = true) |
|
73
|
|
|
{ |
|
74
|
1 |
|
$labels = parent::fieldLabels(); |
|
75
|
|
|
|
|
76
|
1 |
|
$labels['Title'] = 'Name'; |
|
77
|
1 |
|
$labels['Suburb'] = 'City'; |
|
78
|
1 |
|
$labels['Postcode'] = 'Postal Code'; |
|
79
|
1 |
|
$labels['ShowInLocator'] = 'Show'; |
|
80
|
1 |
|
$labels['ShowInLocator.NiceAsBoolean'] = 'Show'; |
|
81
|
1 |
|
$labels['Category.Name'] = 'Category'; |
|
82
|
1 |
|
$labels['Category.ID'] = 'Category'; |
|
83
|
1 |
|
$labels['Email'] = 'Email'; |
|
84
|
1 |
|
$labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
85
|
|
|
$labels['Coords'] = 'Coords'; |
|
86
|
1 |
|
|
|
87
|
|
|
return $labels; |
|
88
|
|
|
} |
|
89
|
1 |
|
|
|
90
|
|
|
public function getCMSFields() |
|
|
|
|
|
|
91
|
1 |
|
{ |
|
92
|
1 |
|
$fields = FieldList::create( |
|
93
|
1 |
|
new TabSet( |
|
94
|
1 |
|
$name = 'Root', |
|
95
|
1 |
|
new Tab( |
|
96
|
1 |
|
$title = 'Main', |
|
97
|
1 |
|
HeaderField::create('ContactHD', 'Contact Information'), |
|
98
|
1 |
|
TextField::create('Title', 'Name'), |
|
99
|
1 |
|
TextField::create('Phone'), |
|
100
|
1 |
|
EmailField::create('Email', 'Email'), |
|
101
|
1 |
|
TextField::create('Website') |
|
102
|
1 |
|
->setAttribute('placeholder', 'http://'), |
|
103
|
1 |
|
DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
104
|
1 |
|
->setEmptyString('-- select --'), |
|
105
|
1 |
|
CheckboxField::create('ShowInLocator', 'Show in results') |
|
106
|
1 |
|
->setDescription('Location will be included in results list'), |
|
107
|
1 |
|
CheckboxField::create('Featured') |
|
108
|
1 |
|
->setDescription('Location will show at/near the top of the results list') |
|
109
|
1 |
|
) |
|
110
|
1 |
|
) |
|
111
|
|
|
); |
|
112
|
|
|
|
|
113
|
1 |
|
// allow to be extended via DataExtension |
|
114
|
|
|
$this->extend('updateCMSFields', $fields); |
|
115
|
|
|
|
|
116
|
1 |
|
// override Suburb field name |
|
117
|
|
|
$fields->dataFieldByName('Suburb')->setTitle('City'); |
|
118
|
1 |
|
|
|
119
|
|
|
return $fields; |
|
120
|
|
|
} |
|
121
|
5 |
|
|
|
122
|
|
|
public function validate() |
|
123
|
5 |
|
{ |
|
124
|
|
|
$result = parent::validate(); |
|
125
|
5 |
|
|
|
126
|
|
|
return $result; |
|
127
|
|
|
} |
|
128
|
|
|
|
|
129
|
|
|
public function EmailAddress() |
|
|
|
|
|
|
130
|
|
|
{ |
|
131
|
|
|
Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
132
|
|
|
if ($this->Email) { |
|
|
|
|
|
|
133
|
|
|
return $this->Email; |
|
|
|
|
|
|
134
|
|
|
} elseif ($this->EmailAddress) { |
|
|
|
|
|
|
135
|
|
|
return $this->EmailAddress; |
|
|
|
|
|
|
136
|
|
|
} |
|
137
|
|
|
|
|
138
|
|
|
return false; |
|
139
|
|
|
} |
|
140
|
|
|
|
|
141
|
|
|
public function getCustomSearchContext() |
|
142
|
|
|
{ |
|
143
|
|
|
$fields = $this->scaffoldSearchFields(array( |
|
144
|
|
|
'restrictFields' => array('Address', 'Category.ID'), |
|
145
|
1 |
|
)); |
|
146
|
|
|
|
|
147
|
1 |
|
$filters = array( |
|
148
|
|
|
'Address' => new PartialMatchFilter('Address'), |
|
149
|
|
|
'Suburb' => new PartialMatchFilter('Suburb'), |
|
150
|
1 |
|
'State' => new PartialMatchFilter('State'), |
|
151
|
|
|
'Postcode' => new PartialMatchFilter('Postcode'), |
|
152
|
1 |
|
'Country' => new PartialMatchFilter('Postcode'), |
|
153
|
|
|
'CategoryID' => new ExactMatchFilter('CategoryID'), |
|
154
|
|
|
); |
|
155
|
1 |
|
|
|
156
|
|
|
return new SearchContext( |
|
157
|
1 |
|
$this->class, |
|
158
|
|
|
$fields, |
|
159
|
|
|
$filters |
|
160
|
1 |
|
); |
|
161
|
|
|
} |
|
162
|
1 |
|
|
|
163
|
|
|
/** |
|
164
|
|
|
* @param Member $member |
|
|
|
|
|
|
165
|
|
|
* |
|
166
|
|
|
* @return bool |
|
167
|
|
|
*/ |
|
168
|
|
|
public function canView($member = false) |
|
169
|
|
|
{ |
|
170
|
|
|
return true; |
|
171
|
|
|
} |
|
172
|
|
|
|
|
173
|
|
|
public function canEdit($member = false) |
|
174
|
20 |
|
{ |
|
175
|
|
|
return Permission::check('Location_EDIT'); |
|
176
|
20 |
|
} |
|
177
|
20 |
|
|
|
178
|
|
|
public function canDelete($member = false) |
|
179
|
1 |
|
{ |
|
180
|
|
|
return Permission::check('Location_DELETE'); |
|
181
|
|
|
} |
|
182
|
|
|
|
|
183
|
|
|
public function canCreate($member = false) |
|
184
|
|
|
{ |
|
185
|
|
|
return Permission::check('Location_CREATE'); |
|
186
|
|
|
} |
|
187
|
|
|
|
|
188
|
|
|
public function providePermissions() |
|
189
|
|
|
{ |
|
190
|
|
|
return array( |
|
191
|
|
|
'Location_EDIT' => 'Edit a Location', |
|
192
|
|
|
'Location_DELETE' => 'Delete a Location', |
|
193
|
|
|
'Location_CREATE' => 'Create a Location', |
|
194
|
|
|
); |
|
195
|
|
|
} |
|
196
|
|
|
|
|
197
|
|
|
public function onBeforeWrite() |
|
198
|
|
|
{ |
|
199
|
|
|
parent::onBeforeWrite(); |
|
200
|
|
|
} |
|
201
|
|
|
} |
|
202
|
|
|
|
This check marks private properties in classes that are never used. Those properties can be removed.