Completed
Push — ci/githubActions ( f5773d...1bb421 )
by Jason
13s
created
src/Tasks/EmailAddressTask.php 2 patches
Indentation   +31 added lines, -31 removed lines patch added patch discarded remove patch
@@ -13,35 +13,35 @@
 block discarded – undo
13 13
  */
14 14
 class EmailAddressTask extends BuildTask
15 15
 {
16
-    /**
17
-     * @var string
18
-     */
19
-    protected $title = 'Email Address Task'; // title of the script
20
-
21
-    /**
22
-     * @var string
23
-     */
24
-    protected $description = "Convert depreciated 'Email Address' field to new 'Email' field.";
25
-
26
-    /**
27
-     * @param HTTPRequest $request
28
-     */
29
-    public function run($request)
30
-    {
31
-        Config::modify()->set('DataObject', 'validation_enabled', false);
32
-
33
-        $ct = 0;
34
-        $updateEmail = function ($location) use (&$ct) {
35
-            if (!$location->Email && $location->EmailAddress) {
36
-                $location->Email = $location->EmailAddress;
37
-                $location->write();
38
-                ++$ct;
39
-            }
40
-        };
41
-
42
-        Location::get()->each($updateEmail);
43
-        Config::modify()->set('DataObject', 'validation_enabled', true);
44
-
45
-        echo '<p>' . $ct . ' Locations updated</p>';
46
-    }
16
+	/**
17
+	 * @var string
18
+	 */
19
+	protected $title = 'Email Address Task'; // title of the script
20
+
21
+	/**
22
+	 * @var string
23
+	 */
24
+	protected $description = "Convert depreciated 'Email Address' field to new 'Email' field.";
25
+
26
+	/**
27
+	 * @param HTTPRequest $request
28
+	 */
29
+	public function run($request)
30
+	{
31
+		Config::modify()->set('DataObject', 'validation_enabled', false);
32
+
33
+		$ct = 0;
34
+		$updateEmail = function ($location) use (&$ct) {
35
+			if (!$location->Email && $location->EmailAddress) {
36
+				$location->Email = $location->EmailAddress;
37
+				$location->write();
38
+				++$ct;
39
+			}
40
+		};
41
+
42
+		Location::get()->each($updateEmail);
43
+		Config::modify()->set('DataObject', 'validation_enabled', true);
44
+
45
+		echo '<p>' . $ct . ' Locations updated</p>';
46
+	}
47 47
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
         Config::modify()->set('DataObject', 'validation_enabled', false);
32 32
 
33 33
         $ct = 0;
34
-        $updateEmail = function ($location) use (&$ct) {
34
+        $updateEmail = function($location) use (&$ct) {
35 35
             if (!$location->Email && $location->EmailAddress) {
36 36
                 $location->Email = $location->EmailAddress;
37 37
                 $location->write();
@@ -42,6 +42,6 @@  discard block
 block discarded – undo
42 42
         Location::get()->each($updateEmail);
43 43
         Config::modify()->set('DataObject', 'validation_enabled', true);
44 44
 
45
-        echo '<p>' . $ct . ' Locations updated</p>';
45
+        echo '<p>'.$ct.' Locations updated</p>';
46 46
     }
47 47
 }
Please login to merge, or discard this patch.
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 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -199,7 +199,7 @@  discard block
 block discarded – undo
199 199
      */
200 200
     public function getCMSFields()
201 201
     {
202
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
202
+        $this->beforeUpdateCMSFields(function(FieldList $fields) {
203 203
             $fields->addFieldsToTab(
204 204
                 'Root.Main',
205 205
                 [
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
         $url = $this->Website;
304 304
 
305 305
         if ($url && !preg_match('/^(http|https):\/\//', $url)) {
306
-            $url = 'http://' . $url;
306
+            $url = 'http://'.$url;
307 307
         }
308 308
 
309 309
         $this->extend('updateWebsiteURL', $url);
Please login to merge, or discard this patch.
Indentation   +279 added lines, -279 removed lines patch added patch discarded remove patch
@@ -31,283 +31,283 @@
 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 int[]
75
-     */
76
-    private static $defaults = [
77
-        'ShowInMenus' => 0,
78
-    ];
79
-
80
-    /**
81
-     * @var string
82
-     */
83
-    private static $default_sort = 'Title';
84
-
85
-    /**
86
-     * api access via Restful Server module
87
-     *
88
-     * @var bool
89
-     */
90
-    private static $api_access = true;
91
-
92
-    /**
93
-     * search fields for Model Admin
94
-     *
95
-     * @var array
96
-     */
97
-    private static $searchable_fields = [
98
-        'Title',
99
-        'Address',
100
-        'City',
101
-        'State',
102
-        'PostalCode',
103
-        'Country',
104
-        'Website',
105
-        'Phone',
106
-        'Email',
107
-        'Featured',
108
-    ];
109
-
110
-    /**
111
-     * columns for grid field
112
-     *
113
-     * @var array
114
-     */
115
-    private static $summary_fields = [
116
-        'Title',
117
-        'Address',
118
-        'Address2',
119
-        'City',
120
-        'State',
121
-        'PostalCode',
122
-        'CountryCode',
123
-        'Phone' => 'Phone',
124
-        'Fax' => 'Fax',
125
-        'Email' => 'Email',
126
-        'Website' => 'Website',
127
-        'Featured',
128
-        'CategoryList',
129
-        'Lat',
130
-        'Lng',
131
-        'Import_ID',
132
-    ];
133
-
134
-    /**
135
-     * @var bool
136
-     */
137
-    private static $show_in_sitetree = false;
138
-
139
-    /**
140
-     * @var array
141
-     */
142
-    private static $allowed_children = [];
143
-
144
-    /**
145
-     * Coords status for $summary_fields
146
-     *
147
-     * @return string
148
-     */
149
-    public function getCoords()
150
-    {
151
-        return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
152
-    }
153
-
154
-    /**
155
-     * @return string
156
-     */
157
-    public function getCategoryList()
158
-    {
159
-        if ($this->Categories()->count()) {
160
-            return implode(', ', $this->Categories()->column('Name'));
161
-        }
162
-
163
-        return '';
164
-    }
165
-
166
-    /**
167
-     * @return bool|string
168
-     */
169
-    public function getCountryCode()
170
-    {
171
-        if ($this->Country) {
172
-            return strtoupper($this->Country);
173
-        }
174
-
175
-        return false;
176
-    }
177
-
178
-    /**
179
-     * custom labels for fields
180
-     *
181
-     * @param bool $includerelations
182
-     * @return array|string
183
-     */
184
-    public function fieldLabels($includerelations = true)
185
-    {
186
-        $labels = parent::fieldLabels($includerelations);
187
-
188
-        $labels['Title'] = 'Name';
189
-        $labels['Address2'] = 'Address 2';
190
-        $labels['PostalCode'] = 'Postal Code';
191
-        $labels['Categories.Name'] = 'Categories';
192
-        $labels['Featured.NiceAsBoolean'] = 'Featured';
193
-
194
-        return $labels;
195
-    }
196
-
197
-    /**
198
-     * @return FieldList
199
-     */
200
-    public function getCMSFields()
201
-    {
202
-        $this->beforeUpdateCMSFields(function (FieldList $fields) {
203
-            $fields->addFieldsToTab(
204
-                'Root.Main',
205
-                [
206
-                    CheckboxField::create('Featured')
207
-                        ->setTitle('Featured'),
208
-                ],
209
-                'Content'
210
-            );
211
-
212
-            if ($this->exists()) {
213
-                $fields->addFieldToTab(
214
-                    'Root.Categories',
215
-                    GridField::create(
216
-                        'Categories',
217
-                        'Categories',
218
-                        $this->Categories(),
219
-                        $catConfig = GridFieldConfig_RelationEditor::create()
220
-                    )
221
-                );
222
-
223
-                $catConfig->removeComponentsByType([
224
-                    GridFieldAddExistingAutocompleter::class,
225
-                ])->addComponents([
226
-                    new GridFieldAddExistingSearchButton()
227
-                ]);
228
-            }
229
-
230
-            $fields->addFieldsToTab('Root.Contact', [
231
-                TextField::create('Website')
232
-                    ->setTitle('Website')
233
-                    ->setDescription('Include the http/https (example: https://google.com)'),
234
-                TextField::create('Phone')
235
-                    ->setTitle('Phone'),
236
-                EmailField::create('Email')
237
-                    ->setTitle('Email'),
238
-                TextField::create('Fax')
239
-                    ->setTitle('Fax'),
240
-            ]);
241
-        });
242
-
243
-        return parent::getCMSFields();
244
-    }
245
-
246
-    /**
247
-     * @param null $member
248
-     * @param array $context
249
-     * @return bool
250
-     */
251
-    public function canView($member = null, $context = [])
252
-    {
253
-        return true;
254
-    }
255
-
256
-    /**
257
-     * @param null $member
258
-     * @param array $context
259
-     * @return bool|int
260
-     */
261
-    public function canEdit($member = null, $context = [])
262
-    {
263
-        return Permission::check('Location_EDIT', 'any', $member);
264
-    }
265
-
266
-    /**
267
-     * @param null $member
268
-     * @param array $context
269
-     * @return bool|int
270
-     */
271
-    public function canDelete($member = null, $context = [])
272
-    {
273
-        return Permission::check('Location_DELETE', 'any', $member);
274
-    }
275
-
276
-    /**
277
-     * @param null $member
278
-     * @param array $context
279
-     * @return bool|int
280
-     */
281
-    public function canCreate($member = null, $context = [])
282
-    {
283
-        return Permission::check('Location_CREATE', 'any', $member);
284
-    }
285
-
286
-    /**
287
-     * @return array
288
-     */
289
-    public function providePermissions()
290
-    {
291
-        return [
292
-            'Location_EDIT' => 'Edit a Location',
293
-            'Location_DELETE' => 'Delete a Location',
294
-            'Location_CREATE' => 'Create a Location',
295
-        ];
296
-    }
297
-
298
-    /**
299
-     * @return string
300
-     */
301
-    public function getWebsiteURL()
302
-    {
303
-        $url = $this->Website;
304
-
305
-        if ($url && !preg_match('/^(http|https):\/\//', $url)) {
306
-            $url = 'http://' . $url;
307
-        }
308
-
309
-        $this->extend('updateWebsiteURL', $url);
310
-
311
-        return $url;
312
-    }
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 int[]
75
+	 */
76
+	private static $defaults = [
77
+		'ShowInMenus' => 0,
78
+	];
79
+
80
+	/**
81
+	 * @var string
82
+	 */
83
+	private static $default_sort = 'Title';
84
+
85
+	/**
86
+	 * api access via Restful Server module
87
+	 *
88
+	 * @var bool
89
+	 */
90
+	private static $api_access = true;
91
+
92
+	/**
93
+	 * search fields for Model Admin
94
+	 *
95
+	 * @var array
96
+	 */
97
+	private static $searchable_fields = [
98
+		'Title',
99
+		'Address',
100
+		'City',
101
+		'State',
102
+		'PostalCode',
103
+		'Country',
104
+		'Website',
105
+		'Phone',
106
+		'Email',
107
+		'Featured',
108
+	];
109
+
110
+	/**
111
+	 * columns for grid field
112
+	 *
113
+	 * @var array
114
+	 */
115
+	private static $summary_fields = [
116
+		'Title',
117
+		'Address',
118
+		'Address2',
119
+		'City',
120
+		'State',
121
+		'PostalCode',
122
+		'CountryCode',
123
+		'Phone' => 'Phone',
124
+		'Fax' => 'Fax',
125
+		'Email' => 'Email',
126
+		'Website' => 'Website',
127
+		'Featured',
128
+		'CategoryList',
129
+		'Lat',
130
+		'Lng',
131
+		'Import_ID',
132
+	];
133
+
134
+	/**
135
+	 * @var bool
136
+	 */
137
+	private static $show_in_sitetree = false;
138
+
139
+	/**
140
+	 * @var array
141
+	 */
142
+	private static $allowed_children = [];
143
+
144
+	/**
145
+	 * Coords status for $summary_fields
146
+	 *
147
+	 * @return string
148
+	 */
149
+	public function getCoords()
150
+	{
151
+		return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false';
152
+	}
153
+
154
+	/**
155
+	 * @return string
156
+	 */
157
+	public function getCategoryList()
158
+	{
159
+		if ($this->Categories()->count()) {
160
+			return implode(', ', $this->Categories()->column('Name'));
161
+		}
162
+
163
+		return '';
164
+	}
165
+
166
+	/**
167
+	 * @return bool|string
168
+	 */
169
+	public function getCountryCode()
170
+	{
171
+		if ($this->Country) {
172
+			return strtoupper($this->Country);
173
+		}
174
+
175
+		return false;
176
+	}
177
+
178
+	/**
179
+	 * custom labels for fields
180
+	 *
181
+	 * @param bool $includerelations
182
+	 * @return array|string
183
+	 */
184
+	public function fieldLabels($includerelations = true)
185
+	{
186
+		$labels = parent::fieldLabels($includerelations);
187
+
188
+		$labels['Title'] = 'Name';
189
+		$labels['Address2'] = 'Address 2';
190
+		$labels['PostalCode'] = 'Postal Code';
191
+		$labels['Categories.Name'] = 'Categories';
192
+		$labels['Featured.NiceAsBoolean'] = 'Featured';
193
+
194
+		return $labels;
195
+	}
196
+
197
+	/**
198
+	 * @return FieldList
199
+	 */
200
+	public function getCMSFields()
201
+	{
202
+		$this->beforeUpdateCMSFields(function (FieldList $fields) {
203
+			$fields->addFieldsToTab(
204
+				'Root.Main',
205
+				[
206
+					CheckboxField::create('Featured')
207
+						->setTitle('Featured'),
208
+				],
209
+				'Content'
210
+			);
211
+
212
+			if ($this->exists()) {
213
+				$fields->addFieldToTab(
214
+					'Root.Categories',
215
+					GridField::create(
216
+						'Categories',
217
+						'Categories',
218
+						$this->Categories(),
219
+						$catConfig = GridFieldConfig_RelationEditor::create()
220
+					)
221
+				);
222
+
223
+				$catConfig->removeComponentsByType([
224
+					GridFieldAddExistingAutocompleter::class,
225
+				])->addComponents([
226
+					new GridFieldAddExistingSearchButton()
227
+				]);
228
+			}
229
+
230
+			$fields->addFieldsToTab('Root.Contact', [
231
+				TextField::create('Website')
232
+					->setTitle('Website')
233
+					->setDescription('Include the http/https (example: https://google.com)'),
234
+				TextField::create('Phone')
235
+					->setTitle('Phone'),
236
+				EmailField::create('Email')
237
+					->setTitle('Email'),
238
+				TextField::create('Fax')
239
+					->setTitle('Fax'),
240
+			]);
241
+		});
242
+
243
+		return parent::getCMSFields();
244
+	}
245
+
246
+	/**
247
+	 * @param null $member
248
+	 * @param array $context
249
+	 * @return bool
250
+	 */
251
+	public function canView($member = null, $context = [])
252
+	{
253
+		return true;
254
+	}
255
+
256
+	/**
257
+	 * @param null $member
258
+	 * @param array $context
259
+	 * @return bool|int
260
+	 */
261
+	public function canEdit($member = null, $context = [])
262
+	{
263
+		return Permission::check('Location_EDIT', 'any', $member);
264
+	}
265
+
266
+	/**
267
+	 * @param null $member
268
+	 * @param array $context
269
+	 * @return bool|int
270
+	 */
271
+	public function canDelete($member = null, $context = [])
272
+	{
273
+		return Permission::check('Location_DELETE', 'any', $member);
274
+	}
275
+
276
+	/**
277
+	 * @param null $member
278
+	 * @param array $context
279
+	 * @return bool|int
280
+	 */
281
+	public function canCreate($member = null, $context = [])
282
+	{
283
+		return Permission::check('Location_CREATE', 'any', $member);
284
+	}
285
+
286
+	/**
287
+	 * @return array
288
+	 */
289
+	public function providePermissions()
290
+	{
291
+		return [
292
+			'Location_EDIT' => 'Edit a Location',
293
+			'Location_DELETE' => 'Delete a Location',
294
+			'Location_CREATE' => 'Create a Location',
295
+		];
296
+	}
297
+
298
+	/**
299
+	 * @return string
300
+	 */
301
+	public function getWebsiteURL()
302
+	{
303
+		$url = $this->Website;
304
+
305
+		if ($url && !preg_match('/^(http|https):\/\//', $url)) {
306
+			$url = 'http://' . $url;
307
+		}
308
+
309
+		$this->extend('updateWebsiteURL', $url);
310
+
311
+		return $url;
312
+	}
313 313
 }
Please login to merge, or discard this patch.