Passed
Pull Request — master (#223)
by Jason
10:01
created
src/admin/LocationsAdmin.php 1 patch
Indentation   +69 added lines, -69 removed lines patch added patch discarded remove patch
@@ -17,83 +17,83 @@
 block discarded – undo
17 17
 class LocationsAdmin extends CatalogPageAdmin
18 18
 {
19 19
 
20
-    /**
21
-     * @var array
22
-     */
23
-    private static $managed_models = [
24
-        LocationPage::class,
25
-        LocationCategory::class,
26
-    ];
20
+	/**
21
+	 * @var array
22
+	 */
23
+	private static $managed_models = [
24
+		LocationPage::class,
25
+		LocationCategory::class,
26
+	];
27 27
 
28
-    /**
29
-     * @var array
30
-     */
31
-    private static $model_importers = [
32
-        LocationCategory::class => CsvBulkLoader::class,
33
-    ];
28
+	/**
29
+	 * @var array
30
+	 */
31
+	private static $model_importers = [
32
+		LocationCategory::class => CsvBulkLoader::class,
33
+	];
34 34
 
35
-    /**
36
-     * @var string
37
-     */
38
-    private static $menu_title = 'Locations';
35
+	/**
36
+	 * @var string
37
+	 */
38
+	private static $menu_title = 'Locations';
39 39
 
40
-    /**
41
-     * @var string
42
-     */
43
-    private static $url_segment = 'locations';
40
+	/**
41
+	 * @var string
42
+	 */
43
+	private static $url_segment = 'locations';
44 44
 
45
-    /**
46
-     * @return array
47
-     */
48
-    public function getExportFields()
49
-    {
50
-        if ($this->modelClass == LocationPage::class) {
51
-            $fields = [
52
-                'Title' => 'Name',
53
-                'Address' => 'Address',
54
-                'Address2' => 'Address2',
55
-                'City' => 'City',
56
-                'State' => 'State',
57
-                'PostalCode' => 'PostalCode',
58
-                'CountryCode' => 'Country',
59
-                'Phone' => 'Phone',
60
-                'Fax' => 'Fax',
61
-                'Email' => 'Email',
62
-                'Website' => 'Website',
63
-                'Featured' => 'Featured',
64
-                'CategoryList' => 'Categories',
65
-                'Lat' => 'Lat',
66
-                'Lng' => 'Lng',
67
-                'Import_ID' => 'Import_ID',
68
-            ];
69
-        }
45
+	/**
46
+	 * @return array
47
+	 */
48
+	public function getExportFields()
49
+	{
50
+		if ($this->modelClass == LocationPage::class) {
51
+			$fields = [
52
+				'Title' => 'Name',
53
+				'Address' => 'Address',
54
+				'Address2' => 'Address2',
55
+				'City' => 'City',
56
+				'State' => 'State',
57
+				'PostalCode' => 'PostalCode',
58
+				'CountryCode' => 'Country',
59
+				'Phone' => 'Phone',
60
+				'Fax' => 'Fax',
61
+				'Email' => 'Email',
62
+				'Website' => 'Website',
63
+				'Featured' => 'Featured',
64
+				'CategoryList' => 'Categories',
65
+				'Lat' => 'Lat',
66
+				'Lng' => 'Lng',
67
+				'Import_ID' => 'Import_ID',
68
+			];
69
+		}
70 70
 
71
-        if (!isset($fields)) {
72
-            $fields = parent::getExportFields();
73
-        }
71
+		if (!isset($fields)) {
72
+			$fields = parent::getExportFields();
73
+		}
74 74
 
75
-        $this->extend('updateGetExportFields', $fields);
75
+		$this->extend('updateGetExportFields', $fields);
76 76
 
77
-        return $fields;
78
-    }
77
+		return $fields;
78
+	}
79 79
 
80
-    /**
81
-     * @param null $id
82
-     * @param null $fields
83
-     * @return $this|Form
84
-     */
85
-    public function getEditForm($id = null, $fields = null)
86
-    {
87
-        $form = parent::getEditForm($id, $fields);
80
+	/**
81
+	 * @param null $id
82
+	 * @param null $fields
83
+	 * @return $this|Form
84
+	 */
85
+	public function getEditForm($id = null, $fields = null)
86
+	{
87
+		$form = parent::getEditForm($id, $fields);
88 88
 
89
-        if ($this->modelClass == LocationPage::class) {
90
-            /** @var GridField $gridField */
91
-            if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) {
92
-                $gridField->getConfig()
93
-                    ->removeComponentsByType('GridFieldDeleteAction');
94
-            }
95
-        }
89
+		if ($this->modelClass == LocationPage::class) {
90
+			/** @var GridField $gridField */
91
+			if ($gridField = $form->Fields()->fieldByName($this->sanitiseClassName($this->modelClass))) {
92
+				$gridField->getConfig()
93
+					->removeComponentsByType('GridFieldDeleteAction');
94
+			}
95
+		}
96 96
 
97
-        return $form;
98
-    }
97
+		return $form;
98
+	}
99 99
 }
