@@ -2,41 +2,41 @@ |
||
2 | 2 | |
3 | 3 | class LocationAdmin extends ModelAdmin |
4 | 4 | { |
5 | - private static $managed_models = array( |
|
6 | - 'Location', |
|
7 | - 'LocationCategory', |
|
8 | - ); |
|
5 | + private static $managed_models = array( |
|
6 | + 'Location', |
|
7 | + 'LocationCategory', |
|
8 | + ); |
|
9 | 9 | |
10 | - private static $model_importers = array( |
|
11 | - 'Location' => 'LocationCsvBulkLoader', |
|
12 | - 'LocationCategory' => 'CsvBulkLoader', |
|
13 | - ); |
|
10 | + private static $model_importers = array( |
|
11 | + 'Location' => 'LocationCsvBulkLoader', |
|
12 | + 'LocationCategory' => 'CsvBulkLoader', |
|
13 | + ); |
|
14 | 14 | |
15 | - private static $menu_title = 'Locator'; |
|
16 | - private static $url_segment = 'locator'; |
|
15 | + private static $menu_title = 'Locator'; |
|
16 | + private static $url_segment = 'locator'; |
|
17 | 17 | |
18 | - public function getExportFields() |
|
19 | - { |
|
20 | - if ($this->modelClass == 'Location') { |
|
21 | - return array( |
|
22 | - 'Title' => 'Name', |
|
23 | - 'Address' => 'Address', |
|
24 | - 'Suburb' => 'City', |
|
25 | - 'State' => 'State', |
|
26 | - 'Postcode' => 'Postcode', |
|
27 | - 'Country' => 'Country', |
|
28 | - 'Website' => 'Website', |
|
29 | - 'Phone' => 'Phone', |
|
30 | - 'Fax' => 'Fax', |
|
31 | - 'Email' => 'Email', |
|
32 | - 'Category.Name' => 'Category', |
|
33 | - 'ShowInLocator' => 'ShowInLocator', |
|
34 | - 'Featured' => 'Featured', |
|
35 | - 'Lat' => 'Lat', |
|
36 | - 'Lng' => 'Lng', |
|
37 | - ); |
|
38 | - } |
|
18 | + public function getExportFields() |
|
19 | + { |
|
20 | + if ($this->modelClass == 'Location') { |
|
21 | + return array( |
|
22 | + 'Title' => 'Name', |
|
23 | + 'Address' => 'Address', |
|
24 | + 'Suburb' => 'City', |
|
25 | + 'State' => 'State', |
|
26 | + 'Postcode' => 'Postcode', |
|
27 | + 'Country' => 'Country', |
|
28 | + 'Website' => 'Website', |
|
29 | + 'Phone' => 'Phone', |
|
30 | + 'Fax' => 'Fax', |
|
31 | + 'Email' => 'Email', |
|
32 | + 'Category.Name' => 'Category', |
|
33 | + 'ShowInLocator' => 'ShowInLocator', |
|
34 | + 'Featured' => 'Featured', |
|
35 | + 'Lat' => 'Lat', |
|
36 | + 'Lng' => 'Lng', |
|
37 | + ); |
|
38 | + } |
|
39 | 39 | |
40 | - return parent::getExportFields(); |
|
41 | - } |
|
40 | + return parent::getExportFields(); |
|
41 | + } |
|
42 | 42 | } |
@@ -2,30 +2,30 @@ |
||
2 | 2 | |
3 | 3 | class LocationCsvBulkLoader extends CsvBulkLoader |
4 | 4 | { |
5 | - public $columnMap = array( |
|
6 | - 'Name' => 'Title', |
|
7 | - 'City' => 'Suburb', |
|
8 | - 'EmailAddress' => 'Email', |
|
9 | - 'Category' => 'Category.Name', |
|
10 | - ); |
|
5 | + public $columnMap = array( |
|
6 | + 'Name' => 'Title', |
|
7 | + 'City' => 'Suburb', |
|
8 | + 'EmailAddress' => 'Email', |
|
9 | + 'Category' => 'Category.Name', |
|
10 | + ); |
|
11 | 11 | |
12 | - public $relationCallbacks = array( |
|
13 | - 'Category.Name' => array( |
|
14 | - 'relationname' => 'Category', |
|
15 | - 'callback' => 'getCategoryByName', |
|
16 | - ), |
|
17 | - ); |
|
12 | + public $relationCallbacks = array( |
|
13 | + 'Category.Name' => array( |
|
14 | + 'relationname' => 'Category', |
|
15 | + 'callback' => 'getCategoryByName', |
|
16 | + ), |
|
17 | + ); |
|
18 | 18 | |
19 | - public static function getCategoryByName(&$obj, $val, $record) |
|
20 | - { |
|
21 | - $val = Convert::raw2sql($val); |
|
22 | - $category = LocationCategory::get()->filter(array('Name' => $val))->First(); |
|
23 | - if (!$category) { |
|
24 | - $category = LocationCategory::create(); |
|
25 | - $category->Name = $val; |
|
26 | - $category->write(); |
|
27 | - } |
|
19 | + public static function getCategoryByName(&$obj, $val, $record) |
|
20 | + { |
|
21 | + $val = Convert::raw2sql($val); |
|
22 | + $category = LocationCategory::get()->filter(array('Name' => $val))->First(); |
|
23 | + if (!$category) { |
|
24 | + $category = LocationCategory::create(); |
|
25 | + $category->Name = $val; |
|
26 | + $category->write(); |
|
27 | + } |
|
28 | 28 | |
29 | - return $category; |
|
30 | - } |
|
29 | + return $category; |
|
30 | + } |
|
31 | 31 | } |
@@ -2,26 +2,26 @@ |
||
2 | 2 | |
3 | 3 | class Locator_Test extends FunctionalTest |
4 | 4 | { |
5 | - protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
|
6 | - protected static $disable_themes = true; |
|
7 | - protected static $use_draft_site = false; |
|
5 | + protected static $fixture_file = 'locator/tests/Locator_Test.yml'; |
|
6 | + protected static $disable_themes = true; |
|
7 | + protected static $use_draft_site = false; |
|
8 | 8 | |
9 | - public function setUp() |
|
10 | - { |
|
11 | - parent::setUp(); |
|
9 | + public function setUp() |
|
10 | + { |
|
11 | + parent::setUp(); |
|
12 | 12 | |
13 | - ini_set('display_errors', 1); |
|
14 | - ini_set('log_errors', 1); |
|
15 | - error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|
16 | - } |
|
13 | + ini_set('display_errors', 1); |
|
14 | + ini_set('log_errors', 1); |
|
15 | + error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED); |
|
16 | + } |
|
17 | 17 | |
18 | - public function logOut() |
|
19 | - { |
|
20 | - $this->session()->clear('loggedInAs'); |
|
21 | - $this->session()->clear('logInWithPermission'); |
|
22 | - } |
|
18 | + public function logOut() |
|
19 | + { |
|
20 | + $this->session()->clear('loggedInAs'); |
|
21 | + $this->session()->clear('logInWithPermission'); |
|
22 | + } |
|
23 | 23 | |
24 | - public function testLocator_Test() |
|
25 | - { |
|
26 | - } |
|
24 | + public function testLocator_Test() |
|
25 | + { |
|
26 | + } |
|
27 | 27 | } |
@@ -2,20 +2,20 @@ |
||
2 | 2 | |
3 | 3 | class LocationCategory extends DataObject |
4 | 4 | { |
5 | - private static $db = array( |
|
6 | - 'Name' => 'Varchar(100)', |
|
7 | - ); |
|
5 | + private static $db = array( |
|
6 | + 'Name' => 'Varchar(100)', |
|
7 | + ); |
|
8 | 8 | |
9 | - private static $has_many = array( |
|
10 | - 'Locations' => 'Location', |
|
11 | - ); |
|
9 | + private static $has_many = array( |
|
10 | + 'Locations' => 'Location', |
|
11 | + ); |
|
12 | 12 | |
13 | - private static $belogs_many_many = array( |
|
14 | - 'Locators' => 'Locator', |
|
15 | - ); |
|
13 | + private static $belogs_many_many = array( |
|
14 | + 'Locators' => 'Locator', |
|
15 | + ); |
|
16 | 16 | |
17 | - private static $singular_name = 'Category'; |
|
18 | - private static $plural_name = 'Categories'; |
|
17 | + private static $singular_name = 'Category'; |
|
18 | + private static $plural_name = 'Categories'; |
|
19 | 19 | |
20 | - private static $default_sort = 'Name'; |
|
20 | + private static $default_sort = 'Name'; |
|
21 | 21 | } |
@@ -2,173 +2,173 @@ |
||
2 | 2 | |
3 | 3 | class Location extends DataObject implements PermissionProvider |
4 | 4 | { |
5 | - private static $db = array( |
|
6 | - 'Title' => 'Varchar(255)', |
|
7 | - 'Featured' => 'Boolean', |
|
8 | - 'Website' => 'Varchar(255)', |
|
9 | - 'Phone' => 'Varchar(40)', |
|
10 | - 'Email' => 'Varchar(255)', |
|
11 | - 'EmailAddress' => 'Varchar(255)', |
|
12 | - 'ShowInLocator' => 'Boolean', |
|
13 | - ); |
|
14 | - |
|
15 | - private static $has_one = array( |
|
16 | - 'Category' => 'LocationCategory', |
|
17 | - ); |
|
18 | - |
|
19 | - private static $casting = array( |
|
20 | - 'distance' => 'Int', |
|
21 | - ); |
|
22 | - |
|
23 | - private static $default_sort = 'Title'; |
|
24 | - |
|
25 | - private static $defaults = array( |
|
26 | - 'ShowInLocator' => true, |
|
27 | - ); |
|
28 | - |
|
29 | - private static $singular_name = 'Location'; |
|
30 | - private static $plural_name = 'Locations'; |
|
31 | - |
|
32 | - // api access via Restful Server module |
|
33 | - private static $api_access = true; |
|
34 | - |
|
35 | - // search fields for Model Admin |
|
36 | - private static $searchable_fields = array( |
|
37 | - 'Title', |
|
38 | - 'Address', |
|
39 | - 'Suburb', |
|
40 | - 'State', |
|
41 | - 'Postcode', |
|
42 | - 'Country', |
|
43 | - 'Website', |
|
44 | - 'Phone', |
|
45 | - 'Email', |
|
46 | - 'Category.ID', |
|
47 | - 'ShowInLocator', |
|
48 | - 'Featured', |
|
49 | - ); |
|
50 | - |
|
51 | - // columns for grid field |
|
52 | - private static $summary_fields = array( |
|
53 | - 'Title', |
|
54 | - 'Address', |
|
55 | - 'Suburb', |
|
56 | - 'State', |
|
57 | - 'Postcode', |
|
58 | - 'Country', |
|
59 | - 'Category.Name', |
|
60 | - 'ShowInLocator.NiceAsBoolean', |
|
61 | - 'Featured.NiceAsBoolean', |
|
62 | - 'Coords', |
|
63 | - ); |
|
64 | - |
|
65 | - // Coords status for $summary_fields |
|
66 | - public function getCoords() |
|
67 | - { |
|
68 | - return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
69 | - } |
|
70 | - |
|
71 | - // custom labels for fields |
|
72 | - public function fieldLabels($includerelations = true) |
|
73 | - { |
|
74 | - $labels = parent::fieldLabels(); |
|
75 | - |
|
76 | - $labels['Title'] = 'Name'; |
|
77 | - $labels['Suburb'] = 'City'; |
|
78 | - $labels['Postcode'] = 'Postal Code'; |
|
79 | - $labels['ShowInLocator'] = 'Show'; |
|
80 | - $labels['ShowInLocator.NiceAsBoolean'] = 'Show'; |
|
81 | - $labels['Category.Name'] = 'Category'; |
|
82 | - $labels['Category.ID'] = 'Category'; |
|
83 | - $labels['Email'] = 'Email'; |
|
84 | - $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
85 | - $labels['Coords'] = 'Coords'; |
|
86 | - |
|
87 | - return $labels; |
|
88 | - } |
|
89 | - |
|
90 | - public function getCMSFields() |
|
91 | - { |
|
92 | - $fields = FieldList::create( |
|
93 | - new TabSet( |
|
94 | - $name = 'Root', |
|
95 | - new Tab( |
|
96 | - $title = 'Main', |
|
97 | - HeaderField::create('ContactHD', 'Contact Information'), |
|
98 | - TextField::create('Title', 'Name'), |
|
99 | - TextField::create('Phone'), |
|
100 | - EmailField::create('Email', 'Email'), |
|
101 | - TextField::create('Website') |
|
102 | - ->setAttribute('placeholder', 'http://'), |
|
103 | - DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
104 | - ->setEmptyString('-- select --'), |
|
105 | - CheckboxField::create('ShowInLocator', 'Show in results') |
|
106 | - ->setDescription('Location will be included in results list'), |
|
107 | - CheckboxField::create('Featured') |
|
108 | - ->setDescription('Location will show at/near the top of the results list') |
|
109 | - ) |
|
110 | - ) |
|
111 | - ); |
|
112 | - |
|
113 | - // allow to be extended via DataExtension |
|
114 | - $this->extend('updateCMSFields', $fields); |
|
115 | - |
|
116 | - // override Suburb field name |
|
117 | - $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
118 | - |
|
119 | - return $fields; |
|
120 | - } |
|
121 | - |
|
122 | - public function validate() |
|
123 | - { |
|
124 | - $result = parent::validate(); |
|
125 | - |
|
126 | - return $result; |
|
127 | - } |
|
128 | - |
|
129 | - public function EmailAddress() |
|
130 | - { |
|
131 | - Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
132 | - if ($this->Email) { |
|
133 | - return $this->Email; |
|
134 | - } elseif ($this->EmailAddress) { |
|
135 | - return $this->EmailAddress; |
|
136 | - } |
|
137 | - |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - /** |
|
142 | - * @param Member $member |
|
143 | - * |
|
144 | - * @return bool |
|
145 | - */ |
|
146 | - public function canView($member = false) |
|
147 | - { |
|
148 | - return true; |
|
149 | - } |
|
150 | - |
|
151 | - public function canEdit($member = false) |
|
152 | - { |
|
153 | - return Permission::check('Location_EDIT'); |
|
154 | - } |
|
155 | - |
|
156 | - public function canDelete($member = false) |
|
157 | - { |
|
158 | - return Permission::check('Location_DELETE'); |
|
159 | - } |
|
160 | - |
|
161 | - public function canCreate($member = false) |
|
162 | - { |
|
163 | - return Permission::check('Location_CREATE'); |
|
164 | - } |
|
165 | - |
|
166 | - public function providePermissions() |
|
167 | - { |
|
168 | - return array( |
|
169 | - 'Location_EDIT' => 'Edit a Location', |
|
170 | - 'Location_DELETE' => 'Delete a Location', |
|
171 | - 'Location_CREATE' => 'Create a Location', |
|
172 | - ); |
|
173 | - } |
|
5 | + private static $db = array( |
|
6 | + 'Title' => 'Varchar(255)', |
|
7 | + 'Featured' => 'Boolean', |
|
8 | + 'Website' => 'Varchar(255)', |
|
9 | + 'Phone' => 'Varchar(40)', |
|
10 | + 'Email' => 'Varchar(255)', |
|
11 | + 'EmailAddress' => 'Varchar(255)', |
|
12 | + 'ShowInLocator' => 'Boolean', |
|
13 | + ); |
|
14 | + |
|
15 | + private static $has_one = array( |
|
16 | + 'Category' => 'LocationCategory', |
|
17 | + ); |
|
18 | + |
|
19 | + private static $casting = array( |
|
20 | + 'distance' => 'Int', |
|
21 | + ); |
|
22 | + |
|
23 | + private static $default_sort = 'Title'; |
|
24 | + |
|
25 | + private static $defaults = array( |
|
26 | + 'ShowInLocator' => true, |
|
27 | + ); |
|
28 | + |
|
29 | + private static $singular_name = 'Location'; |
|
30 | + private static $plural_name = 'Locations'; |
|
31 | + |
|
32 | + // api access via Restful Server module |
|
33 | + private static $api_access = true; |
|
34 | + |
|
35 | + // search fields for Model Admin |
|
36 | + private static $searchable_fields = array( |
|
37 | + 'Title', |
|
38 | + 'Address', |
|
39 | + 'Suburb', |
|
40 | + 'State', |
|
41 | + 'Postcode', |
|
42 | + 'Country', |
|
43 | + 'Website', |
|
44 | + 'Phone', |
|
45 | + 'Email', |
|
46 | + 'Category.ID', |
|
47 | + 'ShowInLocator', |
|
48 | + 'Featured', |
|
49 | + ); |
|
50 | + |
|
51 | + // columns for grid field |
|
52 | + private static $summary_fields = array( |
|
53 | + 'Title', |
|
54 | + 'Address', |
|
55 | + 'Suburb', |
|
56 | + 'State', |
|
57 | + 'Postcode', |
|
58 | + 'Country', |
|
59 | + 'Category.Name', |
|
60 | + 'ShowInLocator.NiceAsBoolean', |
|
61 | + 'Featured.NiceAsBoolean', |
|
62 | + 'Coords', |
|
63 | + ); |
|
64 | + |
|
65 | + // Coords status for $summary_fields |
|
66 | + public function getCoords() |
|
67 | + { |
|
68 | + return ($this->Lat != 0 && $this->Lng != 0) ? 'true' : 'false'; |
|
69 | + } |
|
70 | + |
|
71 | + // custom labels for fields |
|
72 | + public function fieldLabels($includerelations = true) |
|
73 | + { |
|
74 | + $labels = parent::fieldLabels(); |
|
75 | + |
|
76 | + $labels['Title'] = 'Name'; |
|
77 | + $labels['Suburb'] = 'City'; |
|
78 | + $labels['Postcode'] = 'Postal Code'; |
|
79 | + $labels['ShowInLocator'] = 'Show'; |
|
80 | + $labels['ShowInLocator.NiceAsBoolean'] = 'Show'; |
|
81 | + $labels['Category.Name'] = 'Category'; |
|
82 | + $labels['Category.ID'] = 'Category'; |
|
83 | + $labels['Email'] = 'Email'; |
|
84 | + $labels['Featured.NiceAsBoolean'] = 'Featured'; |
|
85 | + $labels['Coords'] = 'Coords'; |
|
86 | + |
|
87 | + return $labels; |
|
88 | + } |
|
89 | + |
|
90 | + public function getCMSFields() |
|
91 | + { |
|
92 | + $fields = FieldList::create( |
|
93 | + new TabSet( |
|
94 | + $name = 'Root', |
|
95 | + new Tab( |
|
96 | + $title = 'Main', |
|
97 | + HeaderField::create('ContactHD', 'Contact Information'), |
|
98 | + TextField::create('Title', 'Name'), |
|
99 | + TextField::create('Phone'), |
|
100 | + EmailField::create('Email', 'Email'), |
|
101 | + TextField::create('Website') |
|
102 | + ->setAttribute('placeholder', 'http://'), |
|
103 | + DropDownField::create('CategoryID', 'Category', LocationCategory::get()->map('ID', 'Title')) |
|
104 | + ->setEmptyString('-- select --'), |
|
105 | + CheckboxField::create('ShowInLocator', 'Show in results') |
|
106 | + ->setDescription('Location will be included in results list'), |
|
107 | + CheckboxField::create('Featured') |
|
108 | + ->setDescription('Location will show at/near the top of the results list') |
|
109 | + ) |
|
110 | + ) |
|
111 | + ); |
|
112 | + |
|
113 | + // allow to be extended via DataExtension |
|
114 | + $this->extend('updateCMSFields', $fields); |
|
115 | + |
|
116 | + // override Suburb field name |
|
117 | + $fields->dataFieldByName('Suburb')->setTitle('City'); |
|
118 | + |
|
119 | + return $fields; |
|
120 | + } |
|
121 | + |
|
122 | + public function validate() |
|
123 | + { |
|
124 | + $result = parent::validate(); |
|
125 | + |
|
126 | + return $result; |
|
127 | + } |
|
128 | + |
|
129 | + public function EmailAddress() |
|
130 | + { |
|
131 | + Deprecation::notice('3.0', 'Use "$Email" instead.'); |
|
132 | + if ($this->Email) { |
|
133 | + return $this->Email; |
|
134 | + } elseif ($this->EmailAddress) { |
|
135 | + return $this->EmailAddress; |
|
136 | + } |
|
137 | + |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + /** |
|
142 | + * @param Member $member |
|
143 | + * |
|
144 | + * @return bool |
|
145 | + */ |
|
146 | + public function canView($member = false) |
|
147 | + { |
|
148 | + return true; |
|
149 | + } |
|
150 | + |
|
151 | + public function canEdit($member = false) |
|
152 | + { |
|
153 | + return Permission::check('Location_EDIT'); |
|
154 | + } |
|
155 | + |
|
156 | + public function canDelete($member = false) |
|
157 | + { |
|
158 | + return Permission::check('Location_DELETE'); |
|
159 | + } |
|
160 | + |
|
161 | + public function canCreate($member = false) |
|
162 | + { |
|
163 | + return Permission::check('Location_CREATE'); |
|
164 | + } |
|
165 | + |
|
166 | + public function providePermissions() |
|
167 | + { |
|
168 | + return array( |
|
169 | + 'Location_EDIT' => 'Edit a Location', |
|
170 | + 'Location_DELETE' => 'Delete a Location', |
|
171 | + 'Location_CREATE' => 'Create a Location', |
|
172 | + ); |
|
173 | + } |
|
174 | 174 | } |
@@ -2,88 +2,88 @@ |
||
2 | 2 | |
3 | 3 | class LocatorTest extends Locator_Test |
4 | 4 | { |
5 | - public function testGetCMSFields() |
|
6 | - { |
|
7 | - $object = new Locator(); |
|
8 | - $fieldset = $object->getCMSFields(); |
|
9 | - $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
10 | - } |
|
5 | + public function testGetCMSFields() |
|
6 | + { |
|
7 | + $object = new Locator(); |
|
8 | + $fieldset = $object->getCMSFields(); |
|
9 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
10 | + } |
|
11 | 11 | |
12 | - public function testLocations() |
|
13 | - { |
|
14 | - $filter = array('ShowInLocator' => 1); |
|
15 | - $filterAny = array('Suburb' => 'Sheboygan'); |
|
16 | - $exclude = array('Suburb' => 'Milwaukee'); |
|
17 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
18 | - $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
19 | - $this->assertEquals($locations->Count(), $locations2->Count()); |
|
20 | - } |
|
12 | + public function testLocations() |
|
13 | + { |
|
14 | + $filter = array('ShowInLocator' => 1); |
|
15 | + $filterAny = array('Suburb' => 'Sheboygan'); |
|
16 | + $exclude = array('Suburb' => 'Milwaukee'); |
|
17 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
18 | + $locations2 = Location::get()->filter($filter)->filterAny($filterAny)->exclude($exclude); |
|
19 | + $this->assertEquals($locations->Count(), $locations2->Count()); |
|
20 | + } |
|
21 | 21 | |
22 | - public function testGetAllCategories() |
|
23 | - { |
|
24 | - $locator = singleton('Locator'); |
|
25 | - $count = LocationCategory::get(); |
|
26 | - $this->assertEquals($locator->getAllCategories(), $count); |
|
27 | - } |
|
22 | + public function testGetAllCategories() |
|
23 | + { |
|
24 | + $locator = singleton('Locator'); |
|
25 | + $count = LocationCategory::get(); |
|
26 | + $this->assertEquals($locator->getAllCategories(), $count); |
|
27 | + } |
|
28 | 28 | |
29 | - public function testGetPageCategories() |
|
30 | - { |
|
31 | - $locator = Locator::create(); |
|
32 | - $this->assertFalse($locator->getPageCategories()); |
|
29 | + public function testGetPageCategories() |
|
30 | + { |
|
31 | + $locator = Locator::create(); |
|
32 | + $this->assertFalse($locator->getPageCategories()); |
|
33 | 33 | |
34 | - $this->assertFalse($locator->getPageCategories(500)); |
|
34 | + $this->assertFalse($locator->getPageCategories(500)); |
|
35 | 35 | |
36 | - $locator->write(); |
|
37 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
38 | - $locator->Categories()->add($category); |
|
39 | - $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
40 | - } |
|
36 | + $locator->write(); |
|
37 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
38 | + $locator->Categories()->add($category); |
|
39 | + $this->assertEquals($locator->getPageCategories($locator->ID), $locator->Categories()); |
|
40 | + } |
|
41 | 41 | |
42 | - public function testInit() |
|
43 | - { |
|
44 | - } |
|
42 | + public function testInit() |
|
43 | + { |
|
44 | + } |
|
45 | 45 | |
46 | - public function testIndex() |
|
47 | - { |
|
48 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
49 | - $controller = Locator_Controller::create($locator); |
|
50 | - $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
51 | - } |
|
46 | + public function testIndex() |
|
47 | + { |
|
48 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
49 | + $controller = Locator_Controller::create($locator); |
|
50 | + $this->assertInstanceOf('ViewableData', $controller->index($controller->request)); |
|
51 | + } |
|
52 | 52 | |
53 | - public function testXml() |
|
54 | - { |
|
55 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
56 | - $controller = Locator_Controller::create($locator); |
|
57 | - $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
58 | - } |
|
53 | + public function testXml() |
|
54 | + { |
|
55 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
56 | + $controller = Locator_Controller::create($locator); |
|
57 | + $this->assertInstanceOf('HTMLText', $controller->xml($controller->request)); |
|
58 | + } |
|
59 | 59 | |
60 | - public function testItems() |
|
61 | - { |
|
62 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
63 | - $controller = Locator_Controller::create($locator); |
|
60 | + public function testItems() |
|
61 | + { |
|
62 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
63 | + $controller = Locator_Controller::create($locator); |
|
64 | 64 | |
65 | - $filter = array('ShowInLocator' => 1); |
|
66 | - $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
65 | + $filter = array('ShowInLocator' => 1); |
|
66 | + $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
67 | 67 | |
68 | - $locations = $controller->Items($controller->request); |
|
69 | - $locations2 = Location::get()->filter($filter)->exclude($exclude); |
|
70 | - $this->assertEquals($locations->count(), $locations2->count()); |
|
71 | - } |
|
68 | + $locations = $controller->Items($controller->request); |
|
69 | + $locations2 = Location::get()->filter($filter)->exclude($exclude); |
|
70 | + $this->assertEquals($locations->count(), $locations2->count()); |
|
71 | + } |
|
72 | 72 | |
73 | - public function testLocationSearch() |
|
74 | - { |
|
75 | - $locator = $this->objFromFixture('Locator', 'locator1'); |
|
76 | - $object = Locator_Controller::create($locator); |
|
77 | - $form = $object->LocationSearch(); |
|
78 | - $this->assertTrue(is_a($form, 'Form')); |
|
73 | + public function testLocationSearch() |
|
74 | + { |
|
75 | + $locator = $this->objFromFixture('Locator', 'locator1'); |
|
76 | + $object = Locator_Controller::create($locator); |
|
77 | + $form = $object->LocationSearch(); |
|
78 | + $this->assertTrue(is_a($form, 'Form')); |
|
79 | 79 | |
80 | - $category = $this->objFromFixture('LocationCategory', 'service'); |
|
81 | - $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
82 | - $locator->Categories()->add($category); |
|
83 | - $locator->Categories()->add($category2); |
|
80 | + $category = $this->objFromFixture('LocationCategory', 'service'); |
|
81 | + $category2 = $this->objFromFixture('LocationCategory', 'manufacturing'); |
|
82 | + $locator->Categories()->add($category); |
|
83 | + $locator->Categories()->add($category2); |
|
84 | 84 | |
85 | - $form = $object->LocationSearch(); |
|
86 | - $fields = $form->Fields(); |
|
87 | - $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
88 | - } |
|
85 | + $form = $object->LocationSearch(); |
|
86 | + $fields = $form->Fields(); |
|
87 | + $this->assertNotNull($fields->fieldByName('CategoryID')); |
|
88 | + } |
|
89 | 89 | } |
@@ -2,119 +2,119 @@ |
||
2 | 2 | |
3 | 3 | class LocationTest extends Locator_Test |
4 | 4 | { |
5 | - public function testGetCoords() |
|
6 | - { |
|
7 | - $location = $this->objFromFixture('Location', 'dynamic'); |
|
5 | + public function testGetCoords() |
|
6 | + { |
|
7 | + $location = $this->objFromFixture('Location', 'dynamic'); |
|
8 | 8 | |
9 | - $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
9 | + $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
10 | 10 | |
11 | - $this->assertEquals($coords, $location->getCoords()); |
|
12 | - } |
|
11 | + $this->assertEquals($coords, $location->getCoords()); |
|
12 | + } |
|
13 | 13 | |
14 | - public function testFieldLabels() |
|
15 | - { |
|
16 | - $location = $this->objFromFixture('Location', 'dynamic'); |
|
17 | - $labels = $location->FieldLabels(); |
|
18 | - $expected = array( |
|
19 | - 'Title' => 'Name', |
|
20 | - 'Featured' => 'Featured', |
|
21 | - 'Website' => 'Website', |
|
22 | - 'Phone' => 'Phone', |
|
23 | - 'Email' => 'Email', |
|
24 | - 'EmailAddress' => 'Email Address', |
|
25 | - 'ShowInLocator' => 'Show', |
|
26 | - 'Address' => 'Address', |
|
27 | - 'Suburb' => 'City', |
|
28 | - 'State' => 'State', |
|
29 | - 'Postcode' => 'Postal Code', |
|
30 | - 'Country' => 'Country', |
|
31 | - 'Lat' => 'Lat', |
|
32 | - 'Lng' => 'Lng', |
|
33 | - 'Category' => 'Category', |
|
34 | - 'ShowInLocator.NiceAsBoolean' => 'Show', |
|
35 | - 'Category.Name' => 'Category', |
|
36 | - 'Category.ID' => 'Category', |
|
37 | - 'Featured.NiceAsBoolean' => 'Featured', |
|
38 | - 'Coords' => 'Coords', |
|
39 | - ); |
|
40 | - $this->assertEquals($expected, $labels); |
|
41 | - } |
|
14 | + public function testFieldLabels() |
|
15 | + { |
|
16 | + $location = $this->objFromFixture('Location', 'dynamic'); |
|
17 | + $labels = $location->FieldLabels(); |
|
18 | + $expected = array( |
|
19 | + 'Title' => 'Name', |
|
20 | + 'Featured' => 'Featured', |
|
21 | + 'Website' => 'Website', |
|
22 | + 'Phone' => 'Phone', |
|
23 | + 'Email' => 'Email', |
|
24 | + 'EmailAddress' => 'Email Address', |
|
25 | + 'ShowInLocator' => 'Show', |
|
26 | + 'Address' => 'Address', |
|
27 | + 'Suburb' => 'City', |
|
28 | + 'State' => 'State', |
|
29 | + 'Postcode' => 'Postal Code', |
|
30 | + 'Country' => 'Country', |
|
31 | + 'Lat' => 'Lat', |
|
32 | + 'Lng' => 'Lng', |
|
33 | + 'Category' => 'Category', |
|
34 | + 'ShowInLocator.NiceAsBoolean' => 'Show', |
|
35 | + 'Category.Name' => 'Category', |
|
36 | + 'Category.ID' => 'Category', |
|
37 | + 'Featured.NiceAsBoolean' => 'Featured', |
|
38 | + 'Coords' => 'Coords', |
|
39 | + ); |
|
40 | + $this->assertEquals($expected, $labels); |
|
41 | + } |
|
42 | 42 | |
43 | - public function testGetCMSFields() |
|
44 | - { |
|
45 | - $object = new Location(); |
|
46 | - $fieldset = $object->getCMSFields(); |
|
47 | - $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
48 | - } |
|
43 | + public function testGetCMSFields() |
|
44 | + { |
|
45 | + $object = new Location(); |
|
46 | + $fieldset = $object->getCMSFields(); |
|
47 | + $this->assertTrue(is_a($fieldset, 'FieldList')); |
|
48 | + } |
|
49 | 49 | |
50 | - public function testValidate() |
|
51 | - { |
|
52 | - } |
|
50 | + public function testValidate() |
|
51 | + { |
|
52 | + } |
|
53 | 53 | |
54 | - public function testEmailAddress() |
|
55 | - { |
|
56 | - } |
|
54 | + public function testEmailAddress() |
|
55 | + { |
|
56 | + } |
|
57 | 57 | |
58 | - public function testCanView() |
|
59 | - { |
|
60 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
61 | - $object->write(); |
|
62 | - $this->logInWithPermission('ADMIN'); |
|
63 | - $this->assertTrue($object->canView()); |
|
64 | - $this->logOut(); |
|
65 | - $nullMember = Member::create(); |
|
66 | - $nullMember->write(); |
|
67 | - $this->assertTrue($object->canView($nullMember)); |
|
68 | - $nullMember->delete(); |
|
69 | - } |
|
58 | + public function testCanView() |
|
59 | + { |
|
60 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
61 | + $object->write(); |
|
62 | + $this->logInWithPermission('ADMIN'); |
|
63 | + $this->assertTrue($object->canView()); |
|
64 | + $this->logOut(); |
|
65 | + $nullMember = Member::create(); |
|
66 | + $nullMember->write(); |
|
67 | + $this->assertTrue($object->canView($nullMember)); |
|
68 | + $nullMember->delete(); |
|
69 | + } |
|
70 | 70 | |
71 | - public function testCanEdit() |
|
72 | - { |
|
73 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
74 | - $object->write(); |
|
75 | - $objectID = $object->ID; |
|
76 | - $this->logInWithPermission('Location_EDIT'); |
|
77 | - $originalTitle = $object->Title; |
|
78 | - $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
79 | - $this->assertTrue($object->canEdit()); |
|
80 | - $object->Title = 'Changed Title'; |
|
81 | - $object->write(); |
|
82 | - $testEdit = Location::get()->byID($objectID); |
|
83 | - $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
84 | - $this->logOut(); |
|
85 | - } |
|
71 | + public function testCanEdit() |
|
72 | + { |
|
73 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
74 | + $object->write(); |
|
75 | + $objectID = $object->ID; |
|
76 | + $this->logInWithPermission('Location_EDIT'); |
|
77 | + $originalTitle = $object->Title; |
|
78 | + $this->assertEquals($originalTitle, 'Dynamic, Inc.'); |
|
79 | + $this->assertTrue($object->canEdit()); |
|
80 | + $object->Title = 'Changed Title'; |
|
81 | + $object->write(); |
|
82 | + $testEdit = Location::get()->byID($objectID); |
|
83 | + $this->assertEquals($testEdit->Title, 'Changed Title'); |
|
84 | + $this->logOut(); |
|
85 | + } |
|
86 | 86 | |
87 | - public function testCanDelete() |
|
88 | - { |
|
89 | - $object = $this->objFromFixture('Location', 'dynamic'); |
|
90 | - $object->write(); |
|
91 | - $this->logInWithPermission('Location_DELETE'); |
|
92 | - $this->assertTrue($object->canDelete()); |
|
93 | - $checkObject = $object; |
|
94 | - $object->delete(); |
|
95 | - $this->assertEquals($checkObject->ID, 0); |
|
96 | - } |
|
87 | + public function testCanDelete() |
|
88 | + { |
|
89 | + $object = $this->objFromFixture('Location', 'dynamic'); |
|
90 | + $object->write(); |
|
91 | + $this->logInWithPermission('Location_DELETE'); |
|
92 | + $this->assertTrue($object->canDelete()); |
|
93 | + $checkObject = $object; |
|
94 | + $object->delete(); |
|
95 | + $this->assertEquals($checkObject->ID, 0); |
|
96 | + } |
|
97 | 97 | |
98 | - public function testCanCreate() |
|
99 | - { |
|
100 | - $object = singleton('Location'); |
|
101 | - $this->logInWithPermission('Location_CREATE'); |
|
102 | - $this->assertTrue($object->canCreate()); |
|
103 | - $this->logOut(); |
|
104 | - $nullMember = Member::create(); |
|
105 | - $nullMember->write(); |
|
106 | - $this->assertFalse($object->canCreate($nullMember)); |
|
107 | - $nullMember->delete(); |
|
108 | - } |
|
98 | + public function testCanCreate() |
|
99 | + { |
|
100 | + $object = singleton('Location'); |
|
101 | + $this->logInWithPermission('Location_CREATE'); |
|
102 | + $this->assertTrue($object->canCreate()); |
|
103 | + $this->logOut(); |
|
104 | + $nullMember = Member::create(); |
|
105 | + $nullMember->write(); |
|
106 | + $this->assertFalse($object->canCreate($nullMember)); |
|
107 | + $nullMember->delete(); |
|
108 | + } |
|
109 | 109 | |
110 | - public function testProvidePermissions() |
|
111 | - { |
|
112 | - $object = Location::create(); |
|
113 | - $expected = array( |
|
114 | - 'Location_EDIT' => 'Edit a Location', |
|
115 | - 'Location_DELETE' => 'Delete a Location', |
|
116 | - 'Location_CREATE' => 'Create a Location', |
|
117 | - ); |
|
118 | - $this->assertEquals($expected, $object->providePermissions()); |
|
119 | - } |
|
110 | + public function testProvidePermissions() |
|
111 | + { |
|
112 | + $object = Location::create(); |
|
113 | + $expected = array( |
|
114 | + 'Location_EDIT' => 'Edit a Location', |
|
115 | + 'Location_DELETE' => 'Delete a Location', |
|
116 | + 'Location_CREATE' => 'Create a Location', |
|
117 | + ); |
|
118 | + $this->assertEquals($expected, $object->providePermissions()); |
|
119 | + } |
|
120 | 120 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | { |
7 | 7 | $location = $this->objFromFixture('Location', 'dynamic'); |
8 | 8 | |
9 | - $coords = ((int)$location->Lat != 0 && (int)$location->Lng != 0) ? 'true' : 'false'; |
|
9 | + $coords = ((int) $location->Lat != 0 && (int) $location->Lng != 0) ? 'true' : 'false'; |
|
10 | 10 | |
11 | 11 | $this->assertEquals($coords, $location->getCoords()); |
12 | 12 | } |
@@ -2,208 +2,208 @@ discard block |
||
2 | 2 | |
3 | 3 | class Locator extends Page |
4 | 4 | { |
5 | - private static $db = array( |
|
6 | - 'AutoGeocode' => 'Boolean', |
|
7 | - 'ModalWindow' => 'Boolean', |
|
8 | - 'Unit' => 'Enum("m,km","m")', |
|
9 | - ); |
|
10 | - |
|
11 | - private static $many_many = array( |
|
12 | - 'Categories' => 'LocationCategory', |
|
13 | - ); |
|
14 | - |
|
15 | - private static $defaults = array( |
|
16 | - 'AutoGeocode' => true, |
|
17 | - ); |
|
18 | - |
|
19 | - private static $singular_name = 'Locator'; |
|
20 | - private static $plural_name = 'Locators'; |
|
21 | - private static $description = 'Find locations on a map'; |
|
22 | - |
|
23 | - /** |
|
24 | - * @return FieldList |
|
25 | - */ |
|
26 | - public function getCMSFields() |
|
27 | - { |
|
28 | - $fields = parent::getCMSFields(); |
|
29 | - |
|
30 | - // Settings |
|
31 | - $fields->addFieldsToTab('Root.Settings', array( |
|
32 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
33 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
34 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
35 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
36 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
37 | - )); |
|
38 | - |
|
39 | - // Filter categories |
|
40 | - $config = GridFieldConfig_RelationEditor::create(); |
|
41 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
42 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
43 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
44 | - } |
|
45 | - $categories = $this->Categories(); |
|
46 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
47 | - ->setDescription('only show locations from the selected category'); |
|
48 | - |
|
49 | - // Filter |
|
50 | - $fields->addFieldsToTab('Root.Filter', array( |
|
51 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
52 | - $categoriesField, |
|
53 | - )); |
|
54 | - |
|
55 | - $this->extend('updateCMSFields', $fields); |
|
56 | - |
|
57 | - return $fields; |
|
58 | - } |
|
59 | - |
|
60 | - /** |
|
61 | - * @param array $filter |
|
62 | - * @param array $filterAny |
|
63 | - * @param array $exclude |
|
64 | - * @param null $filterByCallback |
|
65 | - * @return ArrayList |
|
66 | - */ |
|
67 | - public static function locations( |
|
68 | - $filter = array(), |
|
69 | - $filterAny = array(), |
|
70 | - $exclude = array(), |
|
71 | - $filterByCallback = null |
|
72 | - ) |
|
73 | - { |
|
74 | - $locationsList = ArrayList::create(); |
|
75 | - |
|
76 | - // filter by ShowInLocator |
|
77 | - $filter['ShowInLocator'] = 1; |
|
78 | - |
|
79 | - $locations = Location::get()->filter($filter); |
|
80 | - |
|
81 | - if (!empty($filterAny)) { |
|
82 | - $locations = $locations->filterAny($filterAny); |
|
83 | - } |
|
84 | - if (!empty($exclude)) { |
|
85 | - $locations = $locations->exclude($exclude); |
|
86 | - } |
|
87 | - |
|
88 | - if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
89 | - $locations = $locations->filterByCallback($filterByCallback); |
|
90 | - } |
|
91 | - |
|
92 | - if ($locations->exists()) { |
|
93 | - $locationsList->merge($locations); |
|
94 | - } |
|
95 | - |
|
96 | - return $locationsList; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * @return DataList |
|
101 | - */ |
|
102 | - public static function getAllCategories() |
|
103 | - { |
|
104 | - return LocationCategory::get(); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param null $id |
|
109 | - * @return bool |
|
110 | - */ |
|
111 | - public static function getPageCategories($id = null) |
|
112 | - { |
|
113 | - if ($id) { |
|
114 | - if ($locator = self::get()->byID($id)) { |
|
115 | - return $locator->Categories(); |
|
116 | - } |
|
117 | - |
|
118 | - return false; |
|
119 | - } |
|
120 | - |
|
121 | - return false; |
|
122 | - } |
|
5 | + private static $db = array( |
|
6 | + 'AutoGeocode' => 'Boolean', |
|
7 | + 'ModalWindow' => 'Boolean', |
|
8 | + 'Unit' => 'Enum("m,km","m")', |
|
9 | + ); |
|
10 | + |
|
11 | + private static $many_many = array( |
|
12 | + 'Categories' => 'LocationCategory', |
|
13 | + ); |
|
14 | + |
|
15 | + private static $defaults = array( |
|
16 | + 'AutoGeocode' => true, |
|
17 | + ); |
|
18 | + |
|
19 | + private static $singular_name = 'Locator'; |
|
20 | + private static $plural_name = 'Locators'; |
|
21 | + private static $description = 'Find locations on a map'; |
|
22 | + |
|
23 | + /** |
|
24 | + * @return FieldList |
|
25 | + */ |
|
26 | + public function getCMSFields() |
|
27 | + { |
|
28 | + $fields = parent::getCMSFields(); |
|
29 | + |
|
30 | + // Settings |
|
31 | + $fields->addFieldsToTab('Root.Settings', array( |
|
32 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
33 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
34 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
35 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
36 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
37 | + )); |
|
38 | + |
|
39 | + // Filter categories |
|
40 | + $config = GridFieldConfig_RelationEditor::create(); |
|
41 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
42 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
43 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
44 | + } |
|
45 | + $categories = $this->Categories(); |
|
46 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
47 | + ->setDescription('only show locations from the selected category'); |
|
48 | + |
|
49 | + // Filter |
|
50 | + $fields->addFieldsToTab('Root.Filter', array( |
|
51 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
52 | + $categoriesField, |
|
53 | + )); |
|
54 | + |
|
55 | + $this->extend('updateCMSFields', $fields); |
|
56 | + |
|
57 | + return $fields; |
|
58 | + } |
|
59 | + |
|
60 | + /** |
|
61 | + * @param array $filter |
|
62 | + * @param array $filterAny |
|
63 | + * @param array $exclude |
|
64 | + * @param null $filterByCallback |
|
65 | + * @return ArrayList |
|
66 | + */ |
|
67 | + public static function locations( |
|
68 | + $filter = array(), |
|
69 | + $filterAny = array(), |
|
70 | + $exclude = array(), |
|
71 | + $filterByCallback = null |
|
72 | + ) |
|
73 | + { |
|
74 | + $locationsList = ArrayList::create(); |
|
75 | + |
|
76 | + // filter by ShowInLocator |
|
77 | + $filter['ShowInLocator'] = 1; |
|
78 | + |
|
79 | + $locations = Location::get()->filter($filter); |
|
80 | + |
|
81 | + if (!empty($filterAny)) { |
|
82 | + $locations = $locations->filterAny($filterAny); |
|
83 | + } |
|
84 | + if (!empty($exclude)) { |
|
85 | + $locations = $locations->exclude($exclude); |
|
86 | + } |
|
87 | + |
|
88 | + if ($filterByCallback !== null && is_callable($filterByCallback)) { |
|
89 | + $locations = $locations->filterByCallback($filterByCallback); |
|
90 | + } |
|
91 | + |
|
92 | + if ($locations->exists()) { |
|
93 | + $locationsList->merge($locations); |
|
94 | + } |
|
95 | + |
|
96 | + return $locationsList; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * @return DataList |
|
101 | + */ |
|
102 | + public static function getAllCategories() |
|
103 | + { |
|
104 | + return LocationCategory::get(); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param null $id |
|
109 | + * @return bool |
|
110 | + */ |
|
111 | + public static function getPageCategories($id = null) |
|
112 | + { |
|
113 | + if ($id) { |
|
114 | + if ($locator = self::get()->byID($id)) { |
|
115 | + return $locator->Categories(); |
|
116 | + } |
|
117 | + |
|
118 | + return false; |
|
119 | + } |
|
120 | + |
|
121 | + return false; |
|
122 | + } |
|
123 | 123 | |
124 | 124 | |
125 | 125 | } |
126 | 126 | |
127 | 127 | class Locator_Controller extends Page_Controller |
128 | 128 | { |
129 | - /** |
|
130 | - * @var array |
|
131 | - */ |
|
132 | - private static $allowed_actions = array( |
|
133 | - 'xml', |
|
134 | - ); |
|
135 | - |
|
136 | - /** |
|
137 | - * Set Requirements based on input from CMS |
|
138 | - */ |
|
139 | - public function init() |
|
140 | - { |
|
141 | - parent::init(); |
|
142 | - |
|
143 | - $themeDir = SSViewer::get_theme_folder(); |
|
144 | - |
|
145 | - // google maps api key |
|
146 | - $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
147 | - |
|
148 | - $locations = $this->Items($this->request); |
|
149 | - |
|
150 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
151 | - if ($locations) { |
|
152 | - Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
153 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
154 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
155 | - } |
|
156 | - |
|
157 | - Requirements::css('locator/css/map.css'); |
|
158 | - |
|
159 | - $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
160 | - |
|
161 | - $featured = $featuredInList |
|
162 | - ? 'featuredLocations: true' |
|
163 | - : 'featuredLocations: false'; |
|
164 | - |
|
165 | - // map config based on user input in Settings tab |
|
166 | - // AutoGeocode or Full Map |
|
167 | - if ($this->data()->AutoGeocode) { |
|
168 | - $load = $featuredInList |
|
169 | - ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
170 | - : 'autoGeocode: true, fullMapStart: false,'; |
|
171 | - } else { |
|
172 | - $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
173 | - } |
|
174 | - |
|
175 | - /*$load = ($this->data()->AutoGeocode) ? |
|
129 | + /** |
|
130 | + * @var array |
|
131 | + */ |
|
132 | + private static $allowed_actions = array( |
|
133 | + 'xml', |
|
134 | + ); |
|
135 | + |
|
136 | + /** |
|
137 | + * Set Requirements based on input from CMS |
|
138 | + */ |
|
139 | + public function init() |
|
140 | + { |
|
141 | + parent::init(); |
|
142 | + |
|
143 | + $themeDir = SSViewer::get_theme_folder(); |
|
144 | + |
|
145 | + // google maps api key |
|
146 | + $key = Config::inst()->get('GoogleGeocoding', 'google_api_key'); |
|
147 | + |
|
148 | + $locations = $this->Items($this->request); |
|
149 | + |
|
150 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
151 | + if ($locations) { |
|
152 | + Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
153 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
154 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
155 | + } |
|
156 | + |
|
157 | + Requirements::css('locator/css/map.css'); |
|
158 | + |
|
159 | + $featuredInList = ($locations->filter('Featured', true)->count() > 0); |
|
160 | + |
|
161 | + $featured = $featuredInList |
|
162 | + ? 'featuredLocations: true' |
|
163 | + : 'featuredLocations: false'; |
|
164 | + |
|
165 | + // map config based on user input in Settings tab |
|
166 | + // AutoGeocode or Full Map |
|
167 | + if ($this->data()->AutoGeocode) { |
|
168 | + $load = $featuredInList |
|
169 | + ? 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,' |
|
170 | + : 'autoGeocode: true, fullMapStart: false,'; |
|
171 | + } else { |
|
172 | + $load = 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
173 | + } |
|
174 | + |
|
175 | + /*$load = ($this->data()->AutoGeocode) ? |
|
176 | 176 | 'autoGeocode: true, fullMapStart: false,' : |
177 | 177 | 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';*/ |
178 | 178 | |
179 | - $base = Director::baseFolder(); |
|
180 | - $themePath = $base . '/' . $themeDir; |
|
181 | - |
|
182 | - $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
183 | - $themeDir . '/templates/location-list-description.html' : |
|
184 | - 'locator/templates/location-list-description.html'; |
|
185 | - $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
186 | - $themeDir . '/templates/infowindow-description.html' : |
|
187 | - 'locator/templates/infowindow-description.html'; |
|
188 | - |
|
189 | - // in page or modal |
|
190 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
191 | - |
|
192 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
193 | - |
|
194 | - // pass GET variables to xml action |
|
195 | - $vars = $this->request->getVars(); |
|
196 | - unset($vars['url']); |
|
197 | - unset($vars['action_index']); |
|
198 | - $url = ''; |
|
199 | - if (count($vars)) { |
|
200 | - $url .= '?' . http_build_query($vars); |
|
201 | - } |
|
202 | - $link = $this->Link() . 'xml.xml' . $url; |
|
203 | - |
|
204 | - // init map |
|
205 | - if ($locations) { |
|
206 | - Requirements::customScript(" |
|
179 | + $base = Director::baseFolder(); |
|
180 | + $themePath = $base . '/' . $themeDir; |
|
181 | + |
|
182 | + $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
183 | + $themeDir . '/templates/location-list-description.html' : |
|
184 | + 'locator/templates/location-list-description.html'; |
|
185 | + $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
186 | + $themeDir . '/templates/infowindow-description.html' : |
|
187 | + 'locator/templates/infowindow-description.html'; |
|
188 | + |
|
189 | + // in page or modal |
|
190 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
191 | + |
|
192 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
193 | + |
|
194 | + // pass GET variables to xml action |
|
195 | + $vars = $this->request->getVars(); |
|
196 | + unset($vars['url']); |
|
197 | + unset($vars['action_index']); |
|
198 | + $url = ''; |
|
199 | + if (count($vars)) { |
|
200 | + $url .= '?' . http_build_query($vars); |
|
201 | + } |
|
202 | + $link = $this->Link() . 'xml.xml' . $url; |
|
203 | + |
|
204 | + // init map |
|
205 | + if ($locations) { |
|
206 | + Requirements::customScript(" |
|
207 | 207 | $(function($) { |
208 | 208 | $('#map-container').storeLocator({ |
209 | 209 | " . $load . " |
@@ -224,135 +224,135 @@ discard block |
||
224 | 224 | }); |
225 | 225 | }); |
226 | 226 | '); |
227 | - } |
|
228 | - } |
|
229 | - |
|
230 | - /** |
|
231 | - * @param SS_HTTPRequest $request |
|
232 | - * |
|
233 | - * @return ViewableData_Customised |
|
234 | - */ |
|
235 | - public function index(SS_HTTPRequest $request) |
|
236 | - { |
|
237 | - $locations = $this->Items($request); |
|
238 | - |
|
239 | - return $this->customise(array( |
|
240 | - 'Locations' => $locations, |
|
241 | - )); |
|
242 | - } |
|
243 | - |
|
244 | - /** |
|
245 | - * Return a XML feed of all locations marked "show in locator" |
|
246 | - * |
|
247 | - * @param SS_HTTPRequest $request |
|
248 | - * @return HTMLText |
|
249 | - */ |
|
250 | - public function xml(SS_HTTPRequest $request) |
|
251 | - { |
|
252 | - $locations = $this->Items($request); |
|
253 | - |
|
254 | - return $this->customise(array( |
|
255 | - 'Locations' => $locations, |
|
256 | - ))->renderWith('LocationXML'); |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * @param SS_HTTPRequest $request |
|
261 | - * |
|
262 | - * @return ArrayList |
|
263 | - */ |
|
264 | - public function Items(SS_HTTPRequest $request) |
|
265 | - { |
|
266 | - $request = ($request) ? $request : $this->request; |
|
267 | - |
|
268 | - $filter = array(); |
|
269 | - $filterAny = array(); |
|
270 | - $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
271 | - |
|
272 | - // only show locations marked as ShowInLocator |
|
273 | - $filter['ShowInLocator'] = 1; |
|
274 | - |
|
275 | - // search across all address related fields |
|
276 | - $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
277 | - if ($address && $this->data()->AutoGeocode == 0) { |
|
278 | - $filterAny['Address:PartialMatch'] = $address; |
|
279 | - $filterAny['Suburb:PartialMatch'] = $address; |
|
280 | - $filterAny['State:PartialMatch'] = $address; |
|
281 | - $filterAny['Postcode:PartialMatch'] = $address; |
|
282 | - $filterAny['Country:PartialMatch'] = $address; |
|
283 | - } else { |
|
284 | - unset($filter['Address']); |
|
285 | - } |
|
286 | - |
|
287 | - // search for category from form, else categories from Locator |
|
288 | - $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
289 | - if ($category) { |
|
290 | - $filter['CategoryID:ExactMatch'] = $category; |
|
291 | - } elseif ($this->Categories()->exists()) { |
|
292 | - $categories = $this->Categories(); |
|
293 | - $categoryArray = array(); |
|
294 | - foreach ($categories as $category) { |
|
295 | - array_push($categoryArray, $category->ID); |
|
296 | - } |
|
297 | - $filter['CategoryID'] = $categoryArray; |
|
298 | - } |
|
299 | - |
|
300 | - $locations = Locator::locations($filter, $filterAny, $exclude); |
|
301 | - |
|
302 | - return $locations; |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * LocationSearch form. |
|
307 | - * |
|
308 | - * Search form for locations, updates map and results list via AJAX |
|
309 | - * |
|
310 | - * @return Form |
|
311 | - */ |
|
312 | - public function LocationSearch() |
|
313 | - { |
|
314 | - $fields = FieldList::create( |
|
315 | - $address = TextField::create('Address', '') |
|
316 | - ->setAttribute('placeholder', 'address or zip code') |
|
317 | - ); |
|
318 | - |
|
319 | - $filterCategories = Locator::getPageCategories($this->ID); |
|
320 | - $allCategories = Locator::getAllCategories(); |
|
321 | - |
|
322 | - if ($allCategories->Count() > 0) { |
|
323 | - $categories = ArrayList::create(); |
|
324 | - if ($filterCategories->Count() > 0) { |
|
325 | - if ($filterCategories->Count() != 1) { |
|
326 | - $categories = $filterCategories; |
|
327 | - } |
|
328 | - } else { |
|
329 | - $categories = $allCategories; |
|
330 | - } |
|
331 | - |
|
332 | - if ($categories->count() > 0) { |
|
333 | - $fields->push( |
|
334 | - DropdownField::create( |
|
335 | - 'CategoryID', |
|
336 | - '', |
|
337 | - $categories->map() |
|
338 | - )->setEmptyString('All Categories')); |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - $actions = FieldList::create( |
|
343 | - FormAction::create('index', 'Search') |
|
344 | - ); |
|
345 | - |
|
346 | - if (class_exists('BootstrapForm')) { |
|
347 | - $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
348 | - } else { |
|
349 | - $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
350 | - } |
|
351 | - |
|
352 | - return $form |
|
353 | - ->setFormMethod('GET') |
|
354 | - ->setFormAction($this->Link()) |
|
355 | - ->disableSecurityToken() |
|
356 | - ->loadDataFrom($this->request->getVars()); |
|
357 | - } |
|
227 | + } |
|
228 | + } |
|
229 | + |
|
230 | + /** |
|
231 | + * @param SS_HTTPRequest $request |
|
232 | + * |
|
233 | + * @return ViewableData_Customised |
|
234 | + */ |
|
235 | + public function index(SS_HTTPRequest $request) |
|
236 | + { |
|
237 | + $locations = $this->Items($request); |
|
238 | + |
|
239 | + return $this->customise(array( |
|
240 | + 'Locations' => $locations, |
|
241 | + )); |
|
242 | + } |
|
243 | + |
|
244 | + /** |
|
245 | + * Return a XML feed of all locations marked "show in locator" |
|
246 | + * |
|
247 | + * @param SS_HTTPRequest $request |
|
248 | + * @return HTMLText |
|
249 | + */ |
|
250 | + public function xml(SS_HTTPRequest $request) |
|
251 | + { |
|
252 | + $locations = $this->Items($request); |
|
253 | + |
|
254 | + return $this->customise(array( |
|
255 | + 'Locations' => $locations, |
|
256 | + ))->renderWith('LocationXML'); |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * @param SS_HTTPRequest $request |
|
261 | + * |
|
262 | + * @return ArrayList |
|
263 | + */ |
|
264 | + public function Items(SS_HTTPRequest $request) |
|
265 | + { |
|
266 | + $request = ($request) ? $request : $this->request; |
|
267 | + |
|
268 | + $filter = array(); |
|
269 | + $filterAny = array(); |
|
270 | + $exclude = ['Lat' => 0.00000, 'Lng' => 0.00000]; |
|
271 | + |
|
272 | + // only show locations marked as ShowInLocator |
|
273 | + $filter['ShowInLocator'] = 1; |
|
274 | + |
|
275 | + // search across all address related fields |
|
276 | + $address = ($request->getVar('Address')) ? $request->getVar('Address') : false; |
|
277 | + if ($address && $this->data()->AutoGeocode == 0) { |
|
278 | + $filterAny['Address:PartialMatch'] = $address; |
|
279 | + $filterAny['Suburb:PartialMatch'] = $address; |
|
280 | + $filterAny['State:PartialMatch'] = $address; |
|
281 | + $filterAny['Postcode:PartialMatch'] = $address; |
|
282 | + $filterAny['Country:PartialMatch'] = $address; |
|
283 | + } else { |
|
284 | + unset($filter['Address']); |
|
285 | + } |
|
286 | + |
|
287 | + // search for category from form, else categories from Locator |
|
288 | + $category = ($request->getVar('CategoryID')) ? $request->getVar('CategoryID') : false; |
|
289 | + if ($category) { |
|
290 | + $filter['CategoryID:ExactMatch'] = $category; |
|
291 | + } elseif ($this->Categories()->exists()) { |
|
292 | + $categories = $this->Categories(); |
|
293 | + $categoryArray = array(); |
|
294 | + foreach ($categories as $category) { |
|
295 | + array_push($categoryArray, $category->ID); |
|
296 | + } |
|
297 | + $filter['CategoryID'] = $categoryArray; |
|
298 | + } |
|
299 | + |
|
300 | + $locations = Locator::locations($filter, $filterAny, $exclude); |
|
301 | + |
|
302 | + return $locations; |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * LocationSearch form. |
|
307 | + * |
|
308 | + * Search form for locations, updates map and results list via AJAX |
|
309 | + * |
|
310 | + * @return Form |
|
311 | + */ |
|
312 | + public function LocationSearch() |
|
313 | + { |
|
314 | + $fields = FieldList::create( |
|
315 | + $address = TextField::create('Address', '') |
|
316 | + ->setAttribute('placeholder', 'address or zip code') |
|
317 | + ); |
|
318 | + |
|
319 | + $filterCategories = Locator::getPageCategories($this->ID); |
|
320 | + $allCategories = Locator::getAllCategories(); |
|
321 | + |
|
322 | + if ($allCategories->Count() > 0) { |
|
323 | + $categories = ArrayList::create(); |
|
324 | + if ($filterCategories->Count() > 0) { |
|
325 | + if ($filterCategories->Count() != 1) { |
|
326 | + $categories = $filterCategories; |
|
327 | + } |
|
328 | + } else { |
|
329 | + $categories = $allCategories; |
|
330 | + } |
|
331 | + |
|
332 | + if ($categories->count() > 0) { |
|
333 | + $fields->push( |
|
334 | + DropdownField::create( |
|
335 | + 'CategoryID', |
|
336 | + '', |
|
337 | + $categories->map() |
|
338 | + )->setEmptyString('All Categories')); |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + $actions = FieldList::create( |
|
343 | + FormAction::create('index', 'Search') |
|
344 | + ); |
|
345 | + |
|
346 | + if (class_exists('BootstrapForm')) { |
|
347 | + $form = BootstrapForm::create($this, 'LocationSearch', $fields, $actions); |
|
348 | + } else { |
|
349 | + $form = Form::create($this, 'LocationSearch', $fields, $actions); |
|
350 | + } |
|
351 | + |
|
352 | + return $form |
|
353 | + ->setFormMethod('GET') |
|
354 | + ->setFormAction($this->Link()) |
|
355 | + ->disableSecurityToken() |
|
356 | + ->loadDataFrom($this->request->getVars()); |
|
357 | + } |
|
358 | 358 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
151 | 151 | if ($locations) { |
152 | - Requirements::javascript('http://maps.google.com/maps/api/js?key=' . $key); |
|
152 | + Requirements::javascript('http://maps.google.com/maps/api/js?key='.$key); |
|
153 | 153 | Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
154 | 154 | Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
155 | 155 | } |
@@ -177,14 +177,12 @@ discard block |
||
177 | 177 | 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';*/ |
178 | 178 | |
179 | 179 | $base = Director::baseFolder(); |
180 | - $themePath = $base . '/' . $themeDir; |
|
180 | + $themePath = $base.'/'.$themeDir; |
|
181 | 181 | |
182 | - $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
183 | - $themeDir . '/templates/location-list-description.html' : |
|
184 | - 'locator/templates/location-list-description.html'; |
|
185 | - $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
186 | - $themeDir . '/templates/infowindow-description.html' : |
|
187 | - 'locator/templates/infowindow-description.html'; |
|
182 | + $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
183 | + $themeDir.'/templates/location-list-description.html' : 'locator/templates/location-list-description.html'; |
|
184 | + $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
185 | + $themeDir.'/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html'; |
|
188 | 186 | |
189 | 187 | // in page or modal |
190 | 188 | $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
@@ -197,22 +195,22 @@ discard block |
||
197 | 195 | unset($vars['action_index']); |
198 | 196 | $url = ''; |
199 | 197 | if (count($vars)) { |
200 | - $url .= '?' . http_build_query($vars); |
|
198 | + $url .= '?'.http_build_query($vars); |
|
201 | 199 | } |
202 | - $link = $this->Link() . 'xml.xml' . $url; |
|
200 | + $link = $this->Link().'xml.xml'.$url; |
|
203 | 201 | |
204 | 202 | // init map |
205 | 203 | if ($locations) { |
206 | 204 | Requirements::customScript(" |
207 | 205 | $(function($) { |
208 | 206 | $('#map-container').storeLocator({ |
209 | - " . $load . " |
|
210 | - dataLocation: '" . $link . "', |
|
211 | - listTemplatePath: '" . $listTemplatePath . "', |
|
212 | - infowindowTemplatePath: '" . $infowindowTemplatePath . "', |
|
207 | + " . $load." |
|
208 | + dataLocation: '" . $link."', |
|
209 | + listTemplatePath: '" . $listTemplatePath."', |
|
210 | + infowindowTemplatePath: '" . $infowindowTemplatePath."', |
|
213 | 211 | originMarker: true, |
214 | - " . $modal . ', |
|
215 | - ' . $featured . ", |
|
212 | + " . $modal.', |
|
213 | + ' . $featured.", |
|
216 | 214 | slideMap: false, |
217 | 215 | zoomLevel: 0, |
218 | 216 | noForm: true, |
@@ -220,7 +218,7 @@ discard block |
||
220 | 218 | inputID: 'Form_LocationSearch_Address', |
221 | 219 | categoryID: 'Form_LocationSearch_category', |
222 | 220 | distanceAlert: -1, |
223 | - " . $kilometer . ' |
|
221 | + " . $kilometer.' |
|
224 | 222 | }); |
225 | 223 | }); |
226 | 224 | '); |