@@ -2,200 +2,200 @@ |
||
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 | - public function getCustomSearchContext() |
|
142 | - { |
|
143 | - $fields = $this->scaffoldSearchFields(array( |
|
144 | - 'restrictFields' => array('Address','Category.ID') |
|
145 | - )); |
|
146 | - |
|
147 | - $filters = array( |
|
148 | - 'Address' => new PartialMatchFilter('Address'), |
|
149 | - 'Suburb' => new PartialMatchFilter('Suburb'), |
|
150 | - 'State' => new PartialMatchFilter('State'), |
|
151 | - 'Postcode' => new PartialMatchFilter('Postcode'), |
|
152 | - 'Country' => new PartialMatchFilter('Postcode'), |
|
153 | - 'CategoryID' => new ExactMatchFilter('CategoryID'), |
|
154 | - ); |
|
155 | - |
|
156 | - return new SearchContext( |
|
157 | - $this->class, |
|
158 | - $fields, |
|
159 | - $filters |
|
160 | - ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * @param Member $member |
|
165 | - * |
|
166 | - * @return bool |
|
167 | - */ |
|
168 | - public function canView($member = false) |
|
169 | - { |
|
170 | - return true; |
|
171 | - } |
|
172 | - |
|
173 | - public function canEdit($member = false) |
|
174 | - { |
|
175 | - return Permission::check('Location_EDIT'); |
|
176 | - } |
|
177 | - |
|
178 | - public function canDelete($member = false) |
|
179 | - { |
|
180 | - return Permission::check('Location_DELETE'); |
|
181 | - } |
|
182 | - |
|
183 | - public function canCreate($member = false) |
|
184 | - { |
|
185 | - return Permission::check('Location_CREATE'); |
|
186 | - } |
|
187 | - |
|
188 | - public function providePermissions() |
|
189 | - { |
|
190 | - return array( |
|
191 | - 'Location_EDIT' => 'Edit a Location', |
|
192 | - 'Location_DELETE' => 'Delete a Location', |
|
193 | - 'Location_CREATE' => 'Create a Location', |
|
194 | - ); |
|
195 | - } |
|
196 | - |
|
197 | - public function onBeforeWrite() |
|
198 | - { |
|
199 | - parent::onBeforeWrite(); |
|
200 | - } |
|
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 | + public function getCustomSearchContext() |
|
142 | + { |
|
143 | + $fields = $this->scaffoldSearchFields(array( |
|
144 | + 'restrictFields' => array('Address','Category.ID') |
|
145 | + )); |
|
146 | + |
|
147 | + $filters = array( |
|
148 | + 'Address' => new PartialMatchFilter('Address'), |
|
149 | + 'Suburb' => new PartialMatchFilter('Suburb'), |
|
150 | + 'State' => new PartialMatchFilter('State'), |
|
151 | + 'Postcode' => new PartialMatchFilter('Postcode'), |
|
152 | + 'Country' => new PartialMatchFilter('Postcode'), |
|
153 | + 'CategoryID' => new ExactMatchFilter('CategoryID'), |
|
154 | + ); |
|
155 | + |
|
156 | + return new SearchContext( |
|
157 | + $this->class, |
|
158 | + $fields, |
|
159 | + $filters |
|
160 | + ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * @param Member $member |
|
165 | + * |
|
166 | + * @return bool |
|
167 | + */ |
|
168 | + public function canView($member = false) |
|
169 | + { |
|
170 | + return true; |
|
171 | + } |
|
172 | + |
|
173 | + public function canEdit($member = false) |
|
174 | + { |
|
175 | + return Permission::check('Location_EDIT'); |
|
176 | + } |
|
177 | + |
|
178 | + public function canDelete($member = false) |
|
179 | + { |
|
180 | + return Permission::check('Location_DELETE'); |
|
181 | + } |
|
182 | + |
|
183 | + public function canCreate($member = false) |
|
184 | + { |
|
185 | + return Permission::check('Location_CREATE'); |
|
186 | + } |
|
187 | + |
|
188 | + public function providePermissions() |
|
189 | + { |
|
190 | + return array( |
|
191 | + 'Location_EDIT' => 'Edit a Location', |
|
192 | + 'Location_DELETE' => 'Delete a Location', |
|
193 | + 'Location_CREATE' => 'Create a Location', |
|
194 | + ); |
|
195 | + } |
|
196 | + |
|
197 | + public function onBeforeWrite() |
|
198 | + { |
|
199 | + parent::onBeforeWrite(); |
|
200 | + } |
|
201 | 201 | } |
@@ -141,7 +141,7 @@ |
||
141 | 141 | public function getCustomSearchContext() |
142 | 142 | { |
143 | 143 | $fields = $this->scaffoldSearchFields(array( |
144 | - 'restrictFields' => array('Address','Category.ID') |
|
144 | + 'restrictFields' => array('Address', 'Category.ID') |
|
145 | 145 | )); |
146 | 146 | |
147 | 147 | $filters = array( |
@@ -2,146 +2,146 @@ 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 | - public function getCMSFields() |
|
24 | - { |
|
25 | - $fields = parent::getCMSFields(); |
|
26 | - |
|
27 | - // Settings |
|
28 | - $fields->addFieldsToTab('Root.Settings', array( |
|
29 | - HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
30 | - OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
31 | - CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
32 | - ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
33 | - CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
34 | - )); |
|
35 | - |
|
36 | - // Filter categories |
|
37 | - $config = GridFieldConfig_RelationEditor::create(); |
|
38 | - if (class_exists('GridFieldAddExistingSearchButton')) { |
|
39 | - $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
40 | - $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
41 | - } |
|
42 | - $categories = $this->Categories(); |
|
43 | - $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
44 | - ->setDescription('only show locations from the selected category'); |
|
45 | - |
|
46 | - // Filter |
|
47 | - $fields->addFieldsToTab('Root.Filter', array( |
|
48 | - HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
49 | - $categoriesField, |
|
50 | - )); |
|
51 | - |
|
52 | - $this->extend('updateCMSFields', $fields); |
|
53 | - |
|
54 | - return $fields; |
|
55 | - } |
|
56 | - |
|
57 | - public static function getLocations($filter = array(), $exclude = array(), $filterAny = array()) |
|
58 | - { |
|
59 | - $filter['ShowInLocator'] = true; |
|
60 | - $exclude['Lat'] = 0; |
|
61 | - |
|
62 | - $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny); |
|
63 | - |
|
64 | - return $Locations; |
|
65 | - } |
|
66 | - |
|
67 | - public function getAreLocations() |
|
68 | - { |
|
69 | - return self::getLocations(); |
|
70 | - } |
|
71 | - |
|
72 | - public function getAllCategories() |
|
73 | - { |
|
74 | - return LocationCategory::get(); |
|
75 | - } |
|
76 | - |
|
77 | - public static function getPageCategories($id = null) |
|
78 | - { |
|
79 | - if ($id) { |
|
80 | - if ($locator = self::get()->byID($id)) { |
|
81 | - return $locator->Categories(); |
|
82 | - } |
|
83 | - |
|
84 | - return false; |
|
85 | - } |
|
86 | - |
|
87 | - return false; |
|
88 | - } |
|
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 | + public function getCMSFields() |
|
24 | + { |
|
25 | + $fields = parent::getCMSFields(); |
|
26 | + |
|
27 | + // Settings |
|
28 | + $fields->addFieldsToTab('Root.Settings', array( |
|
29 | + HeaderField::create('DisplayOptions', 'Display Options', 3), |
|
30 | + OptionsetField::create('Unit', 'Unit of measure', array('m' => 'Miles', 'km' => 'Kilometers')), |
|
31 | + CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location') |
|
32 | + ->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'), |
|
33 | + CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window'), |
|
34 | + )); |
|
35 | + |
|
36 | + // Filter categories |
|
37 | + $config = GridFieldConfig_RelationEditor::create(); |
|
38 | + if (class_exists('GridFieldAddExistingSearchButton')) { |
|
39 | + $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
|
40 | + $config->addComponent(new GridFieldAddExistingSearchButton()); |
|
41 | + } |
|
42 | + $categories = $this->Categories(); |
|
43 | + $categoriesField = GridField::create('Categories', 'Categories', $categories, $config) |
|
44 | + ->setDescription('only show locations from the selected category'); |
|
45 | + |
|
46 | + // Filter |
|
47 | + $fields->addFieldsToTab('Root.Filter', array( |
|
48 | + HeaderField::create('CategoryOptionsHeader', 'Location Filtering', 3), |
|
49 | + $categoriesField, |
|
50 | + )); |
|
51 | + |
|
52 | + $this->extend('updateCMSFields', $fields); |
|
53 | + |
|
54 | + return $fields; |
|
55 | + } |
|
56 | + |
|
57 | + public static function getLocations($filter = array(), $exclude = array(), $filterAny = array()) |
|
58 | + { |
|
59 | + $filter['ShowInLocator'] = true; |
|
60 | + $exclude['Lat'] = 0; |
|
61 | + |
|
62 | + $Locations = Location::get()->exclude($exclude)->filter($filter)->filterAny($filterAny); |
|
63 | + |
|
64 | + return $Locations; |
|
65 | + } |
|
66 | + |
|
67 | + public function getAreLocations() |
|
68 | + { |
|
69 | + return self::getLocations(); |
|
70 | + } |
|
71 | + |
|
72 | + public function getAllCategories() |
|
73 | + { |
|
74 | + return LocationCategory::get(); |
|
75 | + } |
|
76 | + |
|
77 | + public static function getPageCategories($id = null) |
|
78 | + { |
|
79 | + if ($id) { |
|
80 | + if ($locator = self::get()->byID($id)) { |
|
81 | + return $locator->Categories(); |
|
82 | + } |
|
83 | + |
|
84 | + return false; |
|
85 | + } |
|
86 | + |
|
87 | + return false; |
|
88 | + } |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | class Locator_Controller extends Page_Controller |
92 | 92 | { |
93 | - // allowed actions |
|
94 | - private static $allowed_actions = array( |
|
95 | - 'xml', |
|
96 | - 'LocationSearch', |
|
97 | - ); |
|
98 | - |
|
99 | - // Set Requirements based on input from CMS |
|
100 | - public function init() |
|
101 | - { |
|
102 | - parent::init(); |
|
103 | - |
|
104 | - $themeDir = SSViewer::get_theme_folder(); |
|
105 | - |
|
106 | - Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
107 | - if (Locator::getLocations()) { |
|
108 | - Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false'); |
|
109 | - Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
110 | - Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
111 | - } |
|
112 | - |
|
113 | - Requirements::css('locator/css/map.css'); |
|
114 | - |
|
115 | - $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
|
116 | - 'featuredLocations: true' : |
|
117 | - 'featuredLocations: false'; |
|
118 | - |
|
119 | - // map config based on user input in Settings tab |
|
120 | - // AutoGeocode or Full Map |
|
121 | - $load = ($this->data()->AutoGeocode) ? |
|
122 | - 'autoGeocode: true, fullMapStart: false,' : |
|
123 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
124 | - |
|
125 | - $base = Director::baseFolder(); |
|
126 | - $themePath = $base.'/'.$themeDir; |
|
127 | - |
|
128 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
129 | - $themeDir.'/templates/location-list-description.html' : |
|
130 | - 'locator/templates/location-list-description.html'; |
|
131 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
132 | - $themeDir.'/templates/infowindow-description.html' : |
|
133 | - 'locator/templates/infowindow-description.html'; |
|
134 | - |
|
135 | - // in page or modal |
|
136 | - $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
137 | - |
|
138 | - $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
139 | - |
|
140 | - $link = $this->Link().'xml.xml'; |
|
141 | - |
|
142 | - // init map |
|
143 | - if (Locator::getLocations()) { |
|
144 | - Requirements::customScript(" |
|
93 | + // allowed actions |
|
94 | + private static $allowed_actions = array( |
|
95 | + 'xml', |
|
96 | + 'LocationSearch', |
|
97 | + ); |
|
98 | + |
|
99 | + // Set Requirements based on input from CMS |
|
100 | + public function init() |
|
101 | + { |
|
102 | + parent::init(); |
|
103 | + |
|
104 | + $themeDir = SSViewer::get_theme_folder(); |
|
105 | + |
|
106 | + Requirements::javascript('framework/thirdparty/jquery/jquery.js'); |
|
107 | + if (Locator::getLocations()) { |
|
108 | + Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false'); |
|
109 | + Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js'); |
|
110 | + Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js'); |
|
111 | + } |
|
112 | + |
|
113 | + Requirements::css('locator/css/map.css'); |
|
114 | + |
|
115 | + $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
|
116 | + 'featuredLocations: true' : |
|
117 | + 'featuredLocations: false'; |
|
118 | + |
|
119 | + // map config based on user input in Settings tab |
|
120 | + // AutoGeocode or Full Map |
|
121 | + $load = ($this->data()->AutoGeocode) ? |
|
122 | + 'autoGeocode: true, fullMapStart: false,' : |
|
123 | + 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
124 | + |
|
125 | + $base = Director::baseFolder(); |
|
126 | + $themePath = $base.'/'.$themeDir; |
|
127 | + |
|
128 | + $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
129 | + $themeDir.'/templates/location-list-description.html' : |
|
130 | + 'locator/templates/location-list-description.html'; |
|
131 | + $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
132 | + $themeDir.'/templates/infowindow-description.html' : |
|
133 | + 'locator/templates/infowindow-description.html'; |
|
134 | + |
|
135 | + // in page or modal |
|
136 | + $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
|
137 | + |
|
138 | + $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
|
139 | + |
|
140 | + $link = $this->Link().'xml.xml'; |
|
141 | + |
|
142 | + // init map |
|
143 | + if (Locator::getLocations()) { |
|
144 | + Requirements::customScript(" |
|
145 | 145 | $(function($) { |
146 | 146 | $('#map-container').storeLocator({ |
147 | 147 | ".$load." |
@@ -163,117 +163,117 @@ discard block |
||
163 | 163 | }); |
164 | 164 | }); |
165 | 165 | '); |
166 | - } |
|
167 | - } |
|
168 | - |
|
169 | - public function index(SS_HTTPRequest $request) |
|
170 | - { |
|
171 | - |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param array $searchCriteria |
|
176 | - * @return mixed |
|
177 | - */ |
|
178 | - public function Items($searchCriteria = array()) |
|
179 | - { |
|
180 | - $request = ($this->request) ? $this->request : $this->parentController->getRequest(); |
|
181 | - if(empty($searchCriteria)) $searchCriteria = $request->requestVars(); |
|
182 | - |
|
183 | - //if category filters are selected on Locator |
|
184 | - $filterAny = array(); |
|
185 | - if ($this->Categories()->exists() && !isset($searchCriteria['CategoryID'])) { |
|
186 | - $categories = $this->Categories(); |
|
187 | - foreach ($categories as $category) { |
|
188 | - $filterAny['CategoryID'] = $category->ID; |
|
189 | - } |
|
190 | - $searchCriteria['filterAny'] = $filterAny; |
|
191 | - } |
|
192 | - |
|
193 | - // if address field has value, check against all address fields |
|
194 | - |
|
195 | - |
|
196 | - $context = (method_exists('Location', 'getCustomSearchContext')) ? singleton('Location')->getCustomSearchContext() : singleton('Location')->getDefaultSearchContext(); |
|
197 | - $records = $context->getResults($searchCriteria); |
|
198 | - |
|
199 | - return $records; |
|
200 | - } |
|
201 | - |
|
202 | - /** |
|
203 | - * Find all locations for map. |
|
204 | - * |
|
205 | - * Will return a XML feed of all locations marked "show in locator". |
|
206 | - * |
|
207 | - * @return XML file |
|
208 | - * |
|
209 | - * @todo rename/refactor to allow for json/xml |
|
210 | - * @todo allow $filter to run off of getVars key/val pair |
|
211 | - */ |
|
212 | - public function xml() |
|
213 | - { |
|
214 | - return $this->customise(array( |
|
215 | - 'Locations' => $this->Items(), |
|
216 | - ))->renderWith('LocationXML'); |
|
217 | - } |
|
218 | - |
|
219 | - /** |
|
220 | - * LocationSearch form. |
|
221 | - * |
|
222 | - * Search form for locations, updates map and results list via AJAX |
|
223 | - * |
|
224 | - * @return Form |
|
225 | - */ |
|
226 | - public function LocationSearch() |
|
227 | - { |
|
228 | - $fields = FieldList::create( |
|
229 | - $address = TextField::create('location', '') |
|
230 | - ->setAttribute('placeholder', 'address or zip code') |
|
231 | - ); |
|
232 | - |
|
233 | - $locatorCategories = Locator::getPageCategories($this->ID); |
|
234 | - |
|
235 | - if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) { |
|
236 | - |
|
237 | - $ct = $locatorCategories->Count(); |
|
238 | - |
|
239 | - if ($ct > 0 && $ct != 1) { |
|
240 | - $categories = $locatorCategories; |
|
241 | - } else { |
|
242 | - $categories = LocationCategory::get(); |
|
243 | - } |
|
244 | - |
|
245 | - if ($categories->count() > 0) { |
|
246 | - $fields->push( |
|
247 | - DropdownField::create( |
|
248 | - 'CategoryID', |
|
249 | - '', |
|
250 | - $categories->map() |
|
251 | - )->setEmptyString('Select Category')); |
|
252 | - } |
|
253 | - } |
|
254 | - |
|
255 | - $actions = FieldList::create( |
|
256 | - FormAction::create('doSearch', 'Search') |
|
257 | - ); |
|
258 | - |
|
259 | - return Form::create($this, 'LocationSearch', $fields, $actions) |
|
260 | - ->setFormMethod('get'); |
|
261 | - } |
|
262 | - |
|
263 | - // Results filtered by query |
|
264 | - function doSearch($data, $form, $request) |
|
265 | - { |
|
266 | - if (isset($data['location'])) { |
|
267 | - $location = $data['location']; |
|
268 | - $data['Address'] = $location; |
|
269 | - $data['Suburb'] = $location; |
|
270 | - $data['State'] = $location; |
|
271 | - $data['Postcode'] = $location; |
|
272 | - $data['Country'] = $location; |
|
273 | - } |
|
274 | - return $this->render(array( |
|
275 | - 'Items' => $this->Items($data), |
|
276 | - 'AdvSearchForm' => $form |
|
277 | - )); |
|
278 | - } |
|
166 | + } |
|
167 | + } |
|
168 | + |
|
169 | + public function index(SS_HTTPRequest $request) |
|
170 | + { |
|
171 | + |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param array $searchCriteria |
|
176 | + * @return mixed |
|
177 | + */ |
|
178 | + public function Items($searchCriteria = array()) |
|
179 | + { |
|
180 | + $request = ($this->request) ? $this->request : $this->parentController->getRequest(); |
|
181 | + if(empty($searchCriteria)) $searchCriteria = $request->requestVars(); |
|
182 | + |
|
183 | + //if category filters are selected on Locator |
|
184 | + $filterAny = array(); |
|
185 | + if ($this->Categories()->exists() && !isset($searchCriteria['CategoryID'])) { |
|
186 | + $categories = $this->Categories(); |
|
187 | + foreach ($categories as $category) { |
|
188 | + $filterAny['CategoryID'] = $category->ID; |
|
189 | + } |
|
190 | + $searchCriteria['filterAny'] = $filterAny; |
|
191 | + } |
|
192 | + |
|
193 | + // if address field has value, check against all address fields |
|
194 | + |
|
195 | + |
|
196 | + $context = (method_exists('Location', 'getCustomSearchContext')) ? singleton('Location')->getCustomSearchContext() : singleton('Location')->getDefaultSearchContext(); |
|
197 | + $records = $context->getResults($searchCriteria); |
|
198 | + |
|
199 | + return $records; |
|
200 | + } |
|
201 | + |
|
202 | + /** |
|
203 | + * Find all locations for map. |
|
204 | + * |
|
205 | + * Will return a XML feed of all locations marked "show in locator". |
|
206 | + * |
|
207 | + * @return XML file |
|
208 | + * |
|
209 | + * @todo rename/refactor to allow for json/xml |
|
210 | + * @todo allow $filter to run off of getVars key/val pair |
|
211 | + */ |
|
212 | + public function xml() |
|
213 | + { |
|
214 | + return $this->customise(array( |
|
215 | + 'Locations' => $this->Items(), |
|
216 | + ))->renderWith('LocationXML'); |
|
217 | + } |
|
218 | + |
|
219 | + /** |
|
220 | + * LocationSearch form. |
|
221 | + * |
|
222 | + * Search form for locations, updates map and results list via AJAX |
|
223 | + * |
|
224 | + * @return Form |
|
225 | + */ |
|
226 | + public function LocationSearch() |
|
227 | + { |
|
228 | + $fields = FieldList::create( |
|
229 | + $address = TextField::create('location', '') |
|
230 | + ->setAttribute('placeholder', 'address or zip code') |
|
231 | + ); |
|
232 | + |
|
233 | + $locatorCategories = Locator::getPageCategories($this->ID); |
|
234 | + |
|
235 | + if (LocationCategory::get()->Count() > 0 && $locatorCategories && $locatorCategories->Count() != 1) { |
|
236 | + |
|
237 | + $ct = $locatorCategories->Count(); |
|
238 | + |
|
239 | + if ($ct > 0 && $ct != 1) { |
|
240 | + $categories = $locatorCategories; |
|
241 | + } else { |
|
242 | + $categories = LocationCategory::get(); |
|
243 | + } |
|
244 | + |
|
245 | + if ($categories->count() > 0) { |
|
246 | + $fields->push( |
|
247 | + DropdownField::create( |
|
248 | + 'CategoryID', |
|
249 | + '', |
|
250 | + $categories->map() |
|
251 | + )->setEmptyString('Select Category')); |
|
252 | + } |
|
253 | + } |
|
254 | + |
|
255 | + $actions = FieldList::create( |
|
256 | + FormAction::create('doSearch', 'Search') |
|
257 | + ); |
|
258 | + |
|
259 | + return Form::create($this, 'LocationSearch', $fields, $actions) |
|
260 | + ->setFormMethod('get'); |
|
261 | + } |
|
262 | + |
|
263 | + // Results filtered by query |
|
264 | + function doSearch($data, $form, $request) |
|
265 | + { |
|
266 | + if (isset($data['location'])) { |
|
267 | + $location = $data['location']; |
|
268 | + $data['Address'] = $location; |
|
269 | + $data['Suburb'] = $location; |
|
270 | + $data['State'] = $location; |
|
271 | + $data['Postcode'] = $location; |
|
272 | + $data['Country'] = $location; |
|
273 | + } |
|
274 | + return $this->render(array( |
|
275 | + 'Items' => $this->Items($data), |
|
276 | + 'AdvSearchForm' => $form |
|
277 | + )); |
|
278 | + } |
|
279 | 279 | } |
@@ -113,44 +113,40 @@ discard block |
||
113 | 113 | Requirements::css('locator/css/map.css'); |
114 | 114 | |
115 | 115 | $featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ? |
116 | - 'featuredLocations: true' : |
|
117 | - 'featuredLocations: false'; |
|
116 | + 'featuredLocations: true' : 'featuredLocations: false'; |
|
118 | 117 | |
119 | 118 | // map config based on user input in Settings tab |
120 | 119 | // AutoGeocode or Full Map |
121 | 120 | $load = ($this->data()->AutoGeocode) ? |
122 | - 'autoGeocode: true, fullMapStart: false,' : |
|
123 | - 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
121 | + 'autoGeocode: true, fullMapStart: false,' : 'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,'; |
|
124 | 122 | |
125 | 123 | $base = Director::baseFolder(); |
126 | - $themePath = $base.'/'.$themeDir; |
|
124 | + $themePath = $base . '/' . $themeDir; |
|
127 | 125 | |
128 | - $listTemplatePath = (file_exists($themePath.'/templates/location-list-description.html')) ? |
|
129 | - $themeDir.'/templates/location-list-description.html' : |
|
130 | - 'locator/templates/location-list-description.html'; |
|
131 | - $infowindowTemplatePath = (file_exists($themePath.'/templates/infowindow-description.html')) ? |
|
132 | - $themeDir.'/templates/infowindow-description.html' : |
|
133 | - 'locator/templates/infowindow-description.html'; |
|
126 | + $listTemplatePath = (file_exists($themePath . '/templates/location-list-description.html')) ? |
|
127 | + $themeDir . '/templates/location-list-description.html' : 'locator/templates/location-list-description.html'; |
|
128 | + $infowindowTemplatePath = (file_exists($themePath . '/templates/infowindow-description.html')) ? |
|
129 | + $themeDir . '/templates/infowindow-description.html' : 'locator/templates/infowindow-description.html'; |
|
134 | 130 | |
135 | 131 | // in page or modal |
136 | 132 | $modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false'; |
137 | 133 | |
138 | 134 | $kilometer = ($this->data()->Unit == 'km') ? 'lengthUnit: "km"' : 'lengthUnit: "m"'; |
139 | 135 | |
140 | - $link = $this->Link().'xml.xml'; |
|
136 | + $link = $this->Link() . 'xml.xml'; |
|
141 | 137 | |
142 | 138 | // init map |
143 | 139 | if (Locator::getLocations()) { |
144 | 140 | Requirements::customScript(" |
145 | 141 | $(function($) { |
146 | 142 | $('#map-container').storeLocator({ |
147 | - ".$load." |
|
148 | - dataLocation: '".$link."', |
|
149 | - listTemplatePath: '".$listTemplatePath."', |
|
150 | - infowindowTemplatePath: '".$infowindowTemplatePath."', |
|
143 | + ".$load . " |
|
144 | + dataLocation: '".$link . "', |
|
145 | + listTemplatePath: '".$listTemplatePath . "', |
|
146 | + infowindowTemplatePath: '".$infowindowTemplatePath . "', |
|
151 | 147 | originMarker: true, |
152 | - ".$modal.', |
|
153 | - '.$featured.", |
|
148 | + ".$modal . ', |
|
149 | + '.$featured . ", |
|
154 | 150 | slideMap: false, |
155 | 151 | zoomLevel: 0, |
156 | 152 | distanceAlert: 120, |
@@ -159,7 +155,7 @@ discard block |
||
159 | 155 | inputID: 'Form_LocationSearch_address', |
160 | 156 | categoryID: 'Form_LocationSearch_category', |
161 | 157 | distanceAlert: -1, |
162 | - ".$kilometer.' |
|
158 | + ".$kilometer . ' |
|
163 | 159 | }); |
164 | 160 | }); |
165 | 161 | '); |
@@ -178,7 +174,7 @@ discard block |
||
178 | 174 | public function Items($searchCriteria = array()) |
179 | 175 | { |
180 | 176 | $request = ($this->request) ? $this->request : $this->parentController->getRequest(); |
181 | - if(empty($searchCriteria)) $searchCriteria = $request->requestVars(); |
|
177 | + if (empty($searchCriteria)) $searchCriteria = $request->requestVars(); |
|
182 | 178 | |
183 | 179 | //if category filters are selected on Locator |
184 | 180 | $filterAny = array(); |
@@ -178,7 +178,9 @@ |
||
178 | 178 | public function Items($searchCriteria = array()) |
179 | 179 | { |
180 | 180 | $request = ($this->request) ? $this->request : $this->parentController->getRequest(); |
181 | - if(empty($searchCriteria)) $searchCriteria = $request->requestVars(); |
|
181 | + if(empty($searchCriteria)) { |
|
182 | + $searchCriteria = $request->requestVars(); |
|
183 | + } |
|
182 | 184 | |
183 | 185 | //if category filters are selected on Locator |
184 | 186 | $filterAny = array(); |