@@ -31,260 +31,260 @@ |
||
| 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 | - 'Title' => 'Varchar(255)', |
|
| 49 | - 'Featured' => 'Boolean', |
|
| 50 | - 'Website' => 'Varchar(255)', |
|
| 51 | - 'Phone' => 'Varchar(40)', |
|
| 52 | - 'Email' => 'Varchar(255)', |
|
| 53 | - 'Fax' => 'Varchar(45)', |
|
| 54 | - 'Import_ID' => 'Int', |
|
| 55 | - 'LegacyObjectID' => 'Int', |
|
| 56 | - ]; |
|
| 57 | - |
|
| 58 | - private static $many_many = [ |
|
| 59 | - 'Categories' => LocationCategory::class, |
|
| 60 | - ]; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var string |
|
| 64 | - */ |
|
| 65 | - private static $table_name = 'LocationPage'; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var array |
|
| 69 | - */ |
|
| 70 | - private static $casting = [ |
|
| 71 | - 'distance' => 'Decimal(9,3)', |
|
| 72 | - ]; |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @var string |
|
| 76 | - */ |
|
| 77 | - private static $default_sort = 'Title'; |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * api access via Restful Server module |
|
| 81 | - * |
|
| 82 | - * @var bool |
|
| 83 | - */ |
|
| 84 | - private static $api_access = true; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * search fields for Model Admin |
|
| 88 | - * |
|
| 89 | - * @var array |
|
| 90 | - */ |
|
| 91 | - private static $searchable_fields = [ |
|
| 92 | - 'Title', |
|
| 93 | - 'Address', |
|
| 94 | - 'City', |
|
| 95 | - 'State', |
|
| 96 | - 'PostalCode', |
|
| 97 | - 'Country', |
|
| 98 | - 'Website', |
|
| 99 | - 'Phone', |
|
| 100 | - 'Email', |
|
| 101 | - 'Featured', |
|
| 102 | - ]; |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * columns for grid field |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - private static $summary_fields = [ |
|
| 110 | - 'Title', |
|
| 111 | - 'Address', |
|
| 112 | - 'Address2', |
|
| 113 | - 'City', |
|
| 114 | - 'State', |
|
| 115 | - 'PostalCode', |
|
| 116 | - 'CountryCode', |
|
| 117 | - 'Phone' => 'Phone', |
|
| 118 | - 'Fax' => 'Fax', |
|
| 119 | - 'Email' => 'Email', |
|
| 120 | - 'Website' => 'Website', |
|
| 121 | - 'Featured', |
|
| 122 | - 'CategoryList', |
|
| 123 | - 'Lat', |
|
| 124 | - 'Lng', |
|
| 125 | - 'Import_ID', |
|
| 126 | - ]; |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Coords status for $summary_fields |
|
| 130 | - * |
|
| 131 | - * @return string |
|
| 132 | - */ |
|
| 133 | - public function getCoords() |
|
| 134 | - { |
|
| 135 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @return string |
|
| 140 | - */ |
|
| 141 | - public function getCategoryList() |
|
| 142 | - { |
|
| 143 | - if ($this->Categories()->count()) { |
|
| 144 | - return implode(', ', $this->Categories()->column('Name')); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return ''; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - /** |
|
| 151 | - * @return bool|string |
|
| 152 | - */ |
|
| 153 | - public function getCountryCode() |
|
| 154 | - { |
|
| 155 | - if ($this->Country) { |
|
| 156 | - return strtoupper($this->Country); |
|
| 157 | - } |
|
| 158 | - |
|
| 159 | - return false; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - /** |
|
| 163 | - * custom labels for fields |
|
| 164 | - * |
|
| 165 | - * @param bool $includerelations |
|
| 166 | - * @return array|string |
|
| 167 | - */ |
|
| 168 | - public function fieldLabels($includerelations = true) |
|
| 169 | - { |
|
| 170 | - $labels = parent::fieldLabels($includerelations); |
|
| 171 | - |
|
| 172 | - $labels['Title'] = 'Name'; |
|
| 173 | - $labels['Address2'] = 'Address 2'; |
|
| 174 | - $labels['PostalCode'] = 'Postal Code'; |
|
| 175 | - $labels['Categories.Name'] = 'Categories'; |
|
| 176 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 177 | - |
|
| 178 | - return $labels; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - /** |
|
| 182 | - * @return FieldList |
|
| 183 | - */ |
|
| 184 | - public function getCMSFields() |
|
| 185 | - { |
|
| 186 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 187 | - $fields->addFieldsToTab( |
|
| 188 | - 'Root.Main', |
|
| 189 | - [ |
|
| 190 | - CheckboxField::create('Featured') |
|
| 191 | - ->setTitle('Featured'), |
|
| 192 | - TextField::create('Website') |
|
| 193 | - ->setTitle('Website') |
|
| 194 | - ->setDescription('Include the http/https (example: https://google.com)'), |
|
| 195 | - TextField::create('Phone') |
|
| 196 | - ->setTitle('Phone'), |
|
| 197 | - EmailField::create('Email') |
|
| 198 | - ->setTitle('Email'), |
|
| 199 | - TextField::create('Fax') |
|
| 200 | - ->setTitle('Fax'), |
|
| 201 | - ], |
|
| 202 | - 'Content' |
|
| 203 | - ); |
|
| 204 | - |
|
| 205 | - if ($this->exists()) { |
|
| 206 | - $fields->addFieldToTab( |
|
| 207 | - 'Root.Categories', |
|
| 208 | - GridField::create( |
|
| 209 | - 'Categories', |
|
| 210 | - 'Categories', |
|
| 211 | - $this->Categories(), |
|
| 212 | - $catConfig = GridFieldConfig_RelationEditor::create() |
|
| 213 | - ) |
|
| 214 | - ); |
|
| 215 | - |
|
| 216 | - $catConfig->removeComponentsByType([ |
|
| 217 | - GridFieldAddExistingAutocompleter::class, |
|
| 218 | - ])->addComponents([ |
|
| 219 | - new GridFieldAddExistingSearchButton() |
|
| 220 | - ]); |
|
| 221 | - } |
|
| 222 | - }); |
|
| 223 | - |
|
| 224 | - return parent::getCMSFields(); |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * @param null $member |
|
| 229 | - * @param array $context |
|
| 230 | - * @return bool |
|
| 231 | - */ |
|
| 232 | - public function canView($member = null, $context = []) |
|
| 233 | - { |
|
| 234 | - return true; |
|
| 235 | - } |
|
| 236 | - |
|
| 237 | - /** |
|
| 238 | - * @param null $member |
|
| 239 | - * @param array $context |
|
| 240 | - * @return bool|int |
|
| 241 | - */ |
|
| 242 | - public function canEdit($member = null, $context = []) |
|
| 243 | - { |
|
| 244 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - /** |
|
| 248 | - * @param null $member |
|
| 249 | - * @param array $context |
|
| 250 | - * @return bool|int |
|
| 251 | - */ |
|
| 252 | - public function canDelete($member = null, $context = []) |
|
| 253 | - { |
|
| 254 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 255 | - } |
|
| 256 | - |
|
| 257 | - /** |
|
| 258 | - * @param null $member |
|
| 259 | - * @param array $context |
|
| 260 | - * @return bool|int |
|
| 261 | - */ |
|
| 262 | - public function canCreate($member = null, $context = []) |
|
| 263 | - { |
|
| 264 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 265 | - } |
|
| 266 | - |
|
| 267 | - /** |
|
| 268 | - * @return array |
|
| 269 | - */ |
|
| 270 | - public function providePermissions() |
|
| 271 | - { |
|
| 272 | - return [ |
|
| 273 | - 'Location_EDIT' => 'Edit a Location', |
|
| 274 | - 'Location_DELETE' => 'Delete a Location', |
|
| 275 | - 'Location_CREATE' => 'Create a Location', |
|
| 276 | - ]; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * @return string |
|
| 281 | - */ |
|
| 282 | - public function getWebsiteURL() |
|
| 283 | - { |
|
| 284 | - $url = $this->Website; |
|
| 285 | - |
|
| 286 | - $this->extend('updateWebsiteURL', $url); |
|
| 287 | - |
|
| 288 | - return $url; |
|
| 289 | - } |
|
| 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 | + 'Title' => 'Varchar(255)', |
|
| 49 | + 'Featured' => 'Boolean', |
|
| 50 | + 'Website' => 'Varchar(255)', |
|
| 51 | + 'Phone' => 'Varchar(40)', |
|
| 52 | + 'Email' => 'Varchar(255)', |
|
| 53 | + 'Fax' => 'Varchar(45)', |
|
| 54 | + 'Import_ID' => 'Int', |
|
| 55 | + 'LegacyObjectID' => 'Int', |
|
| 56 | + ]; |
|
| 57 | + |
|
| 58 | + private static $many_many = [ |
|
| 59 | + 'Categories' => LocationCategory::class, |
|
| 60 | + ]; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var string |
|
| 64 | + */ |
|
| 65 | + private static $table_name = 'LocationPage'; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var array |
|
| 69 | + */ |
|
| 70 | + private static $casting = [ |
|
| 71 | + 'distance' => 'Decimal(9,3)', |
|
| 72 | + ]; |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @var string |
|
| 76 | + */ |
|
| 77 | + private static $default_sort = 'Title'; |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * api access via Restful Server module |
|
| 81 | + * |
|
| 82 | + * @var bool |
|
| 83 | + */ |
|
| 84 | + private static $api_access = true; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * search fields for Model Admin |
|
| 88 | + * |
|
| 89 | + * @var array |
|
| 90 | + */ |
|
| 91 | + private static $searchable_fields = [ |
|
| 92 | + 'Title', |
|
| 93 | + 'Address', |
|
| 94 | + 'City', |
|
| 95 | + 'State', |
|
| 96 | + 'PostalCode', |
|
| 97 | + 'Country', |
|
| 98 | + 'Website', |
|
| 99 | + 'Phone', |
|
| 100 | + 'Email', |
|
| 101 | + 'Featured', |
|
| 102 | + ]; |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * columns for grid field |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + private static $summary_fields = [ |
|
| 110 | + 'Title', |
|
| 111 | + 'Address', |
|
| 112 | + 'Address2', |
|
| 113 | + 'City', |
|
| 114 | + 'State', |
|
| 115 | + 'PostalCode', |
|
| 116 | + 'CountryCode', |
|
| 117 | + 'Phone' => 'Phone', |
|
| 118 | + 'Fax' => 'Fax', |
|
| 119 | + 'Email' => 'Email', |
|
| 120 | + 'Website' => 'Website', |
|
| 121 | + 'Featured', |
|
| 122 | + 'CategoryList', |
|
| 123 | + 'Lat', |
|
| 124 | + 'Lng', |
|
| 125 | + 'Import_ID', |
|
| 126 | + ]; |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Coords status for $summary_fields |
|
| 130 | + * |
|
| 131 | + * @return string |
|
| 132 | + */ |
|
| 133 | + public function getCoords() |
|
| 134 | + { |
|
| 135 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @return string |
|
| 140 | + */ |
|
| 141 | + public function getCategoryList() |
|
| 142 | + { |
|
| 143 | + if ($this->Categories()->count()) { |
|
| 144 | + return implode(', ', $this->Categories()->column('Name')); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return ''; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + /** |
|
| 151 | + * @return bool|string |
|
| 152 | + */ |
|
| 153 | + public function getCountryCode() |
|
| 154 | + { |
|
| 155 | + if ($this->Country) { |
|
| 156 | + return strtoupper($this->Country); |
|
| 157 | + } |
|
| 158 | + |
|
| 159 | + return false; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + /** |
|
| 163 | + * custom labels for fields |
|
| 164 | + * |
|
| 165 | + * @param bool $includerelations |
|
| 166 | + * @return array|string |
|
| 167 | + */ |
|
| 168 | + public function fieldLabels($includerelations = true) |
|
| 169 | + { |
|
| 170 | + $labels = parent::fieldLabels($includerelations); |
|
| 171 | + |
|
| 172 | + $labels['Title'] = 'Name'; |
|
| 173 | + $labels['Address2'] = 'Address 2'; |
|
| 174 | + $labels['PostalCode'] = 'Postal Code'; |
|
| 175 | + $labels['Categories.Name'] = 'Categories'; |
|
| 176 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 177 | + |
|
| 178 | + return $labels; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + /** |
|
| 182 | + * @return FieldList |
|
| 183 | + */ |
|
| 184 | + public function getCMSFields() |
|
| 185 | + { |
|
| 186 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 187 | + $fields->addFieldsToTab( |
|
| 188 | + 'Root.Main', |
|
| 189 | + [ |
|
| 190 | + CheckboxField::create('Featured') |
|
| 191 | + ->setTitle('Featured'), |
|
| 192 | + TextField::create('Website') |
|
| 193 | + ->setTitle('Website') |
|
| 194 | + ->setDescription('Include the http/https (example: https://google.com)'), |
|
| 195 | + TextField::create('Phone') |
|
| 196 | + ->setTitle('Phone'), |
|
| 197 | + EmailField::create('Email') |
|
| 198 | + ->setTitle('Email'), |
|
| 199 | + TextField::create('Fax') |
|
| 200 | + ->setTitle('Fax'), |
|
| 201 | + ], |
|
| 202 | + 'Content' |
|
| 203 | + ); |
|
| 204 | + |
|
| 205 | + if ($this->exists()) { |
|
| 206 | + $fields->addFieldToTab( |
|
| 207 | + 'Root.Categories', |
|
| 208 | + GridField::create( |
|
| 209 | + 'Categories', |
|
| 210 | + 'Categories', |
|
| 211 | + $this->Categories(), |
|
| 212 | + $catConfig = GridFieldConfig_RelationEditor::create() |
|
| 213 | + ) |
|
| 214 | + ); |
|
| 215 | + |
|
| 216 | + $catConfig->removeComponentsByType([ |
|
| 217 | + GridFieldAddExistingAutocompleter::class, |
|
| 218 | + ])->addComponents([ |
|
| 219 | + new GridFieldAddExistingSearchButton() |
|
| 220 | + ]); |
|
| 221 | + } |
|
| 222 | + }); |
|
| 223 | + |
|
| 224 | + return parent::getCMSFields(); |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * @param null $member |
|
| 229 | + * @param array $context |
|
| 230 | + * @return bool |
|
| 231 | + */ |
|
| 232 | + public function canView($member = null, $context = []) |
|
| 233 | + { |
|
| 234 | + return true; |
|
| 235 | + } |
|
| 236 | + |
|
| 237 | + /** |
|
| 238 | + * @param null $member |
|
| 239 | + * @param array $context |
|
| 240 | + * @return bool|int |
|
| 241 | + */ |
|
| 242 | + public function canEdit($member = null, $context = []) |
|
| 243 | + { |
|
| 244 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + /** |
|
| 248 | + * @param null $member |
|
| 249 | + * @param array $context |
|
| 250 | + * @return bool|int |
|
| 251 | + */ |
|
| 252 | + public function canDelete($member = null, $context = []) |
|
| 253 | + { |
|
| 254 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 255 | + } |
|
| 256 | + |
|
| 257 | + /** |
|
| 258 | + * @param null $member |
|
| 259 | + * @param array $context |
|
| 260 | + * @return bool|int |
|
| 261 | + */ |
|
| 262 | + public function canCreate($member = null, $context = []) |
|
| 263 | + { |
|
| 264 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 265 | + } |
|
| 266 | + |
|
| 267 | + /** |
|
| 268 | + * @return array |
|
| 269 | + */ |
|
| 270 | + public function providePermissions() |
|
| 271 | + { |
|
| 272 | + return [ |
|
| 273 | + 'Location_EDIT' => 'Edit a Location', |
|
| 274 | + 'Location_DELETE' => 'Delete a Location', |
|
| 275 | + 'Location_CREATE' => 'Create a Location', |
|
| 276 | + ]; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * @return string |
|
| 281 | + */ |
|
| 282 | + public function getWebsiteURL() |
|
| 283 | + { |
|
| 284 | + $url = $this->Website; |
|
| 285 | + |
|
| 286 | + $this->extend('updateWebsiteURL', $url); |
|
| 287 | + |
|
| 288 | + return $url; |
|
| 289 | + } |
|
| 290 | 290 | } |
@@ -183,7 +183,7 @@ |
||
| 183 | 183 | */ |
| 184 | 184 | public function getCMSFields() |
| 185 | 185 | { |
| 186 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 186 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 187 | 187 | $fields->addFieldsToTab( |
| 188 | 188 | 'Root.Main', |
| 189 | 189 | [ |
@@ -17,83 +17,83 @@ |
||
| 17 | 17 | class LocationAdmin extends ModelAdmin |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var array |
|
| 22 | - */ |
|
| 23 | - private static $managed_models = [ |
|
| 24 | - Location::class, |
|
| 25 | - LocationCategory::class, |
|
| 26 | - ]; |
|
| 20 | + /** |
|
| 21 | + * @var array |
|
| 22 | + */ |
|
| 23 | + private static $managed_models = [ |
|
| 24 | + Location::class, |
|
| 25 | + LocationCategory::class, |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - private static $model_importers = [ |
|
| 32 | - Location::class => LocationCsvBulkLoader::class, |
|
| 33 | - LocationCategory::class => CsvBulkLoader::class, |
|
| 34 | - ]; |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + private static $model_importers = [ |
|
| 32 | + Location::class => LocationCsvBulkLoader::class, |
|
| 33 | + LocationCategory::class => CsvBulkLoader::class, |
|
| 34 | + ]; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private static $menu_title = 'Locator'; |
|
| 40 | - /** |
|
| 41 | - * @var string |
|
| 42 | - */ |
|
| 43 | - private static $url_segment = 'locator'; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private static $menu_title = 'Locator'; |
|
| 40 | + /** |
|
| 41 | + * @var string |
|
| 42 | + */ |
|
| 43 | + private static $url_segment = 'locator'; |
|
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @return array |
|
| 47 | - */ |
|
| 48 | - public function getExportFields() |
|
| 49 | - { |
|
| 50 | - if ($this->modelClass == Location::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 == Location::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 == Location::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 == Location::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 | } |
@@ -15,72 +15,72 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class LocationToPageTask extends BuildTask |
| 17 | 17 | { |
| 18 | - /** |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - protected $title = 'Locator - Location to Page Task'; |
|
| 18 | + /** |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + protected $title = 'Locator - Location to Page Task'; |
|
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var string |
|
| 25 | - */ |
|
| 26 | - private static $segment = 'locator-location-to-page-task'; |
|
| 23 | + /** |
|
| 24 | + * @var string |
|
| 25 | + */ |
|
| 26 | + private static $segment = 'locator-location-to-page-task'; |
|
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var bool |
|
| 30 | - */ |
|
| 31 | - private static $auto_publish_location = false; |
|
| 28 | + /** |
|
| 29 | + * @var bool |
|
| 30 | + */ |
|
| 31 | + private static $auto_publish_location = false; |
|
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @param \SilverStripe\Control\HTTPRequest $request |
|
| 35 | - */ |
|
| 36 | - public function run($request) |
|
| 37 | - { |
|
| 38 | - $this->migrateLocations(); |
|
| 39 | - } |
|
| 33 | + /** |
|
| 34 | + * @param \SilverStripe\Control\HTTPRequest $request |
|
| 35 | + */ |
|
| 36 | + public function run($request) |
|
| 37 | + { |
|
| 38 | + $this->migrateLocations(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * |
|
| 43 | - */ |
|
| 44 | - protected function migrateLocations() |
|
| 45 | - { |
|
| 46 | - if (!$parent = Locator::get()->first()) { |
|
| 47 | - $parent = Locator::create(); |
|
| 48 | - $parent->Title = "Locator"; |
|
| 49 | - $parent->writeToStage(Versioned::DRAFT); |
|
| 50 | - } |
|
| 41 | + /** |
|
| 42 | + * |
|
| 43 | + */ |
|
| 44 | + protected function migrateLocations() |
|
| 45 | + { |
|
| 46 | + if (!$parent = Locator::get()->first()) { |
|
| 47 | + $parent = Locator::create(); |
|
| 48 | + $parent->Title = "Locator"; |
|
| 49 | + $parent->writeToStage(Versioned::DRAFT); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - /** @var Location $location */ |
|
| 53 | - foreach ($this->getLocations() as $location) { |
|
| 54 | - if (!LocationPage::get()->filter('LegacyObjectID', $location->ID)->first()) { |
|
| 55 | - if ($location->hasMethod('isPublished')) { |
|
| 56 | - $published = $location->isPublished(); |
|
| 57 | - } |
|
| 52 | + /** @var Location $location */ |
|
| 53 | + foreach ($this->getLocations() as $location) { |
|
| 54 | + if (!LocationPage::get()->filter('LegacyObjectID', $location->ID)->first()) { |
|
| 55 | + if ($location->hasMethod('isPublished')) { |
|
| 56 | + $published = $location->isPublished(); |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** @var LocationPage $newLocation */ |
|
| 60 | - $newLocation = Injector::inst()->create(LocationPage::class, $location->toMap(), false); |
|
| 61 | - $newLocation->setClassName(LocationPage::class); |
|
| 62 | - $newLocation->ID = null; |
|
| 63 | - $newLocation->ParentID = $parent->ID; |
|
| 64 | - $newLocation->LegacyObjectID = $location->ID; |
|
| 59 | + /** @var LocationPage $newLocation */ |
|
| 60 | + $newLocation = Injector::inst()->create(LocationPage::class, $location->toMap(), false); |
|
| 61 | + $newLocation->setClassName(LocationPage::class); |
|
| 62 | + $newLocation->ID = null; |
|
| 63 | + $newLocation->ParentID = $parent->ID; |
|
| 64 | + $newLocation->LegacyObjectID = $location->ID; |
|
| 65 | 65 | |
| 66 | - $this->extend('preLocationMigrationUpdate', $location, $newLocation); |
|
| 66 | + $this->extend('preLocationMigrationUpdate', $location, $newLocation); |
|
| 67 | 67 | |
| 68 | - $newLocation->writeToStage(Versioned::DRAFT); |
|
| 68 | + $newLocation->writeToStage(Versioned::DRAFT); |
|
| 69 | 69 | |
| 70 | - if ((isset($published) && $published) || $this->config()->get('auto_publish_location')) { |
|
| 71 | - $newLocation->publishSingle(); |
|
| 72 | - } |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 70 | + if ((isset($published) && $published) || $this->config()->get('auto_publish_location')) { |
|
| 71 | + $newLocation->publishSingle(); |
|
| 72 | + } |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | 76 | |
| 77 | - /** |
|
| 78 | - * @return \Generator |
|
| 79 | - */ |
|
| 80 | - protected function getLocations() |
|
| 81 | - { |
|
| 82 | - foreach (Location::get() as $location) { |
|
| 83 | - yield $location; |
|
| 84 | - } |
|
| 85 | - } |
|
| 77 | + /** |
|
| 78 | + * @return \Generator |
|
| 79 | + */ |
|
| 80 | + protected function getLocations() |
|
| 81 | + { |
|
| 82 | + foreach (Location::get() as $location) { |
|
| 83 | + yield $location; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -11,76 +11,76 @@ |
||
| 11 | 11 | */ |
| 12 | 12 | class LocationPublishTask extends BuildTask |
| 13 | 13 | { |
| 14 | - /** |
|
| 15 | - * @var string |
|
| 16 | - */ |
|
| 17 | - protected $title = 'Publish all Locations'; |
|
| 18 | - /** |
|
| 19 | - * @var string |
|
| 20 | - */ |
|
| 21 | - protected $description = 'Migration task - pre versioning on Location'; |
|
| 22 | - /** |
|
| 23 | - * @var bool |
|
| 24 | - */ |
|
| 25 | - protected $enabled = true; |
|
| 14 | + /** |
|
| 15 | + * @var string |
|
| 16 | + */ |
|
| 17 | + protected $title = 'Publish all Locations'; |
|
| 18 | + /** |
|
| 19 | + * @var string |
|
| 20 | + */ |
|
| 21 | + protected $description = 'Migration task - pre versioning on Location'; |
|
| 22 | + /** |
|
| 23 | + * @var bool |
|
| 24 | + */ |
|
| 25 | + protected $enabled = true; |
|
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @param $request |
|
| 29 | - */ |
|
| 30 | - public function run($request) |
|
| 31 | - { |
|
| 32 | - $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location'; |
|
| 33 | - $this->publishLocations($class); |
|
| 34 | - } |
|
| 27 | + /** |
|
| 28 | + * @param $request |
|
| 29 | + */ |
|
| 30 | + public function run($request) |
|
| 31 | + { |
|
| 32 | + $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : 'Location'; |
|
| 33 | + $this->publishLocations($class); |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @param string $class |
|
| 38 | - * @return \Generator |
|
| 39 | - */ |
|
| 40 | - protected function iterateLocations($class) |
|
| 41 | - { |
|
| 42 | - foreach ($class::get()->filter('ShowInLocator', true) as $location) { |
|
| 43 | - yield $location; |
|
| 44 | - } |
|
| 45 | - } |
|
| 36 | + /** |
|
| 37 | + * @param string $class |
|
| 38 | + * @return \Generator |
|
| 39 | + */ |
|
| 40 | + protected function iterateLocations($class) |
|
| 41 | + { |
|
| 42 | + foreach ($class::get()->filter('ShowInLocator', true) as $location) { |
|
| 43 | + yield $location; |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * mark all ProductDetail records as ShowInMenus = 0. |
|
| 49 | - * |
|
| 50 | - * @param string $class |
|
| 51 | - */ |
|
| 52 | - public function publishLocations($class) |
|
| 53 | - { |
|
| 54 | - if (!isset($class) || !class_exists($class) || !$class instanceof Location) { |
|
| 55 | - $class = 'Location'; |
|
| 56 | - } |
|
| 57 | - $ct = 0; |
|
| 58 | - $publish = function ($location) use (&$ct) { |
|
| 59 | - if (!$location->isPublished()) { |
|
| 60 | - $title = $location->Title; |
|
| 61 | - $location->writeToStage('Stage'); |
|
| 62 | - $location->publish('Stage', 'Live'); |
|
| 63 | - static::write_message($title); |
|
| 64 | - ++$ct; |
|
| 65 | - } |
|
| 66 | - }; |
|
| 47 | + /** |
|
| 48 | + * mark all ProductDetail records as ShowInMenus = 0. |
|
| 49 | + * |
|
| 50 | + * @param string $class |
|
| 51 | + */ |
|
| 52 | + public function publishLocations($class) |
|
| 53 | + { |
|
| 54 | + if (!isset($class) || !class_exists($class) || !$class instanceof Location) { |
|
| 55 | + $class = 'Location'; |
|
| 56 | + } |
|
| 57 | + $ct = 0; |
|
| 58 | + $publish = function ($location) use (&$ct) { |
|
| 59 | + if (!$location->isPublished()) { |
|
| 60 | + $title = $location->Title; |
|
| 61 | + $location->writeToStage('Stage'); |
|
| 62 | + $location->publish('Stage', 'Live'); |
|
| 63 | + static::write_message($title); |
|
| 64 | + ++$ct; |
|
| 65 | + } |
|
| 66 | + }; |
|
| 67 | 67 | |
| 68 | - foreach ($this->iterateLocations($class) as $location) { |
|
| 69 | - $publish($location); |
|
| 70 | - } |
|
| 68 | + foreach ($this->iterateLocations($class) as $location) { |
|
| 69 | + $publish($location); |
|
| 70 | + } |
|
| 71 | 71 | |
| 72 | - static::write_message("{$ct} locations updated."); |
|
| 73 | - } |
|
| 72 | + static::write_message("{$ct} locations updated."); |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * @param $message |
|
| 77 | - */ |
|
| 78 | - protected static function write_message($message) |
|
| 79 | - { |
|
| 80 | - if (Director::is_cli()) { |
|
| 81 | - echo "{$message}\n"; |
|
| 82 | - } else { |
|
| 83 | - echo "{$message}<br><br>"; |
|
| 84 | - } |
|
| 85 | - } |
|
| 75 | + /** |
|
| 76 | + * @param $message |
|
| 77 | + */ |
|
| 78 | + protected static function write_message($message) |
|
| 79 | + { |
|
| 80 | + if (Director::is_cli()) { |
|
| 81 | + echo "{$message}\n"; |
|
| 82 | + } else { |
|
| 83 | + echo "{$message}<br><br>"; |
|
| 84 | + } |
|
| 85 | + } |
|
| 86 | 86 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | $class = 'Location'; |
| 56 | 56 | } |
| 57 | 57 | $ct = 0; |
| 58 | - $publish = function ($location) use (&$ct) { |
|
| 58 | + $publish = function($location) use (&$ct) { |
|
| 59 | 59 | if (!$location->isPublished()) { |
| 60 | 60 | $title = $location->Title; |
| 61 | 61 | $location->writeToStage('Stage'); |
@@ -14,72 +14,72 @@ |
||
| 14 | 14 | class LocationCategoriesTask extends BuildTask |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var string |
|
| 19 | - */ |
|
| 20 | - protected $title = 'Location categories to many_many'; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var string |
|
| 24 | - */ |
|
| 25 | - protected $description = 'Migration task - Converts locations to have multiple categories'; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var bool |
|
| 29 | - */ |
|
| 30 | - protected $enabled = true; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @param $request |
|
| 34 | - */ |
|
| 35 | - public function run($request) |
|
| 36 | - { |
|
| 37 | - /** @var DataObject $class */ |
|
| 38 | - $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : Location::class; |
|
| 39 | - $class::add_extension(LocationCategoryExtension::class); |
|
| 40 | - |
|
| 41 | - |
|
| 42 | - $categories = []; |
|
| 43 | - |
|
| 44 | - $convert = function (DataObject $location) use (&$categories) { |
|
| 45 | - /** @var Location $location */ |
|
| 46 | - // skip if no category |
|
| 47 | - if ($location->CategoryID > 0) { |
|
| 48 | - $categories[$location->CategoryID][] = $location->ID; |
|
| 49 | - } |
|
| 50 | - }; |
|
| 51 | - |
|
| 52 | - foreach ($this->iterateLocations($class) as $location) { |
|
| 53 | - $convert($location); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $catCt = 0; |
|
| 57 | - $locCT = 0; |
|
| 58 | - |
|
| 59 | - foreach ($categories as $categoryID => $locations) { |
|
| 60 | - /** @var LocationCategory $category */ |
|
| 61 | - $category = LocationCategory::get()->byID($categoryID); |
|
| 62 | - $category->Locations()->addMany($locations); |
|
| 63 | - |
|
| 64 | - $catCt++; |
|
| 65 | - $locCT += count($locations); |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - echo "{$catCt} categories converted<br />"; |
|
| 69 | - echo "{$locCT} location relations converted<br />"; |
|
| 70 | - |
|
| 71 | - $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; |
|
| 72 | - echo "Process Time: {$time} seconds"; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * @param string $class |
|
| 77 | - * @return \Generator |
|
| 78 | - */ |
|
| 79 | - protected function iterateLocations($class) |
|
| 80 | - { |
|
| 81 | - foreach ($class::get() as $location) { |
|
| 82 | - yield $location; |
|
| 83 | - } |
|
| 84 | - } |
|
| 17 | + /** |
|
| 18 | + * @var string |
|
| 19 | + */ |
|
| 20 | + protected $title = 'Location categories to many_many'; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var string |
|
| 24 | + */ |
|
| 25 | + protected $description = 'Migration task - Converts locations to have multiple categories'; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var bool |
|
| 29 | + */ |
|
| 30 | + protected $enabled = true; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @param $request |
|
| 34 | + */ |
|
| 35 | + public function run($request) |
|
| 36 | + { |
|
| 37 | + /** @var DataObject $class */ |
|
| 38 | + $class = ($request->getVar('locationclass')) ? $request->getVar('locationclass') : Location::class; |
|
| 39 | + $class::add_extension(LocationCategoryExtension::class); |
|
| 40 | + |
|
| 41 | + |
|
| 42 | + $categories = []; |
|
| 43 | + |
|
| 44 | + $convert = function (DataObject $location) use (&$categories) { |
|
| 45 | + /** @var Location $location */ |
|
| 46 | + // skip if no category |
|
| 47 | + if ($location->CategoryID > 0) { |
|
| 48 | + $categories[$location->CategoryID][] = $location->ID; |
|
| 49 | + } |
|
| 50 | + }; |
|
| 51 | + |
|
| 52 | + foreach ($this->iterateLocations($class) as $location) { |
|
| 53 | + $convert($location); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $catCt = 0; |
|
| 57 | + $locCT = 0; |
|
| 58 | + |
|
| 59 | + foreach ($categories as $categoryID => $locations) { |
|
| 60 | + /** @var LocationCategory $category */ |
|
| 61 | + $category = LocationCategory::get()->byID($categoryID); |
|
| 62 | + $category->Locations()->addMany($locations); |
|
| 63 | + |
|
| 64 | + $catCt++; |
|
| 65 | + $locCT += count($locations); |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + echo "{$catCt} categories converted<br />"; |
|
| 69 | + echo "{$locCT} location relations converted<br />"; |
|
| 70 | + |
|
| 71 | + $time = microtime(true) - $_SERVER["REQUEST_TIME_FLOAT"]; |
|
| 72 | + echo "Process Time: {$time} seconds"; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * @param string $class |
|
| 77 | + * @return \Generator |
|
| 78 | + */ |
|
| 79 | + protected function iterateLocations($class) |
|
| 80 | + { |
|
| 81 | + foreach ($class::get() as $location) { |
|
| 82 | + yield $location; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | 85 | } |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | |
| 42 | 42 | $categories = []; |
| 43 | 43 | |
| 44 | - $convert = function (DataObject $location) use (&$categories) { |
|
| 44 | + $convert = function(DataObject $location) use (&$categories) { |
|
| 45 | 45 | /** @var Location $location */ |
| 46 | 46 | // skip if no category |
| 47 | 47 | if ($location->CategoryID > 0) { |
@@ -13,7 +13,7 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class LocationCategoryExtension extends DataExtension |
| 15 | 15 | { |
| 16 | - private static $has_one = [ |
|
| 17 | - 'Category' => LocationCategory::class, |
|
| 18 | - ]; |
|
| 16 | + private static $has_one = [ |
|
| 17 | + 'Category' => LocationCategory::class, |
|
| 18 | + ]; |
|
| 19 | 19 | } |
@@ -8,22 +8,22 @@ |
||
| 8 | 8 | |
| 9 | 9 | class EmailAddressTask extends BuildTask |
| 10 | 10 | { |
| 11 | - protected $title = 'Email Address Task'; // title of the script |
|
| 12 | - protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; |
|
| 11 | + protected $title = 'Email Address Task'; // title of the script |
|
| 12 | + protected $description = "Convert depreciated 'Email Address' field to new 'Email' field."; |
|
| 13 | 13 | |
| 14 | - public function run($request) |
|
| 15 | - { |
|
| 16 | - Config::inst()->update('DataObject', 'validation_enabled', false); |
|
| 17 | - $ct = 0; |
|
| 18 | - $updateEmail = function ($location) use (&$ct) { |
|
| 19 | - if (!$location->Email && $location->EmailAddress) { |
|
| 20 | - $location->Email = $location->EmailAddress; |
|
| 21 | - $location->write(); |
|
| 22 | - ++$ct; |
|
| 23 | - } |
|
| 24 | - }; |
|
| 25 | - Location::get()->each($updateEmail); |
|
| 26 | - Config::inst()->update('DataObject', 'validation_enabled', true); |
|
| 27 | - echo '<p>'.$ct.' Locations updated</p>'; |
|
| 28 | - } |
|
| 14 | + public function run($request) |
|
| 15 | + { |
|
| 16 | + Config::inst()->update('DataObject', 'validation_enabled', false); |
|
| 17 | + $ct = 0; |
|
| 18 | + $updateEmail = function ($location) use (&$ct) { |
|
| 19 | + if (!$location->Email && $location->EmailAddress) { |
|
| 20 | + $location->Email = $location->EmailAddress; |
|
| 21 | + $location->write(); |
|
| 22 | + ++$ct; |
|
| 23 | + } |
|
| 24 | + }; |
|
| 25 | + Location::get()->each($updateEmail); |
|
| 26 | + Config::inst()->update('DataObject', 'validation_enabled', true); |
|
| 27 | + echo '<p>'.$ct.' Locations updated</p>'; |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -15,7 +15,7 @@ |
||
| 15 | 15 | { |
| 16 | 16 | Config::inst()->update('DataObject', 'validation_enabled', false); |
| 17 | 17 | $ct = 0; |
| 18 | - $updateEmail = function ($location) use (&$ct) { |
|
| 18 | + $updateEmail = function($location) use (&$ct) { |
|
| 19 | 19 | if (!$location->Email && $location->EmailAddress) { |
| 20 | 20 | $location->Email = $location->EmailAddress; |
| 21 | 21 | $location->write(); |
@@ -23,125 +23,125 @@ |
||
| 23 | 23 | */ |
| 24 | 24 | class LocationCategory extends DataObject |
| 25 | 25 | { |
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - private static $singular_name = 'Category'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private static $plural_name = 'Categories'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var array |
|
| 38 | - */ |
|
| 39 | - private static $db = [ |
|
| 40 | - 'Name' => 'Varchar(100)', |
|
| 41 | - ]; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * @var array |
|
| 45 | - */ |
|
| 46 | - private static $belongs_many_many = [ |
|
| 47 | - 'Locators' => Locator::class, |
|
| 48 | - 'LocationSet' => Location::class, |
|
| 49 | - ]; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - private static $table_name = 'LocationCategory'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var string |
|
| 58 | - */ |
|
| 59 | - private static $default_sort = 'Name'; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @return \SilverStripe\Forms\FieldList |
|
| 63 | - */ |
|
| 64 | - public function getCMSFields() |
|
| 65 | - { |
|
| 66 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 67 | - $fields->removeByName([ |
|
| 68 | - 'Locations', |
|
| 69 | - 'LocationSet', |
|
| 70 | - 'Locators', |
|
| 71 | - 'LinkTracking', |
|
| 72 | - 'FileTracking', |
|
| 73 | - ]); |
|
| 74 | - |
|
| 75 | - if ($this->ID) { |
|
| 76 | - // Locations |
|
| 77 | - $config = GridFieldConfig_RelationEditor::create(); |
|
| 78 | - $config->removeComponentsByType([ |
|
| 79 | - GridFieldAddExistingAutocompleter::class, |
|
| 80 | - GridFieldAddNewButton::class, |
|
| 81 | - ]) |
|
| 82 | - ->addComponents([ |
|
| 83 | - new GridFieldAddExistingSearchButton(), |
|
| 84 | - ]); |
|
| 85 | - $locations = $this->Locations(); |
|
| 86 | - $locationField = GridField::create('Locations', 'Locations', $locations, $config); |
|
| 87 | - |
|
| 88 | - $fields->addFieldsToTab('Root.Main', [ |
|
| 89 | - $locationField, |
|
| 90 | - ]); |
|
| 91 | - } |
|
| 92 | - }); |
|
| 93 | - |
|
| 94 | - $fields = parent::getCMSFields(); |
|
| 95 | - |
|
| 96 | - return $fields; |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * For backwards compatability |
|
| 101 | - * @return ManyManyList |
|
| 102 | - */ |
|
| 103 | - public function Locations() |
|
| 104 | - { |
|
| 105 | - return $this->LocationSet(); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - /** |
|
| 109 | - * @param null $member |
|
| 110 | - * @param array $context |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function canView($member = null, $context = []) |
|
| 114 | - { |
|
| 115 | - return true; |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * @param null $member |
|
| 120 | - * @param array $context |
|
| 121 | - * @return bool|int |
|
| 122 | - */ |
|
| 123 | - public function canEdit($member = null, $context = []) |
|
| 124 | - { |
|
| 125 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * @param null $member |
|
| 130 | - * @param array $context |
|
| 131 | - * @return bool|int |
|
| 132 | - */ |
|
| 133 | - public function canDelete($member = null, $context = []) |
|
| 134 | - { |
|
| 135 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - /** |
|
| 139 | - * @param null $member |
|
| 140 | - * @param array $context |
|
| 141 | - * @return bool|int |
|
| 142 | - */ |
|
| 143 | - public function canCreate($member = null, $context = []) |
|
| 144 | - { |
|
| 145 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 146 | - } |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + private static $singular_name = 'Category'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private static $plural_name = 'Categories'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var array |
|
| 38 | + */ |
|
| 39 | + private static $db = [ |
|
| 40 | + 'Name' => 'Varchar(100)', |
|
| 41 | + ]; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * @var array |
|
| 45 | + */ |
|
| 46 | + private static $belongs_many_many = [ |
|
| 47 | + 'Locators' => Locator::class, |
|
| 48 | + 'LocationSet' => Location::class, |
|
| 49 | + ]; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + private static $table_name = 'LocationCategory'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var string |
|
| 58 | + */ |
|
| 59 | + private static $default_sort = 'Name'; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @return \SilverStripe\Forms\FieldList |
|
| 63 | + */ |
|
| 64 | + public function getCMSFields() |
|
| 65 | + { |
|
| 66 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 67 | + $fields->removeByName([ |
|
| 68 | + 'Locations', |
|
| 69 | + 'LocationSet', |
|
| 70 | + 'Locators', |
|
| 71 | + 'LinkTracking', |
|
| 72 | + 'FileTracking', |
|
| 73 | + ]); |
|
| 74 | + |
|
| 75 | + if ($this->ID) { |
|
| 76 | + // Locations |
|
| 77 | + $config = GridFieldConfig_RelationEditor::create(); |
|
| 78 | + $config->removeComponentsByType([ |
|
| 79 | + GridFieldAddExistingAutocompleter::class, |
|
| 80 | + GridFieldAddNewButton::class, |
|
| 81 | + ]) |
|
| 82 | + ->addComponents([ |
|
| 83 | + new GridFieldAddExistingSearchButton(), |
|
| 84 | + ]); |
|
| 85 | + $locations = $this->Locations(); |
|
| 86 | + $locationField = GridField::create('Locations', 'Locations', $locations, $config); |
|
| 87 | + |
|
| 88 | + $fields->addFieldsToTab('Root.Main', [ |
|
| 89 | + $locationField, |
|
| 90 | + ]); |
|
| 91 | + } |
|
| 92 | + }); |
|
| 93 | + |
|
| 94 | + $fields = parent::getCMSFields(); |
|
| 95 | + |
|
| 96 | + return $fields; |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * For backwards compatability |
|
| 101 | + * @return ManyManyList |
|
| 102 | + */ |
|
| 103 | + public function Locations() |
|
| 104 | + { |
|
| 105 | + return $this->LocationSet(); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + /** |
|
| 109 | + * @param null $member |
|
| 110 | + * @param array $context |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function canView($member = null, $context = []) |
|
| 114 | + { |
|
| 115 | + return true; |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * @param null $member |
|
| 120 | + * @param array $context |
|
| 121 | + * @return bool|int |
|
| 122 | + */ |
|
| 123 | + public function canEdit($member = null, $context = []) |
|
| 124 | + { |
|
| 125 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * @param null $member |
|
| 130 | + * @param array $context |
|
| 131 | + * @return bool|int |
|
| 132 | + */ |
|
| 133 | + public function canDelete($member = null, $context = []) |
|
| 134 | + { |
|
| 135 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + /** |
|
| 139 | + * @param null $member |
|
| 140 | + * @param array $context |
|
| 141 | + * @return bool|int |
|
| 142 | + */ |
|
| 143 | + public function canCreate($member = null, $context = []) |
|
| 144 | + { |
|
| 145 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 146 | + } |
|
| 147 | 147 | } |
@@ -63,7 +63,7 @@ |
||
| 63 | 63 | */ |
| 64 | 64 | public function getCMSFields() |
| 65 | 65 | { |
| 66 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 66 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 67 | 67 | $fields->removeByName([ |
| 68 | 68 | 'Locations', |
| 69 | 69 | 'LocationSet', |
@@ -28,256 +28,256 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class Location extends DataObject implements PermissionProvider |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private static $singular_name = 'Location'; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private static $plural_name = 'Locations'; |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private static $db = [ |
|
| 45 | - 'Title' => 'Varchar(255)', |
|
| 46 | - 'Featured' => 'Boolean', |
|
| 47 | - 'Website' => 'Varchar(255)', |
|
| 48 | - 'Phone' => 'Varchar(40)', |
|
| 49 | - 'Email' => 'Varchar(255)', |
|
| 50 | - 'Fax' => 'Varchar(45)', |
|
| 51 | - 'Import_ID' => 'Int', |
|
| 52 | - ]; |
|
| 53 | - |
|
| 54 | - private static $many_many = [ |
|
| 55 | - 'Categories' => LocationCategory::class, |
|
| 56 | - ]; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private static $table_name = 'Location'; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - private static $casting = [ |
|
| 67 | - 'distance' => 'Decimal(9,3)', |
|
| 68 | - ]; |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - private static $default_sort = 'Title'; |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * api access via Restful Server module |
|
| 77 | - * |
|
| 78 | - * @var bool |
|
| 79 | - */ |
|
| 80 | - private static $api_access = true; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * search fields for Model Admin |
|
| 84 | - * |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - private static $searchable_fields = [ |
|
| 88 | - 'Title', |
|
| 89 | - 'Address', |
|
| 90 | - 'City', |
|
| 91 | - 'State', |
|
| 92 | - 'PostalCode', |
|
| 93 | - 'Country', |
|
| 94 | - 'Website', |
|
| 95 | - 'Phone', |
|
| 96 | - 'Email', |
|
| 97 | - 'Featured', |
|
| 98 | - ]; |
|
| 99 | - |
|
| 100 | - /** |
|
| 101 | - * columns for grid field |
|
| 102 | - * |
|
| 103 | - * @var array |
|
| 104 | - */ |
|
| 105 | - private static $summary_fields = [ |
|
| 106 | - 'Title', |
|
| 107 | - 'Address', |
|
| 108 | - 'Address2', |
|
| 109 | - 'City', |
|
| 110 | - 'State', |
|
| 111 | - 'PostalCode', |
|
| 112 | - 'CountryCode', |
|
| 113 | - 'Phone' => 'Phone', |
|
| 114 | - 'Fax' => 'Fax', |
|
| 115 | - 'Email' => 'Email', |
|
| 116 | - 'Website' => 'Website', |
|
| 117 | - 'Featured', |
|
| 118 | - 'CategoryList', |
|
| 119 | - 'Lat', |
|
| 120 | - 'Lng', |
|
| 121 | - 'Import_ID', |
|
| 122 | - ]; |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Coords status for $summary_fields |
|
| 126 | - * |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getCoords() |
|
| 130 | - { |
|
| 131 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function getCategoryList() |
|
| 138 | - { |
|
| 139 | - if ($this->Categories()->count()) { |
|
| 140 | - return implode(', ', $this->Categories()->column('Name')); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - return ''; |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - /** |
|
| 147 | - * @return bool|string |
|
| 148 | - */ |
|
| 149 | - public function getCountryCode() |
|
| 150 | - { |
|
| 151 | - if ($this->Country) { |
|
| 152 | - return strtoupper($this->Country); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return false; |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * custom labels for fields |
|
| 160 | - * |
|
| 161 | - * @param bool $includerelations |
|
| 162 | - * @return array|string |
|
| 163 | - */ |
|
| 164 | - public function fieldLabels($includerelations = true) |
|
| 165 | - { |
|
| 166 | - $labels = parent::fieldLabels($includerelations); |
|
| 167 | - $labels['Title'] = 'Name'; |
|
| 168 | - $labels['Address2'] = 'Address 2'; |
|
| 169 | - $labels['PostalCode'] = 'Postal Code'; |
|
| 170 | - $labels['Categories.Name'] = 'Categories'; |
|
| 171 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 172 | - |
|
| 173 | - return $labels; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @return FieldList |
|
| 178 | - */ |
|
| 179 | - public function getCMSFields() |
|
| 180 | - { |
|
| 181 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 182 | - $fields->removeByName([ |
|
| 183 | - 'Import_ID', |
|
| 184 | - 'LinkTracking', |
|
| 185 | - 'FileTracking', |
|
| 186 | - ]); |
|
| 187 | - |
|
| 188 | - $fields->dataFieldByName('Website') |
|
| 189 | - ->setAttribute('placeholder', 'http://'); |
|
| 190 | - |
|
| 191 | - $fields->replaceField('Email', EmailField::create('Email')); |
|
| 192 | - |
|
| 193 | - $featured = $fields->dataFieldByName('Featured') |
|
| 194 | - ->setDescription('Location will display near the top of the results list'); |
|
| 195 | - $fields->insertAfter( |
|
| 196 | - 'Fax', |
|
| 197 | - $featured |
|
| 198 | - ); |
|
| 199 | - |
|
| 200 | - if ($this->ID) { |
|
| 201 | - $categories = $fields->dataFieldByName('Categories'); |
|
| 202 | - $config = $categories->getConfig(); |
|
| 203 | - $config->removeComponentsByType([ |
|
| 204 | - GridFieldAddExistingAutocompleter::class, |
|
| 205 | - ]) |
|
| 206 | - ->addComponents([ |
|
| 207 | - new GridFieldAddExistingSearchButton(), |
|
| 208 | - ]); |
|
| 209 | - } |
|
| 210 | - }); |
|
| 211 | - |
|
| 212 | - $fields = parent::getCMSFields(); |
|
| 213 | - |
|
| 214 | - // allow to be extended via DataExtension |
|
| 215 | - $this->extend('updateLocationFields', $fields); |
|
| 216 | - |
|
| 217 | - return $fields; |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - /** |
|
| 221 | - * @param null $member |
|
| 222 | - * @param array $context |
|
| 223 | - * @return bool |
|
| 224 | - */ |
|
| 225 | - public function canView($member = null, $context = []) |
|
| 226 | - { |
|
| 227 | - return true; |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - /** |
|
| 231 | - * @param null $member |
|
| 232 | - * @param array $context |
|
| 233 | - * @return bool|int |
|
| 234 | - */ |
|
| 235 | - public function canEdit($member = null, $context = []) |
|
| 236 | - { |
|
| 237 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - /** |
|
| 241 | - * @param null $member |
|
| 242 | - * @param array $context |
|
| 243 | - * @return bool|int |
|
| 244 | - */ |
|
| 245 | - public function canDelete($member = null, $context = []) |
|
| 246 | - { |
|
| 247 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - /** |
|
| 251 | - * @param null $member |
|
| 252 | - * @param array $context |
|
| 253 | - * @return bool|int |
|
| 254 | - */ |
|
| 255 | - public function canCreate($member = null, $context = []) |
|
| 256 | - { |
|
| 257 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - /** |
|
| 261 | - * @return array |
|
| 262 | - */ |
|
| 263 | - public function providePermissions() |
|
| 264 | - { |
|
| 265 | - return [ |
|
| 266 | - 'Location_EDIT' => 'Edit a Location', |
|
| 267 | - 'Location_DELETE' => 'Delete a Location', |
|
| 268 | - 'Location_CREATE' => 'Create a Location', |
|
| 269 | - ]; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - /** |
|
| 273 | - * @return string |
|
| 274 | - */ |
|
| 275 | - public function getWebsiteURL() |
|
| 276 | - { |
|
| 277 | - $url = $this->Website; |
|
| 278 | - |
|
| 279 | - $this->extend('updateWebsiteURL', $url); |
|
| 280 | - |
|
| 281 | - return $url; |
|
| 282 | - } |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private static $singular_name = 'Location'; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private static $plural_name = 'Locations'; |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private static $db = [ |
|
| 45 | + 'Title' => 'Varchar(255)', |
|
| 46 | + 'Featured' => 'Boolean', |
|
| 47 | + 'Website' => 'Varchar(255)', |
|
| 48 | + 'Phone' => 'Varchar(40)', |
|
| 49 | + 'Email' => 'Varchar(255)', |
|
| 50 | + 'Fax' => 'Varchar(45)', |
|
| 51 | + 'Import_ID' => 'Int', |
|
| 52 | + ]; |
|
| 53 | + |
|
| 54 | + private static $many_many = [ |
|
| 55 | + 'Categories' => LocationCategory::class, |
|
| 56 | + ]; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private static $table_name = 'Location'; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + private static $casting = [ |
|
| 67 | + 'distance' => 'Decimal(9,3)', |
|
| 68 | + ]; |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + private static $default_sort = 'Title'; |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * api access via Restful Server module |
|
| 77 | + * |
|
| 78 | + * @var bool |
|
| 79 | + */ |
|
| 80 | + private static $api_access = true; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * search fields for Model Admin |
|
| 84 | + * |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + private static $searchable_fields = [ |
|
| 88 | + 'Title', |
|
| 89 | + 'Address', |
|
| 90 | + 'City', |
|
| 91 | + 'State', |
|
| 92 | + 'PostalCode', |
|
| 93 | + 'Country', |
|
| 94 | + 'Website', |
|
| 95 | + 'Phone', |
|
| 96 | + 'Email', |
|
| 97 | + 'Featured', |
|
| 98 | + ]; |
|
| 99 | + |
|
| 100 | + /** |
|
| 101 | + * columns for grid field |
|
| 102 | + * |
|
| 103 | + * @var array |
|
| 104 | + */ |
|
| 105 | + private static $summary_fields = [ |
|
| 106 | + 'Title', |
|
| 107 | + 'Address', |
|
| 108 | + 'Address2', |
|
| 109 | + 'City', |
|
| 110 | + 'State', |
|
| 111 | + 'PostalCode', |
|
| 112 | + 'CountryCode', |
|
| 113 | + 'Phone' => 'Phone', |
|
| 114 | + 'Fax' => 'Fax', |
|
| 115 | + 'Email' => 'Email', |
|
| 116 | + 'Website' => 'Website', |
|
| 117 | + 'Featured', |
|
| 118 | + 'CategoryList', |
|
| 119 | + 'Lat', |
|
| 120 | + 'Lng', |
|
| 121 | + 'Import_ID', |
|
| 122 | + ]; |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Coords status for $summary_fields |
|
| 126 | + * |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getCoords() |
|
| 130 | + { |
|
| 131 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function getCategoryList() |
|
| 138 | + { |
|
| 139 | + if ($this->Categories()->count()) { |
|
| 140 | + return implode(', ', $this->Categories()->column('Name')); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + return ''; |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + /** |
|
| 147 | + * @return bool|string |
|
| 148 | + */ |
|
| 149 | + public function getCountryCode() |
|
| 150 | + { |
|
| 151 | + if ($this->Country) { |
|
| 152 | + return strtoupper($this->Country); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return false; |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * custom labels for fields |
|
| 160 | + * |
|
| 161 | + * @param bool $includerelations |
|
| 162 | + * @return array|string |
|
| 163 | + */ |
|
| 164 | + public function fieldLabels($includerelations = true) |
|
| 165 | + { |
|
| 166 | + $labels = parent::fieldLabels($includerelations); |
|
| 167 | + $labels['Title'] = 'Name'; |
|
| 168 | + $labels['Address2'] = 'Address 2'; |
|
| 169 | + $labels['PostalCode'] = 'Postal Code'; |
|
| 170 | + $labels['Categories.Name'] = 'Categories'; |
|
| 171 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 172 | + |
|
| 173 | + return $labels; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @return FieldList |
|
| 178 | + */ |
|
| 179 | + public function getCMSFields() |
|
| 180 | + { |
|
| 181 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 182 | + $fields->removeByName([ |
|
| 183 | + 'Import_ID', |
|
| 184 | + 'LinkTracking', |
|
| 185 | + 'FileTracking', |
|
| 186 | + ]); |
|
| 187 | + |
|
| 188 | + $fields->dataFieldByName('Website') |
|
| 189 | + ->setAttribute('placeholder', 'http://'); |
|
| 190 | + |
|
| 191 | + $fields->replaceField('Email', EmailField::create('Email')); |
|
| 192 | + |
|
| 193 | + $featured = $fields->dataFieldByName('Featured') |
|
| 194 | + ->setDescription('Location will display near the top of the results list'); |
|
| 195 | + $fields->insertAfter( |
|
| 196 | + 'Fax', |
|
| 197 | + $featured |
|
| 198 | + ); |
|
| 199 | + |
|
| 200 | + if ($this->ID) { |
|
| 201 | + $categories = $fields->dataFieldByName('Categories'); |
|
| 202 | + $config = $categories->getConfig(); |
|
| 203 | + $config->removeComponentsByType([ |
|
| 204 | + GridFieldAddExistingAutocompleter::class, |
|
| 205 | + ]) |
|
| 206 | + ->addComponents([ |
|
| 207 | + new GridFieldAddExistingSearchButton(), |
|
| 208 | + ]); |
|
| 209 | + } |
|
| 210 | + }); |
|
| 211 | + |
|
| 212 | + $fields = parent::getCMSFields(); |
|
| 213 | + |
|
| 214 | + // allow to be extended via DataExtension |
|
| 215 | + $this->extend('updateLocationFields', $fields); |
|
| 216 | + |
|
| 217 | + return $fields; |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + /** |
|
| 221 | + * @param null $member |
|
| 222 | + * @param array $context |
|
| 223 | + * @return bool |
|
| 224 | + */ |
|
| 225 | + public function canView($member = null, $context = []) |
|
| 226 | + { |
|
| 227 | + return true; |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + /** |
|
| 231 | + * @param null $member |
|
| 232 | + * @param array $context |
|
| 233 | + * @return bool|int |
|
| 234 | + */ |
|
| 235 | + public function canEdit($member = null, $context = []) |
|
| 236 | + { |
|
| 237 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + /** |
|
| 241 | + * @param null $member |
|
| 242 | + * @param array $context |
|
| 243 | + * @return bool|int |
|
| 244 | + */ |
|
| 245 | + public function canDelete($member = null, $context = []) |
|
| 246 | + { |
|
| 247 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + /** |
|
| 251 | + * @param null $member |
|
| 252 | + * @param array $context |
|
| 253 | + * @return bool|int |
|
| 254 | + */ |
|
| 255 | + public function canCreate($member = null, $context = []) |
|
| 256 | + { |
|
| 257 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + /** |
|
| 261 | + * @return array |
|
| 262 | + */ |
|
| 263 | + public function providePermissions() |
|
| 264 | + { |
|
| 265 | + return [ |
|
| 266 | + 'Location_EDIT' => 'Edit a Location', |
|
| 267 | + 'Location_DELETE' => 'Delete a Location', |
|
| 268 | + 'Location_CREATE' => 'Create a Location', |
|
| 269 | + ]; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + /** |
|
| 273 | + * @return string |
|
| 274 | + */ |
|
| 275 | + public function getWebsiteURL() |
|
| 276 | + { |
|
| 277 | + $url = $this->Website; |
|
| 278 | + |
|
| 279 | + $this->extend('updateWebsiteURL', $url); |
|
| 280 | + |
|
| 281 | + return $url; |
|
| 282 | + } |
|
| 283 | 283 | } |
@@ -178,7 +178,7 @@ |
||
| 178 | 178 | */ |
| 179 | 179 | public function getCMSFields() |
| 180 | 180 | { |
| 181 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 181 | + $this->beforeUpdateCMSFields(function($fields) { |
|
| 182 | 182 | $fields->removeByName([ |
| 183 | 183 | 'Import_ID', |
| 184 | 184 | 'LinkTracking', |