@@ -12,80 +12,80 @@ |
||
12 | 12 | class LocationAdmin extends ModelAdmin |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - private static $managed_models = array( |
|
19 | - Location::class, |
|
20 | - LocationCategory::class, |
|
21 | - ); |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + private static $managed_models = array( |
|
19 | + Location::class, |
|
20 | + LocationCategory::class, |
|
21 | + ); |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var array |
|
25 | - */ |
|
26 | - private static $model_importers = array( |
|
27 | - Location::class => LocationCsvBulkLoader::class, |
|
28 | - LocationCategory::class => CsvBulkLoader::class, |
|
29 | - ); |
|
23 | + /** |
|
24 | + * @var array |
|
25 | + */ |
|
26 | + private static $model_importers = array( |
|
27 | + Location::class => LocationCsvBulkLoader::class, |
|
28 | + LocationCategory::class => CsvBulkLoader::class, |
|
29 | + ); |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var string |
|
33 | - */ |
|
34 | - private static $menu_title = 'Locator'; |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private static $url_segment = 'locator'; |
|
31 | + /** |
|
32 | + * @var string |
|
33 | + */ |
|
34 | + private static $menu_title = 'Locator'; |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private static $url_segment = 'locator'; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @return array |
|
42 | - */ |
|
43 | - public function getExportFields() |
|
44 | - { |
|
45 | - if ($this->modelClass == Location::class) { |
|
46 | - $fields = [ |
|
47 | - 'Title' => 'Name', |
|
48 | - 'Address' => 'Address', |
|
49 | - 'Address2' => 'Address2', |
|
50 | - 'City' => 'City', |
|
51 | - 'State' => 'State', |
|
52 | - 'PostalCode' => 'PostalCode', |
|
53 | - 'CountryCode' => 'Country', |
|
54 | - 'Phone' => 'Phone', |
|
55 | - 'Fax' => 'Fax', |
|
56 | - 'Email' => 'Email', |
|
57 | - 'Website' => 'Website', |
|
58 | - 'Featured' => 'Featured', |
|
59 | - 'CategoryList' => 'Categories', |
|
60 | - 'Lat' => 'Lat', |
|
61 | - 'Lng' => 'Lng', |
|
62 | - 'Import_ID' => 'Import_ID', |
|
63 | - ]; |
|
64 | - } |
|
40 | + /** |
|
41 | + * @return array |
|
42 | + */ |
|
43 | + public function getExportFields() |
|
44 | + { |
|
45 | + if ($this->modelClass == Location::class) { |
|
46 | + $fields = [ |
|
47 | + 'Title' => 'Name', |
|
48 | + 'Address' => 'Address', |
|
49 | + 'Address2' => 'Address2', |
|
50 | + 'City' => 'City', |
|
51 | + 'State' => 'State', |
|
52 | + 'PostalCode' => 'PostalCode', |
|
53 | + 'CountryCode' => 'Country', |
|
54 | + 'Phone' => 'Phone', |
|
55 | + 'Fax' => 'Fax', |
|
56 | + 'Email' => 'Email', |
|
57 | + 'Website' => 'Website', |
|
58 | + 'Featured' => 'Featured', |
|
59 | + 'CategoryList' => 'Categories', |
|
60 | + 'Lat' => 'Lat', |
|
61 | + 'Lng' => 'Lng', |
|
62 | + 'Import_ID' => 'Import_ID', |
|
63 | + ]; |
|
64 | + } |
|
65 | 65 | |
66 | - if (!isset($fields)) { |
|
67 | - $fields = parent::getExportFields(); |
|
68 | - } |
|
66 | + if (!isset($fields)) { |
|
67 | + $fields = parent::getExportFields(); |
|
68 | + } |
|
69 | 69 | |
70 | - $this->extend('updateGetExportFields', $fields); |
|
70 | + $this->extend('updateGetExportFields', $fields); |
|
71 | 71 | |
72 | - return $fields; |
|
73 | - } |
|
72 | + return $fields; |
|
73 | + } |
|
74 | 74 | |
75 | - /** |
|
76 | - * @param null $id |
|
77 | - * @param null $fields |
|
78 | - * @return $this|Form |
|
79 | - */ |
|
80 | - public function getEditForm($id = null, $fields = null) |
|
81 | - { |
|
82 | - $form = parent::getEditForm($id, $fields); |
|
83 | - $class = $this->sanitiseClassName($this->modelClass); |
|
84 | - if ($class == Location::class) { |
|
85 | - $gridField = $form->Fields()->fieldByName($class); |
|
86 | - $config = $gridField->getConfig(); |
|
87 | - $config->removeComponentsByType('GridFieldDeleteAction'); |
|
88 | - } |
|
89 | - return $form; |
|
90 | - } |
|
75 | + /** |
|
76 | + * @param null $id |
|
77 | + * @param null $fields |
|
78 | + * @return $this|Form |
|
79 | + */ |
|
80 | + public function getEditForm($id = null, $fields = null) |
|
81 | + { |
|
82 | + $form = parent::getEditForm($id, $fields); |
|
83 | + $class = $this->sanitiseClassName($this->modelClass); |
|
84 | + if ($class == Location::class) { |
|
85 | + $gridField = $form->Fields()->fieldByName($class); |
|
86 | + $config = $gridField->getConfig(); |
|
87 | + $config->removeComponentsByType('GridFieldDeleteAction'); |
|
88 | + } |
|
89 | + return $form; |
|
90 | + } |
|
91 | 91 | } |
@@ -13,89 +13,89 @@ |
||
13 | 13 | class LocationCsvBulkLoader extends CsvBulkLoader |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - public $columnMap = array( |
|
20 | - 'Name' => 'Title', |
|
21 | - 'EmailAddress' => 'Email', |
|
22 | - 'Categories' => '->getCategoryByName', |
|
23 | - 'Import_ID' => 'Import_ID', |
|
24 | - 'Country' => '->getCountryByName', |
|
25 | - ); |
|
16 | + /** |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + public $columnMap = array( |
|
20 | + 'Name' => 'Title', |
|
21 | + 'EmailAddress' => 'Email', |
|
22 | + 'Categories' => '->getCategoryByName', |
|
23 | + 'Import_ID' => 'Import_ID', |
|
24 | + 'Country' => '->getCountryByName', |
|
25 | + ); |
|
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - public $duplicateChecks = array( |
|
31 | - 'Import_ID' => 'Import_ID' |
|
32 | - ); |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + public $duplicateChecks = array( |
|
31 | + 'Import_ID' => 'Import_ID' |
|
32 | + ); |
|
33 | 33 | |
34 | - /** |
|
35 | - * @param $val |
|
36 | - * @return string|string[]|null |
|
37 | - */ |
|
38 | - public function getEscape($val) |
|
39 | - { |
|
40 | - return preg_replace("/\r|\n/", "", $val); |
|
41 | - } |
|
34 | + /** |
|
35 | + * @param $val |
|
36 | + * @return string|string[]|null |
|
37 | + */ |
|
38 | + public function getEscape($val) |
|
39 | + { |
|
40 | + return preg_replace("/\r|\n/", "", $val); |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param $obj |
|
45 | - * @param $val |
|
46 | - * @param $record |
|
47 | - * @throws \SilverStripe\ORM\ValidationException |
|
48 | - */ |
|
49 | - public static function getCategoryByName(&$obj, $val, $record) |
|
50 | - { |
|
51 | - $val = Convert::raw2sql($val); |
|
52 | - $parts = explode(', ', $val); |
|
43 | + /** |
|
44 | + * @param $obj |
|
45 | + * @param $val |
|
46 | + * @param $record |
|
47 | + * @throws \SilverStripe\ORM\ValidationException |
|
48 | + */ |
|
49 | + public static function getCategoryByName(&$obj, $val, $record) |
|
50 | + { |
|
51 | + $val = Convert::raw2sql($val); |
|
52 | + $parts = explode(', ', $val); |
|
53 | 53 | |
54 | - foreach ($parts as $part) { |
|
55 | - $category = LocationCategory::get()->filter(array('Name' => $part))->first(); |
|
56 | - if (!$category) { |
|
57 | - $category = LocationCategory::create(); |
|
58 | - $category->Name = $part; |
|
59 | - $category->write(); |
|
60 | - } |
|
61 | - $obj->Categories()->add($category); |
|
62 | - } |
|
63 | - } |
|
54 | + foreach ($parts as $part) { |
|
55 | + $category = LocationCategory::get()->filter(array('Name' => $part))->first(); |
|
56 | + if (!$category) { |
|
57 | + $category = LocationCategory::create(); |
|
58 | + $category->Name = $part; |
|
59 | + $category->write(); |
|
60 | + } |
|
61 | + $obj->Categories()->add($category); |
|
62 | + } |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @param $obj |
|
67 | - * @param $val |
|
68 | - * @param $record |
|
69 | - */ |
|
70 | - public function getCountryByName(&$obj, $val, $record) |
|
71 | - { |
|
72 | - $val = $this->getEscape($val); |
|
73 | - $countries = IntlLocales::singleton()->getCountries(); |
|
65 | + /** |
|
66 | + * @param $obj |
|
67 | + * @param $val |
|
68 | + * @param $record |
|
69 | + */ |
|
70 | + public function getCountryByName(&$obj, $val, $record) |
|
71 | + { |
|
72 | + $val = $this->getEscape($val); |
|
73 | + $countries = IntlLocales::singleton()->getCountries(); |
|
74 | 74 | |
75 | - if (strlen((string)$val) == 2) { |
|
76 | - $val = strtolower($val); |
|
77 | - if (array_key_exists($val, $countries)) { |
|
78 | - $obj->Country = $val; |
|
79 | - } |
|
80 | - } |
|
75 | + if (strlen((string)$val) == 2) { |
|
76 | + $val = strtolower($val); |
|
77 | + if (array_key_exists($val, $countries)) { |
|
78 | + $obj->Country = $val; |
|
79 | + } |
|
80 | + } |
|
81 | 81 | |
82 | - if (in_array($val, $countries)) { |
|
83 | - $obj->Country = array_search($val, $countries); |
|
84 | - } |
|
85 | - } |
|
82 | + if (in_array($val, $countries)) { |
|
83 | + $obj->Country = array_search($val, $countries); |
|
84 | + } |
|
85 | + } |
|
86 | 86 | |
87 | - /** |
|
88 | - * @param array $record |
|
89 | - * @param array $columnMap |
|
90 | - * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
91 | - * @param bool $preview |
|
92 | - * @return int|void |
|
93 | - */ |
|
94 | - protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
95 | - { |
|
96 | - $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
87 | + /** |
|
88 | + * @param array $record |
|
89 | + * @param array $columnMap |
|
90 | + * @param \SilverStripe\Dev\BulkLoader_Result $results |
|
91 | + * @param bool $preview |
|
92 | + * @return int|void |
|
93 | + */ |
|
94 | + protected function processRecord($record, $columnMap, &$results, $preview = false) |
|
95 | + { |
|
96 | + $objID = parent::processRecord($record, $columnMap, $results, $preview = false); |
|
97 | 97 | |
98 | - $location = Location::get()->byID($objID); |
|
99 | - $location->publishSingle(); |
|
100 | - } |
|
98 | + $location = Location::get()->byID($objID); |
|
99 | + $location->publishSingle(); |
|
100 | + } |
|
101 | 101 | } |
@@ -72,7 +72,7 @@ |
||
72 | 72 | $val = $this->getEscape($val); |
73 | 73 | $countries = IntlLocales::singleton()->getCountries(); |
74 | 74 | |
75 | - if (strlen((string)$val) == 2) { |
|
75 | + if (strlen((string) $val) == 2) { |
|
76 | 76 | $val = strtolower($val); |
77 | 77 | if (array_key_exists($val, $countries)) { |
78 | 78 | $obj->Country = $val; |