Please login to merge, or discard this patch.
src/Page/Locator.php 2 patches
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -28,269 +28,269 @@
 block discarded – undo
28 28
  */
29 29
 class Locator extends \Page
30 30
 {
31
-    /**
32
-     * @var string
33
-     */
34
-    private static $singular_name = 'Locator';
35
-
36
-    /**
37
-     * @var string
38
-     */
39
-    private static $plural_name = 'Locators';
40
-
41
-    /**
42
-     * @var string
43
-     */
44
-    private static $description = 'Display locations on a map';
45
-
46
-    /**
47
-     * @var array
48
-     */
49
-    private static $db = [
50
-        'Unit' => 'Enum("m,km","m")',
51
-    ];
52
-
53
-    /**
54
-     * @var array
55
-     */
56
-    private static $many_many = [
57
-        'Categories' => LocationCategory::class,
58
-    ];
59
-
60
-    /**
61
-     * @var string
62
-     */
63
-    private static $table_name = 'Locator';
64
-
65
-    /**
66
-     * @var string
67
-     */
68
-    private static $location_class = LocationPage::class;
69
-
70
-    /**
71
-     * @var string[]
72
-     */
73
-    private static $extensions = [
74
-        Lumberjack::class,
75
-    ];
76
-
77
-    /**
78
-     * @var string[]
79
-     */
80
-    private static $allowed_children = [
81
-        LocationPage::class,
82
-    ];
83
-
84
-    /**
85
-     * @return FieldList
86
-     */
87
-    public function getCMSFields()
88
-    {
89
-        $this->beforeUpdateCMSFields(function ($fields) {
90
-            // Settings
91
-            $fields->addFieldsToTab('Root.Settings', [
92
-                HeaderField::create('DisplayOptions', 'Display Options', 3),
93
-                OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']),
94
-            ]);
95
-
96
-            // Filter categories
97
-            $config = GridFieldConfig_RelationEditor::create();
98
-            $config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
99
-            $config->addComponent(new GridFieldAddExistingSearchButton());
100
-            $categories = $this->Categories();
101
-            $categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
102
-                ->setDescription('only show locations from the selected category');
103
-
104
-            // Filter
105
-            $fields->addFieldsToTab('Root.Filter', [
106
-                HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
107
-                $categoriesField,
108
-            ]);
109
-        });
110
-
111
-        return parent::getCMSFields();
112
-    }
113
-
114
-    /**
115
-     * @param array $filter
116
-     * @param array $filterAny
117
-     * @param array $exclude
118
-     * @param null|callable $callback
119
-     *
120
-     * @return DataList|ArrayList
121
-     */
122
-    public static function get_locations($filter = [], $filterAny = [], $exclude = [], $callback = null)
123
-    {
124
-        $locationClass = Config::inst()->get(static::class, 'location_class');
125
-        $locations = $locationClass::get()->filter($filter)->exclude($exclude);
126
-
127
-        if (!empty($filterAny)) {
128
-            $locations = $locations->filterAny($filterAny);
129
-        }
130
-        if (!empty($exclude)) {
131
-            $locations = $locations->exclude($exclude);
132
-        }
133
-
134
-        if ($callback !== null && is_callable($callback)) {
135
-            $locations->filterByCallback($callback);
136
-        }
137
-
138
-        return $locations;
139
-    }
140
-
141
-    /**
142
-     * @return DataList
143
-     */
144
-    public static function get_all_categories()
145
-    {
146
-        return LocationCategory::get();
147
-    }
148
-
149
-    /**
150
-     * @return bool
151
-     */
152
-    public function getPageCategories()
153
-    {
154
-        return self::locator_categories_by_locator($this->ID);
155
-    }
156
-
157
-    /**
158
-     * @param int $id
159
-     *
160
-     * @return bool|
161
-     */
162
-    public static function locator_categories_by_locator($id = 0)
163
-    {
164
-        if ($id == 0) {
165
-            return false;
166
-        }
167
-
168
-        /** @var Locator $locator */
169
-        if ($locator = static::get()->byID($id)) {
170
-            return $locator->getUsedCategories();
171
-        }
172
-
173
-        return false;
174
-    }
175
-
176
-    /**
177
-     * Gets the list of radii
178
-     *
179
-     * @return ArrayList
180
-     */
181
-    public function getRadii()
182
-    {
183
-        $radii = [
184
-            '0' => '25',
185
-            '1' => '50',
186
-            '2' => '75',
187
-            '3' => '100',
188
-        ];
189
-        $config_radii = $this->config()->get('radii');
190
-        if ($config_radii) {
191
-            $radii = $config_radii;
192
-        }
193
-
194
-        return $radii;
195
-    }
196
-
197
-    public function getRadiiArrayList()
198
-    {
199
-        $list = [];
200
-
201
-        foreach ($this->getRadii() as $radius) {
202
-            $list[] = new ArrayData([
203
-                'Radius' => $radius,
204
-            ]);
205
-        }
206
-
207
-        return new ArrayList($list);
208
-    }
209
-
210
-    /**
211
-     * Gets the limit of locations
212
-     * @return mixed
213
-     */
214
-    public function getLimit()
215
-    {
216
-        return $this->config()->get('limit');
217
-    }
218
-
219
-    /**
220
-     * Gets if the radius drop down should be shown
221
-     * @return mixed
222
-     */
223
-    public function getShowRadius()
224
-    {
225
-        return $this->config()->get('show_radius');
226
-    }
227
-
228
-    /**
229
-     * @return mixed
230
-     */
231
-    public function getUsedCategories()
232
-    {
233
-        return $this->Categories()->filter([
234
-            'LocationSet.ID:GreaterThan' => 0,
235
-        ]);
236
-    }
237
-
238
-    /**
239
-     * Gets the path of the info window template
240
-     *
241
-     * @return string
242
-     */
243
-    public function getInfoWindowTemplate()
244
-    {
245
-        return ModuleResourceLoader::singleton()->resolveURL(
246
-            Config::inst()->get(
247
-                static::class,
248
-                'infoWindowTemplate'
249
-            )
250
-        );
251
-    }
252
-
253
-    /**
254
-     * Gets the path of the list template
255
-     *
256
-     * @return string
257
-     */
258
-    public function getListTemplate()
259
-    {
260
-        return ModuleResourceLoader::singleton()->resolveURL(
261
-            Config::inst()->get(
262
-                static::class,
263
-                'listTemplate'
264
-            )
265
-        );
266
-    }
267
-
268
-    /**
269
-     * @return null|string
270
-     */
271
-    public function getMapStyle()
272
-    {
273
-        return AddressDataExtension::getMapStyleJSON();
274
-    }
275
-
276
-    public function getMapStyleJSONPath()
277
-    {
278
-        return AddressDataExtension::getMapStyleJSONPath();
279
-    }
280
-
281
-    /**
282
-     * @return null|string
283
-     */
284
-    public function getMarkerIcon()
285
-    {
286
-        return AddressDataExtension::getIconImage();
287
-    }
288
-
289
-    /**
290
-     * @return string
291
-     */
292
-    public function getLumberjackTitle()
293
-    {
294
-        return _t(__CLASS__ . '.LumberjackTitle', 'Locations');
295
-    }
31
+	/**
32
+	 * @var string
33
+	 */
34
+	private static $singular_name = 'Locator';
35
+
36
+	/**
37
+	 * @var string
38
+	 */
39
+	private static $plural_name = 'Locators';
40
+
41
+	/**
42
+	 * @var string
43
+	 */
44
+	private static $description = 'Display locations on a map';
45
+
46
+	/**
47
+	 * @var array
48
+	 */
49
+	private static $db = [
50
+		'Unit' => 'Enum("m,km","m")',
51
+	];
52
+
53
+	/**
54
+	 * @var array
55
+	 */
56
+	private static $many_many = [
57
+		'Categories' => LocationCategory::class,
58
+	];
59
+
60
+	/**
61
+	 * @var string
62
+	 */
63
+	private static $table_name = 'Locator';
64
+
65
+	/**
66
+	 * @var string
67
+	 */
68
+	private static $location_class = LocationPage::class;
69
+
70
+	/**
71
+	 * @var string[]
72
+	 */
73
+	private static $extensions = [
74
+		Lumberjack::class,
75
+	];
76
+
77
+	/**
78
+	 * @var string[]
79
+	 */
80
+	private static $allowed_children = [
81
+		LocationPage::class,
82
+	];
83
+
84
+	/**
85
+	 * @return FieldList
86
+	 */
87
+	public function getCMSFields()
88
+	{
89
+		$this->beforeUpdateCMSFields(function ($fields) {
90
+			// Settings
91
+			$fields->addFieldsToTab('Root.Settings', [
92
+				HeaderField::create('DisplayOptions', 'Display Options', 3),
93
+				OptionsetField::create('Unit', 'Unit of measure', ['m' => 'Miles', 'km' => 'Kilometers']),
94
+			]);
95
+
96
+			// Filter categories
97
+			$config = GridFieldConfig_RelationEditor::create();
98
+			$config->removeComponentsByType(GridFieldAddExistingAutocompleter::class);
99
+			$config->addComponent(new GridFieldAddExistingSearchButton());
100
+			$categories = $this->Categories();
101
+			$categoriesField = GridField::create('Categories', 'Categories', $categories, $config)
102
+				->setDescription('only show locations from the selected category');
103
+
104
+			// Filter
105
+			$fields->addFieldsToTab('Root.Filter', [
106
+				HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3),
107
+				$categoriesField,
108
+			]);
109
+		});
110
+
111
+		return parent::getCMSFields();
112
+	}
113
+
114
+	/**
115
+	 * @param array $filter
116
+	 * @param array $filterAny
117
+	 * @param array $exclude
118
+	 * @param null|callable $callback
119
+	 *
120
+	 * @return DataList|ArrayList
121
+	 */
122
+	public static function get_locations($filter = [], $filterAny = [], $exclude = [], $callback = null)
123
+	{
124
+		$locationClass = Config::inst()->get(static::class, 'location_class');
125
+		$locations = $locationClass::get()->filter($filter)->exclude($exclude);
126
+
127
+		if (!empty($filterAny)) {
128
+			$locations = $locations->filterAny($filterAny);
129
+		}
130
+		if (!empty($exclude)) {
131
+			$locations = $locations->exclude($exclude);
132
+		}
133
+
134
+		if ($callback !== null && is_callable($callback)) {
135
+			$locations->filterByCallback($callback);
136
+		}
137
+
138
+		return $locations;
139
+	}
140
+
141
+	/**
142
+	 * @return DataList
143
+	 */
144
+	public static function get_all_categories()
145
+	{
146
+		return LocationCategory::get();
147
+	}
148
+
149
+	/**
150
+	 * @return bool
151
+	 */
152
+	public function getPageCategories()
153
+	{
154
+		return self::locator_categories_by_locator($this->ID);
155
+	}
156
+
157
+	/**
158
+	 * @param int $id
159
+	 *
160
+	 * @return bool|
161
+	 */
162
+	public static function locator_categories_by_locator($id = 0)
163
+	{
164
+		if ($id == 0) {
165
+			return false;
166
+		}
167
+
168
+		/** @var Locator $locator */
169
+		if ($locator = static::get()->byID($id)) {
170
+			return $locator->getUsedCategories();
171
+		}
172
+
173
+		return false;
174
+	}
175
+
176
+	/**
177
+	 * Gets the list of radii
178
+	 *
179
+	 * @return ArrayList
180
+	 */
181
+	public function getRadii()
182
+	{
183
+		$radii = [
184
+			'0' => '25',
185
+			'1' => '50',
186
+			'2' => '75',
187
+			'3' => '100',
188
+		];
189
+		$config_radii = $this->config()->get('radii');
190
+		if ($config_radii) {
191
+			$radii = $config_radii;
192
+		}
193
+
194
+		return $radii;
195
+	}
196
+
197
+	public function getRadiiArrayList()
198
+	{
199
+		$list = [];
200
+
201
+		foreach ($this->getRadii() as $radius) {
202
+			$list[] = new ArrayData([
203
+				'Radius' => $radius,
204
+			]);
205
+		}
206
+
207
+		return new ArrayList($list);
208
+	}
209
+
210
+	/**
211
+	 * Gets the limit of locations
212
+	 * @return mixed
213
+	 */
214
+	public function getLimit()
215
+	{
216
+		return $this->config()->get('limit');
217
+	}
218
+
219
+	/**
220
+	 * Gets if the radius drop down should be shown
221
+	 * @return mixed
222
+	 */
223
+	public function getShowRadius()
224
+	{
225
+		return $this->config()->get('show_radius');
226
+	}
227
+
228
+	/**
229
+	 * @return mixed
230
+	 */
231
+	public function getUsedCategories()
232
+	{
233
+		return $this->Categories()->filter([
234
+			'LocationSet.ID:GreaterThan' => 0,
235
+		]);
236
+	}
237
+
238
+	/**
239
+	 * Gets the path of the info window template
240
+	 *
241
+	 * @return string
242
+	 */
243
+	public function getInfoWindowTemplate()
244
+	{
245
+		return ModuleResourceLoader::singleton()->resolveURL(
246
+			Config::inst()->get(
247
+				static::class,
248
+				'infoWindowTemplate'
249
+			)
250
+		);
251
+	}
252
+
253
+	/**
254
+	 * Gets the path of the list template
255
+	 *
256
+	 * @return string
257
+	 */
258
+	public function getListTemplate()
259
+	{
260
+		return ModuleResourceLoader::singleton()->resolveURL(
261
+			Config::inst()->get(
262
+				static::class,
263
+				'listTemplate'
264
+			)
265
+		);
266
+	}
267
+
268
+	/**
269
+	 * @return null|string
270
+	 */
271
+	public function getMapStyle()
272
+	{
273
+		return AddressDataExtension::getMapStyleJSON();
274
+	}
275
+
276
+	public function getMapStyleJSONPath()
277
+	{
278
+		return AddressDataExtension::getMapStyleJSONPath();
279
+	}
280
+
281
+	/**
282
+	 * @return null|string
283
+	 */
284
+	public function getMarkerIcon()
285
+	{
286
+		return AddressDataExtension::getIconImage();
287
+	}
288
+
289
+	/**
290
+	 * @return string
291
+	 */
292
+	public function getLumberjackTitle()
293
+	{
294
+		return _t(__CLASS__ . '.LumberjackTitle', 'Locations');
295
+	}
296 296
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -86,7 +86,7 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function getCMSFields()
88 88
     {
89
-        $this->beforeUpdateCMSFields(function ($fields) {
89
+        $this->beforeUpdateCMSFields(function($fields) {
90 90
             // Settings
91 91
             $fields->addFieldsToTab('Root.Settings', [
92 92
                 HeaderField::create('DisplayOptions', 'Display Options', 3),
@@ -291,6 +291,6 @@  discard block
 block discarded – undo
291 291
      */
292 292
     public function getLumberjackTitle()
293 293
     {
294
-        return _t(__CLASS__ . '.LumberjackTitle', 'Locations');
294
+        return _t(__CLASS__.'.LumberjackTitle', 'Locations');
295 295
     }
296 296
 }
Please login to merge, or discard this patch.
src/Page/LocationPage.php 1 patch
Indentation   +265 added lines, -265 removed lines patch added patch discarded remove patch
@@ -31,269 +31,269 @@
 block discarded – undo
31 31
  */
32 32
 class LocationPage extends \Page implements PermissionProvider
33 33
 {
34
-    /**
35
-     * @var string
36
-     */
37
-    private static $singular_name = 'Location';
38
-
39
-    /**
40
-     * @var string
41
-     */
42
-    private static $plural_name = 'Locations';
43
-
44
-    /**
45
-     * @var array
46
-     */
47
-    private static $db = [
48
-        'Featured' => 'Boolean',
49
-        'Website' => 'Varchar(255)',
50
-        'Phone' => 'Varchar(40)',
51
-        'Email' => 'Varchar(255)',
52
-        'Fax' => 'Varchar(45)',
53
-        'Import_ID' => 'Int',
54
-        'LegacyObjectID' => 'Int',
55
-    ];
56
-
57
-    private static $many_many = [
58
-        'Categories' => LocationCategory::class,
59
-    ];
60
-
61
-    /**
62
-     * @var string
63
-     */
64
-    private static $table_name = 'LocationPage';
65
-
66
-    /**
67
-     * @var array
68
-     */
69
-    private static $casting = [
70
-        'distance' => 'Decimal(9,3)',
71
-    ];
72
-
73
-    /**
74
-     * @var string
75
-     */
76
-    private static $default_sort = 'Title';
77
-
78
-    /**
79
-     * api access via Restful Server module
80
-     *
81
-     * @var bool
82
-     */
83
-    private static $api_access = true;
84
-
85
-    /**
86
-     * search fields for Model Admin
87
-     *
88
-     * @var array
89
-     */
90
-    private static $searchable_fields = [
91
-        'Title',
92
-        'Address',
93
-        'City',
94
-        'State',
95
-        'PostalCode',
96
-        'Country',
97
-        'Website',
98
-        'Phone',
99
-        'Email',
100
-        'Featured',
101
-    ];
102
-
103
-    /**
104
-     * columns for grid field
105
-     *
106
-     * @var array
107
-     */
108
-    private static $summary_fields = [
109
-        'Title',
110
-        'Address',
111
-        'Address2',
112
-        'City',
113
-        'State',
114
-        'PostalCode',
115
-        'CountryCode',
116
-        'Phone' => 'Phone',
117
-        'Fax' => 'Fax',
118
-        'Email' => 'Email',
119
-        'Website' => 'Website',
120
-        'Featured',
121
-        'CategoryList',
122
-        'Lat',
123
-        'Lng',
124
-        'Import_ID',
125
-    ];
126
-
127
-    /**
128
-     * @var bool
129
-     */
130
-    private static $show_in_sitetree = false;
131
-
132
-    /**
133
-     * @var array 
134
-     */
135
-    private static $allowed_children = [];
136
-
137
-    /**
138
-     * Coords status for $summary_fields
139
-     *
140
-     * @return string
141
-     */
142
-    public function getCoords()
143
-    {
144
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
145
-    }
146
-
147
-    /**
148
-     * @return string
149
-     */
150
-    public function getCategoryList()
151
-    {
152
-        if ($this->Categories()->count()) {
153
-            return implode(', ', $this->Categories()->column('Name'));
154
-        }
155
-
156
-        return '';
157
-    }
158
-
159
-    /**
160
-     * @return bool|string
161
-     */
162
-    public function getCountryCode()
163
-    {
164
-        if ($this->Country) {
165
-            return strtoupper($this->Country);
166
-        }
167
-
168
-        return false;
169
-    }
170
-
171
-    /**
172
-     * custom labels for fields
173
-     *
174
-     * @param bool $includerelations
175
-     * @return array|string
176
-     */
177
-    public function fieldLabels($includerelations = true)
178
-    {
179
-        $labels = parent::fieldLabels($includerelations);
180
-
181
-        $labels['Title'] = 'Name';
182
-        $labels['Address2'] = 'Address 2';
183
-        $labels['PostalCode'] = 'Postal Code';
184
-        $labels['Categories.Name'] = 'Categories';
185
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
186
-
187
-        return $labels;
188
-    }
189
-
190
-    /**
191
-     * @return FieldList
192
-     */
193
-    public function getCMSFields()
194
-    {
195
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
196
-            $fields->addFieldsToTab(
197
-                'Root.Main',
198
-                [
199
-                    CheckboxField::create('Featured')
200
-                        ->setTitle('Featured'),
201
-                    TextField::create('Website')
202
-                        ->setTitle('Website')
203
-                        ->setDescription('Include the http/https (example: https://google.com)'),
204
-                    TextField::create('Phone')
205
-                        ->setTitle('Phone'),
206
-                    EmailField::create('Email')
207
-                        ->setTitle('Email'),
208
-                    TextField::create('Fax')
209
-                        ->setTitle('Fax'),
210
-                ],
211
-                'Content'
212
-            );
213
-
214
-            if ($this->exists()) {
215
-                $fields->addFieldToTab(
216
-                    'Root.Categories',
217
-                    GridField::create(
218
-                        'Categories',
219
-                        'Categories',
220
-                        $this->Categories(),
221
-                        $catConfig = GridFieldConfig_RelationEditor::create()
222
-                    )
223
-                );
224
-
225
-                $catConfig->removeComponentsByType([
226
-                    GridFieldAddExistingAutocompleter::class,
227
-                ])->addComponents([
228
-                    new GridFieldAddExistingSearchButton()
229
-                ]);
230
-            }
231
-        });
232
-
233
-        return parent::getCMSFields();
234
-    }
235
-
236
-    /**
237
-     * @param null $member
238
-     * @param array $context
239
-     * @return bool
240
-     */
241
-    public function canView($member = null, $context = [])
242
-    {
243
-        return true;
244
-    }
245
-
246
-    /**
247
-     * @param null $member
248
-     * @param array $context
249
-     * @return bool|int
250
-     */
251
-    public function canEdit($member = null, $context = [])
252
-    {
253
-        return Permission::check('Location_EDIT', 'any', $member);
254
-    }
255
-
256
-    /**
257
-     * @param null $member
258
-     * @param array $context
259
-     * @return bool|int
260
-     */
261
-    public function canDelete($member = null, $context = [])
262
-    {
263
-        return Permission::check('Location_DELETE', 'any', $member);
264
-    }
265
-
266
-    /**
267
-     * @param null $member
268
-     * @param array $context
269
-     * @return bool|int
270
-     */
271
-    public function canCreate($member = null, $context = [])
272
-    {
273
-        return Permission::check('Location_CREATE', 'any', $member);
274
-    }
275
-
276
-    /**
277
-     * @return array
278
-     */
279
-    public function providePermissions()
280
-    {
281
-        return [
282
-            'Location_EDIT' => 'Edit a Location',
283
-            'Location_DELETE' => 'Delete a Location',
284
-            'Location_CREATE' => 'Create a Location',
285
-        ];
286
-    }
287
-
288
-    /**
289
-     * @return string
290
-     */
291
-    public function getWebsiteURL()
292
-    {
293
-        $url = $this->Website;
294
-
295
-        $this->extend('updateWebsiteURL', $url);
296
-
297
-        return $url;
298
-    }
34
+	/**
35
+	 * @var string
36
+	 */
37
+	private static $singular_name = 'Location';
38
+
39
+	/**
40
+	 * @var string
41
+	 */
42
+	private static $plural_name = 'Locations';
43
+
44
+	/**
45
+	 * @var array
46
+	 */
47
+	private static $db = [
48
+		'Featured' => 'Boolean',
49
+		'Website' => 'Varchar(255)',
50
+		'Phone' => 'Varchar(40)',
51
+		'Email' => 'Varchar(255)',
52
+		'Fax' => 'Varchar(45)',
53
+		'Import_ID' => 'Int',
54
+		'LegacyObjectID' => 'Int',
55
+	];
56
+
57
+	private static $many_many = [
58
+		'Categories' => LocationCategory::class,
59
+	];
60
+
61
+	/**
62
+	 * @var string
63
+	 */
64
+	private static $table_name = 'LocationPage';
65
+
66
+	/**
67
+	 * @var array
68
+	 */
69
+	private static $casting = [
70
+		'distance' => 'Decimal(9,3)',
71
+	];
72
+
73
+	/**
74
+	 * @var string
75
+	 */
76
+	private static $default_sort = 'Title';
77
+
78
+	/**
79
+	 * api access via Restful Server module
80
+	 *
81
+	 * @var bool
82
+	 */
83
+	private static $api_access = true;
84
+
85
+	/**
86
+	 * search fields for Model Admin
87
+	 *
88
+	 * @var array
89
+	 */
90
+	private static $searchable_fields = [
91
+		'Title',
92
+		'Address',
93
+		'City',
94
+		'State',
95
+		'PostalCode',
96
+		'Country',
97
+		'Website',
98
+		'Phone',
99
+		'Email',
100
+		'Featured',
101
+	];
102
+
103
+	/**
104
+	 * columns for grid field
105
+	 *
106
+	 * @var array
107
+	 */
108
+	private static $summary_fields = [
109
+		'Title',
110
+		'Address',
111
+		'Address2',
112
+		'City',
113
+		'State',
114
+		'PostalCode',
115
+		'CountryCode',
116
+		'Phone' => 'Phone',
117
+		'Fax' => 'Fax',
118
+		'Email' => 'Email',
119
+		'Website' => 'Website',
120
+		'Featured',
121
+		'CategoryList',
122
+		'Lat',
123
+		'Lng',
124
+		'Import_ID',
125
+	];
126
+
127
+	/**
128
+	 * @var bool
129
+	 */
130
+	private static $show_in_sitetree = false;
131
+
132
+	/**
133
+	 * @var array 
134
+	 */
135
+	private static $allowed_children = [];
136
+
137
+	/**
138
+	 * Coords status for $summary_fields
139
+	 *
140
+	 * @return string
141
+	 */
142
+	public function getCoords()
143
+	{
144
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
145
+	}
146
+
147
+	/**
148
+	 * @return string
149
+	 */
150
+	public function getCategoryList()
151
+	{
152
+		if ($this->Categories()->count()) {
153
+			return implode(', ', $this->Categories()->column('Name'));
154
+		}
155
+
156
+		return '';
157
+	}
158
+
159
+	/**
160
+	 * @return bool|string
161
+	 */
162
+	public function getCountryCode()
163
+	{
164
+		if ($this->Country) {
165
+			return strtoupper($this->Country);
166
+		}
167
+
168
+		return false;
169
+	}
170
+
171
+	/**
172
+	 * custom labels for fields
173
+	 *
174
+	 * @param bool $includerelations
175
+	 * @return array|string
176
+	 */
177
+	public function fieldLabels($includerelations = true)
178
+	{
179
+		$labels = parent::fieldLabels($includerelations);
180
+
181
+		$labels['Title'] = 'Name';
182
+		$labels['Address2'] = 'Address 2';
183
+		$labels['PostalCode'] = 'Postal Code';
184
+		$labels['Categories.Name'] = 'Categories';
185
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
186
+
187
+		return $labels;
188
+	}
189
+
190
+	/**
191
+	 * @return FieldList
192
+	 */
193
+	public function getCMSFields()
194
+	{
195
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
196
+			$fields->addFieldsToTab(
197
+				'Root.Main',
198
+				[
199
+					CheckboxField::create('Featured')
200
+						->setTitle('Featured'),
201
+					TextField::create('Website')
202
+						->setTitle('Website')
203
+						->setDescription('Include the http/https (example: https://google.com)'),
204
+					TextField::create('Phone')
205
+						->setTitle('Phone'),
206
+					EmailField::create('Email')
207
+						->setTitle('Email'),
208
+					TextField::create('Fax')
209
+						->setTitle('Fax'),
210
+				],
211
+				'Content'
212
+			);
213
+
214
+			if ($this->exists()) {
215
+				$fields->addFieldToTab(
216
+					'Root.Categories',
217
+					GridField::create(
218
+						'Categories',
219
+						'Categories',
220
+						$this->Categories(),
221
+						$catConfig = GridFieldConfig_RelationEditor::create()
222
+					)
223
+				);
224
+
225
+				$catConfig->removeComponentsByType([
226
+					GridFieldAddExistingAutocompleter::class,
227
+				])->addComponents([
228
+					new GridFieldAddExistingSearchButton()
229
+				]);
230
+			}
231
+		});
232
+
233
+		return parent::getCMSFields();
234
+	}
235
+
236
+	/**
237
+	 * @param null $member
238
+	 * @param array $context
239
+	 * @return bool
240
+	 */
241
+	public function canView($member = null, $context = [])
242
+	{
243
+		return true;
244
+	}
245
+
246
+	/**
247
+	 * @param null $member
248
+	 * @param array $context
249
+	 * @return bool|int
250
+	 */
251
+	public function canEdit($member = null, $context = [])
252
+	{
253
+		return Permission::check('Location_EDIT', 'any', $member);
254
+	}
255
+
256
+	/**
257
+	 * @param null $member
258
+	 * @param array $context
259
+	 * @return bool|int
260
+	 */
261
+	public function canDelete($member = null, $context = [])
262
+	{
263
+		return Permission::check('Location_DELETE', 'any', $member);
264
+	}
265
+
266
+	/**
267
+	 * @param null $member
268
+	 * @param array $context
269
+	 * @return bool|int
270
+	 */
271
+	public function canCreate($member = null, $context = [])
272
+	{
273
+		return Permission::check('Location_CREATE', 'any', $member);
274
+	}
275
+
276
+	/**
277
+	 * @return array
278
+	 */
279
+	public function providePermissions()
280
+	{
281
+		return [
282
+			'Location_EDIT' => 'Edit a Location',
283
+			'Location_DELETE' => 'Delete a Location',
284
+			'Location_CREATE' => 'Create a Location',
285
+		];
286
+	}
287
+
288
+	/**
289
+	 * @return string
290
+	 */
291
+	public function getWebsiteURL()
292
+	{
293
+		$url = $this->Website;
294
+
295
+		$this->extend('updateWebsiteURL', $url);
296
+
297
+		return $url;
298
+	}
299 299
 }
Please login to merge, or discard this patch.