@@ -28,254 +28,254 @@ |
||
| 28 | 28 | */ |
| 29 | 29 | class Location extends DataObject implements PermissionProvider |
| 30 | 30 | { |
| 31 | - /** |
|
| 32 | - * @var string |
|
| 33 | - */ |
|
| 34 | - private static $singular_name = 'Location'; |
|
| 31 | + /** |
|
| 32 | + * @var string |
|
| 33 | + */ |
|
| 34 | + private static $singular_name = 'Location'; |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * @var string |
|
| 38 | - */ |
|
| 39 | - private static $plural_name = 'Locations'; |
|
| 36 | + /** |
|
| 37 | + * @var string |
|
| 38 | + */ |
|
| 39 | + private static $plural_name = 'Locations'; |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * @var array |
|
| 43 | - */ |
|
| 44 | - private static $db = array( |
|
| 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 | - ); |
|
| 41 | + /** |
|
| 42 | + * @var array |
|
| 43 | + */ |
|
| 44 | + private static $db = array( |
|
| 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 | 53 | |
| 54 | - private static $many_many = [ |
|
| 55 | - 'Categories' => LocationCategory::class, |
|
| 56 | - ]; |
|
| 54 | + private static $many_many = [ |
|
| 55 | + 'Categories' => LocationCategory::class, |
|
| 56 | + ]; |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * @var string |
|
| 60 | - */ |
|
| 61 | - private static $table_name = 'Location'; |
|
| 58 | + /** |
|
| 59 | + * @var string |
|
| 60 | + */ |
|
| 61 | + private static $table_name = 'Location'; |
|
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * @var array |
|
| 65 | - */ |
|
| 66 | - private static $casting = array( |
|
| 67 | - 'distance' => 'Decimal(9,3)', |
|
| 68 | - ); |
|
| 63 | + /** |
|
| 64 | + * @var array |
|
| 65 | + */ |
|
| 66 | + private static $casting = array( |
|
| 67 | + 'distance' => 'Decimal(9,3)', |
|
| 68 | + ); |
|
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * @var string |
|
| 72 | - */ |
|
| 73 | - private static $default_sort = 'Title'; |
|
| 70 | + /** |
|
| 71 | + * @var string |
|
| 72 | + */ |
|
| 73 | + private static $default_sort = 'Title'; |
|
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * api access via Restful Server module |
|
| 77 | - * |
|
| 78 | - * @var bool |
|
| 79 | - */ |
|
| 80 | - private static $api_access = true; |
|
| 75 | + /** |
|
| 76 | + * api access via Restful Server module |
|
| 77 | + * |
|
| 78 | + * @var bool |
|
| 79 | + */ |
|
| 80 | + private static $api_access = true; |
|
| 81 | 81 | |
| 82 | - /** |
|
| 83 | - * search fields for Model Admin |
|
| 84 | - * |
|
| 85 | - * @var array |
|
| 86 | - */ |
|
| 87 | - private static $searchable_fields = array( |
|
| 88 | - 'Title', |
|
| 89 | - 'Address', |
|
| 90 | - 'City', |
|
| 91 | - 'State', |
|
| 92 | - 'PostalCode', |
|
| 93 | - 'Country', |
|
| 94 | - 'Website', |
|
| 95 | - 'Phone', |
|
| 96 | - 'Email', |
|
| 97 | - 'Featured', |
|
| 98 | - ); |
|
| 82 | + /** |
|
| 83 | + * search fields for Model Admin |
|
| 84 | + * |
|
| 85 | + * @var array |
|
| 86 | + */ |
|
| 87 | + private static $searchable_fields = array( |
|
| 88 | + 'Title', |
|
| 89 | + 'Address', |
|
| 90 | + 'City', |
|
| 91 | + 'State', |
|
| 92 | + 'PostalCode', |
|
| 93 | + 'Country', |
|
| 94 | + 'Website', |
|
| 95 | + 'Phone', |
|
| 96 | + 'Email', |
|
| 97 | + 'Featured', |
|
| 98 | + ); |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * columns for grid field |
|
| 102 | - * |
|
| 103 | - * @var array |
|
| 104 | - */ |
|
| 105 | - private static $summary_fields = array( |
|
| 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 | - ); |
|
| 100 | + /** |
|
| 101 | + * columns for grid field |
|
| 102 | + * |
|
| 103 | + * @var array |
|
| 104 | + */ |
|
| 105 | + private static $summary_fields = array( |
|
| 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 | 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 | - } |
|
| 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 | 133 | |
| 134 | - /** |
|
| 135 | - * @return string |
|
| 136 | - */ |
|
| 137 | - public function getCategoryList() |
|
| 138 | - { |
|
| 139 | - if ($this->Categories()->count()) { |
|
| 140 | - return implode(', ', $this->Categories()->column('Name')); |
|
| 141 | - } |
|
| 134 | + /** |
|
| 135 | + * @return string |
|
| 136 | + */ |
|
| 137 | + public function getCategoryList() |
|
| 138 | + { |
|
| 139 | + if ($this->Categories()->count()) { |
|
| 140 | + return implode(', ', $this->Categories()->column('Name')); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - return ''; |
|
| 144 | - } |
|
| 143 | + return ''; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | - /** |
|
| 147 | - * @return mixed |
|
| 148 | - */ |
|
| 149 | - public function getWebsite() |
|
| 150 | - { |
|
| 151 | - $website = $this->getField('Website'); |
|
| 152 | - if ($website && strpos($website, '//') === false && strpos($website, '.') >= 0) { |
|
| 153 | - return '//' . $website; |
|
| 154 | - } |
|
| 155 | - return $website; |
|
| 156 | - } |
|
| 146 | + /** |
|
| 147 | + * @return mixed |
|
| 148 | + */ |
|
| 149 | + public function getWebsite() |
|
| 150 | + { |
|
| 151 | + $website = $this->getField('Website'); |
|
| 152 | + if ($website && strpos($website, '//') === false && strpos($website, '.') >= 0) { |
|
| 153 | + return '//' . $website; |
|
| 154 | + } |
|
| 155 | + return $website; |
|
| 156 | + } |
|
| 157 | 157 | |
| 158 | - /** |
|
| 159 | - * @return bool|string |
|
| 160 | - */ |
|
| 161 | - public function getCountryCode() |
|
| 162 | - { |
|
| 163 | - if ($this->Country) { |
|
| 164 | - return strtoupper($this->Country); |
|
| 165 | - } |
|
| 166 | - return false; |
|
| 167 | - } |
|
| 158 | + /** |
|
| 159 | + * @return bool|string |
|
| 160 | + */ |
|
| 161 | + public function getCountryCode() |
|
| 162 | + { |
|
| 163 | + if ($this->Country) { |
|
| 164 | + return strtoupper($this->Country); |
|
| 165 | + } |
|
| 166 | + return false; |
|
| 167 | + } |
|
| 168 | 168 | |
| 169 | - /** |
|
| 170 | - * custom labels for fields |
|
| 171 | - * |
|
| 172 | - * @param bool $includerelations |
|
| 173 | - * @return array|string |
|
| 174 | - */ |
|
| 175 | - public function fieldLabels($includerelations = true) |
|
| 176 | - { |
|
| 177 | - $labels = parent::fieldLabels($includerelations); |
|
| 178 | - $labels['Title'] = 'Name'; |
|
| 179 | - $labels['Address2'] = 'Address 2'; |
|
| 180 | - $labels['PostalCode'] = 'Postal Code'; |
|
| 181 | - $labels['Categories.Name'] = 'Categories'; |
|
| 182 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 183 | - return $labels; |
|
| 184 | - } |
|
| 169 | + /** |
|
| 170 | + * custom labels for fields |
|
| 171 | + * |
|
| 172 | + * @param bool $includerelations |
|
| 173 | + * @return array|string |
|
| 174 | + */ |
|
| 175 | + public function fieldLabels($includerelations = true) |
|
| 176 | + { |
|
| 177 | + $labels = parent::fieldLabels($includerelations); |
|
| 178 | + $labels['Title'] = 'Name'; |
|
| 179 | + $labels['Address2'] = 'Address 2'; |
|
| 180 | + $labels['PostalCode'] = 'Postal Code'; |
|
| 181 | + $labels['Categories.Name'] = 'Categories'; |
|
| 182 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
| 183 | + return $labels; |
|
| 184 | + } |
|
| 185 | 185 | |
| 186 | - /** |
|
| 187 | - * @return FieldList |
|
| 188 | - */ |
|
| 189 | - public function getCMSFields() |
|
| 190 | - { |
|
| 191 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 192 | - $fields->removeByName(array( |
|
| 193 | - 'Import_ID', |
|
| 194 | - 'LinkTracking', |
|
| 195 | - 'FileTracking', |
|
| 196 | - )); |
|
| 186 | + /** |
|
| 187 | + * @return FieldList |
|
| 188 | + */ |
|
| 189 | + public function getCMSFields() |
|
| 190 | + { |
|
| 191 | + $this->beforeUpdateCMSFields(function ($fields) { |
|
| 192 | + $fields->removeByName(array( |
|
| 193 | + 'Import_ID', |
|
| 194 | + 'LinkTracking', |
|
| 195 | + 'FileTracking', |
|
| 196 | + )); |
|
| 197 | 197 | |
| 198 | - $fields->dataFieldByName('Website') |
|
| 199 | - ->setAttribute('placeholder', 'http://'); |
|
| 198 | + $fields->dataFieldByName('Website') |
|
| 199 | + ->setAttribute('placeholder', 'http://'); |
|
| 200 | 200 | |
| 201 | - $fields->replaceField('Email', EmailField::create('Email')); |
|
| 201 | + $fields->replaceField('Email', EmailField::create('Email')); |
|
| 202 | 202 | |
| 203 | - $featured = $fields->dataFieldByName('Featured') |
|
| 204 | - ->setDescription('Location will display near the top of the results list'); |
|
| 205 | - $fields->insertAfter( |
|
| 206 | - 'Fax', |
|
| 207 | - $featured |
|
| 208 | - ); |
|
| 203 | + $featured = $fields->dataFieldByName('Featured') |
|
| 204 | + ->setDescription('Location will display near the top of the results list'); |
|
| 205 | + $fields->insertAfter( |
|
| 206 | + 'Fax', |
|
| 207 | + $featured |
|
| 208 | + ); |
|
| 209 | 209 | |
| 210 | - if ($this->ID) { |
|
| 211 | - $categories = $fields->dataFieldByName('Categories'); |
|
| 212 | - $config = $categories->getConfig(); |
|
| 213 | - $config->removeComponentsByType([ |
|
| 214 | - GridFieldAddExistingAutocompleter::class |
|
| 215 | - ]) |
|
| 216 | - ->addComponents([ |
|
| 217 | - new GridFieldAddExistingSearchButton() |
|
| 218 | - ]); |
|
| 219 | - } |
|
| 220 | - }); |
|
| 210 | + if ($this->ID) { |
|
| 211 | + $categories = $fields->dataFieldByName('Categories'); |
|
| 212 | + $config = $categories->getConfig(); |
|
| 213 | + $config->removeComponentsByType([ |
|
| 214 | + GridFieldAddExistingAutocompleter::class |
|
| 215 | + ]) |
|
| 216 | + ->addComponents([ |
|
| 217 | + new GridFieldAddExistingSearchButton() |
|
| 218 | + ]); |
|
| 219 | + } |
|
| 220 | + }); |
|
| 221 | 221 | |
| 222 | - $fields = parent::getCMSFields(); |
|
| 222 | + $fields = parent::getCMSFields(); |
|
| 223 | 223 | |
| 224 | - // allow to be extended via DataExtension |
|
| 225 | - $this->extend('updateLocationFields', $fields); |
|
| 224 | + // allow to be extended via DataExtension |
|
| 225 | + $this->extend('updateLocationFields', $fields); |
|
| 226 | 226 | |
| 227 | - return $fields; |
|
| 228 | - } |
|
| 227 | + return $fields; |
|
| 228 | + } |
|
| 229 | 229 | |
| 230 | - /** |
|
| 231 | - * @param null $member |
|
| 232 | - * @param array $context |
|
| 233 | - * @return bool |
|
| 234 | - */ |
|
| 235 | - public function canView($member = null, $context = []) |
|
| 236 | - { |
|
| 237 | - return true; |
|
| 238 | - } |
|
| 230 | + /** |
|
| 231 | + * @param null $member |
|
| 232 | + * @param array $context |
|
| 233 | + * @return bool |
|
| 234 | + */ |
|
| 235 | + public function canView($member = null, $context = []) |
|
| 236 | + { |
|
| 237 | + return true; |
|
| 238 | + } |
|
| 239 | 239 | |
| 240 | - /** |
|
| 241 | - * @param null $member |
|
| 242 | - * @param array $context |
|
| 243 | - * @return bool|int |
|
| 244 | - */ |
|
| 245 | - public function canEdit($member = null, $context = []) |
|
| 246 | - { |
|
| 247 | - return Permission::check('Location_EDIT', 'any', $member); |
|
| 248 | - } |
|
| 240 | + /** |
|
| 241 | + * @param null $member |
|
| 242 | + * @param array $context |
|
| 243 | + * @return bool|int |
|
| 244 | + */ |
|
| 245 | + public function canEdit($member = null, $context = []) |
|
| 246 | + { |
|
| 247 | + return Permission::check('Location_EDIT', 'any', $member); |
|
| 248 | + } |
|
| 249 | 249 | |
| 250 | - /** |
|
| 251 | - * @param null $member |
|
| 252 | - * @param array $context |
|
| 253 | - * @return bool|int |
|
| 254 | - */ |
|
| 255 | - public function canDelete($member = null, $context = []) |
|
| 256 | - { |
|
| 257 | - return Permission::check('Location_DELETE', 'any', $member); |
|
| 258 | - } |
|
| 250 | + /** |
|
| 251 | + * @param null $member |
|
| 252 | + * @param array $context |
|
| 253 | + * @return bool|int |
|
| 254 | + */ |
|
| 255 | + public function canDelete($member = null, $context = []) |
|
| 256 | + { |
|
| 257 | + return Permission::check('Location_DELETE', 'any', $member); |
|
| 258 | + } |
|
| 259 | 259 | |
| 260 | - /** |
|
| 261 | - * @param null $member |
|
| 262 | - * @param array $context |
|
| 263 | - * @return bool|int |
|
| 264 | - */ |
|
| 265 | - public function canCreate($member = null, $context = []) |
|
| 266 | - { |
|
| 267 | - return Permission::check('Location_CREATE', 'any', $member); |
|
| 268 | - } |
|
| 260 | + /** |
|
| 261 | + * @param null $member |
|
| 262 | + * @param array $context |
|
| 263 | + * @return bool|int |
|
| 264 | + */ |
|
| 265 | + public function canCreate($member = null, $context = []) |
|
| 266 | + { |
|
| 267 | + return Permission::check('Location_CREATE', 'any', $member); |
|
| 268 | + } |
|
| 269 | 269 | |
| 270 | - /** |
|
| 271 | - * @return array |
|
| 272 | - */ |
|
| 273 | - public function providePermissions() |
|
| 274 | - { |
|
| 275 | - return array( |
|
| 276 | - 'Location_EDIT' => 'Edit a Location', |
|
| 277 | - 'Location_DELETE' => 'Delete a Location', |
|
| 278 | - 'Location_CREATE' => 'Create a Location', |
|
| 279 | - ); |
|
| 280 | - } |
|
| 270 | + /** |
|
| 271 | + * @return array |
|
| 272 | + */ |
|
| 273 | + public function providePermissions() |
|
| 274 | + { |
|
| 275 | + return array( |
|
| 276 | + 'Location_EDIT' => 'Edit a Location', |
|
| 277 | + 'Location_DELETE' => 'Delete a Location', |
|
| 278 | + 'Location_CREATE' => 'Create a Location', |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | 281 | } |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $website = $this->getField('Website'); |
| 152 | 152 | if ($website && strpos($website, '//') === false && strpos($website, '.') >= 0) { |
| 153 | - return '//' . $website; |
|
| 153 | + return '//'.$website; |
|
| 154 | 154 | } |
| 155 | 155 | return $website; |
| 156 | 156 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | public function getCMSFields() |
| 190 | 190 | { |
| 191 | - $this->beforeUpdateCMSFields(function ($fields) { |
|
| 191 | + $this->beforeUpdateCMSFields(function($fields) { |
|
| 192 | 192 | $fields->removeByName(array( |
| 193 | 193 | 'Import_ID', |
| 194 | 194 | 'LinkTracking', |