Skip to content

Commit

Permalink
Update store locator plugin
Browse files Browse the repository at this point in the history
Update location system to allow featured locations with geocoding
Update locator to handle featured locations
Update Location.php to add featured option
Update Locator.php to auto geocode based on auto geocode setting and featured locations
Add handlebars-v1.3.0.js
Update jquery store locator plugin
Commit reference: 381c3680c56f801d22c6a6ff928cbf980c743727
  • Loading branch information
muskie9 committed Apr 7, 2014
1 parent 2229149 commit 44b2295
Show file tree
Hide file tree
Showing 37 changed files with 5,852 additions and 2,678 deletions.
17 changes: 12 additions & 5 deletions code/Location.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Location extends DataObject {

static $db = array(
'Title' => 'Varchar(255)',
'Featured' => 'Boolean',
'Website' => 'Varchar(255)',
'Phone' => 'Varchar(40)',
'EmailAddress' => 'Varchar(255)',
Expand Down Expand Up @@ -39,13 +40,17 @@ class Location extends DataObject {
'Postcode',
'Country',
'Category.Name',
'Show'
);

'Show',
'Feature'
);

// LocatorStatus for $summary_fields
public function getShow() {
if ($this->ShowInLocator) return 'y';
return 'n';
return $this->obj('ShowInLocator')->Nice();
}

public function getFeature(){
return ($this->Featured) ? 'true' : 'false';
}

function fieldLabels($includerelations = true) {
Expand All @@ -57,6 +62,7 @@ function fieldLabels($includerelations = true) {
$labels['ShowInLocator'] = 'Show';
$labels['Category.Name'] = 'Category';
$labels['EmailAddress'] = 'Email';
$labels['Feature'] = 'Featured';

return $labels;
}
Expand Down Expand Up @@ -87,6 +93,7 @@ public function getCMSFields() {

// move Title and ShowInLocator fields to Address tab from Addressable
$fields->insertAfter(TextField::create('Title'), 'AddressHeader');
$fields->insertAfter(CheckboxField::create('Featured', 'Featured'), 'Title');
$fields->insertAfter(CheckboxField::create('ShowInLocator', 'Show on Map'), 'Country');

$this->extend('updateCMSFields', $fields);
Expand Down
59 changes: 40 additions & 19 deletions code/Locator.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,23 @@ public function getCMSFields() {
// Settings
$fields->addFieldsToTab('Root.Settings', array(
HeaderField::create('DisplayOptions', 'Display Options', 3),
CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location'),
CheckboxField::create('AutoGeocode', 'Auto Geocode - Automatically filter map results based on user location')
->setDescription('Note: if any locations are set as featured, the auto geocode is automatically disabled.'),
CheckboxField::create('ModalWindow', 'Modal Window - Show Map results in a modal window')
));

$this->extend('updateCMSFields', $fields);

return $fields;
}

public static function getLocations($filter = array(), $exclude = array()){
$filter['ShowInLocator'] = true;
return Location::get()
->exclude($exclude)
->exclude('Lat', 0)
->filter($filter);
}

}

Expand All @@ -53,22 +62,20 @@ public function init() {

Requirements::javascript('framework/thirdparty/jquery/jquery.js');
Requirements::javascript('http://maps.google.com/maps/api/js?sensor=false');
Requirements::javascript('locator/thirdparty/jquery-store-locator/js/handlebars-1.0.rc.1.min.js');
Requirements::javascript('locator/thirdparty/handlebars/handlebars-v1.3.0.js');
Requirements::javascript('locator/thirdparty/jquery-store-locator/js/jquery.storelocator.js');

Requirements::css('locator/css/map.css');

$featured = (Locator::getLocations(array('Featured' => 1))->count() > 0) ?
'featuredLocations: true' :
'featuredLocations: false';

// map config based on user input in Settings tab
// AutoGeocode or Full Map
if ($this->AutoGeocode) {
$load = 'autoGeocode: true,
fullMapStart: false,';
} else {
$load = 'autoGeocode: false,
fullMapStart: true,
storeLimit: 1000,
maxDistance: true,';
}
$load = ($this->data()->AutoGeocode) ?
'autoGeocode: true, fullMapStart: false,' :
'autoGeocode: false, fullMapStart: true, storeLimit: 1000, maxDistance: true,';

$absoluteBase = getcwd();//get current working dir
$base = str_replace('/framework','',$absoluteBase);//remove framework if .htaccess is working
Expand All @@ -82,11 +89,7 @@ public function init() {
'locator/templates/infowindow-description.html';

// in page or modal
if ($this->ModalWindow) {
$modal = 'modalWindow: true';
} else {
$modal = 'modalWindow: false';
}
$modal = ($this->data()->ModalWindow) ? 'modalWindow: true' : 'modalWindow: false';

// init map
Requirements::customScript("
Expand All @@ -98,12 +101,14 @@ public function init() {
infowindowTemplatePath: '".$infowindowTemplatePath."',
originMarker: true,
" . $modal . ",
" . $featured . ",
slideMap: false,
zoomLevel: 0,
distanceAlert: 120,
formID: 'Form_LocationSearch',
inputID: 'Form_LocationSearch_address',
categoryID: 'Form_LocationSearch_category'
categoryID: 'Form_LocationSearch_category',
distanceAlert: -1
});
});
");
Expand All @@ -123,7 +128,7 @@ public function init() {
*/
public function xml() {

$Locations = Location::get()->filter(array('ShowInLocator' => true))->exclude('Lat', 0);
$Locations = Locator::getLocations();

return $this->customise(array(
'Locations' => $Locations
Expand All @@ -147,7 +152,23 @@ public function LocationSearch() {
$address->setAttribute('placeholder', 'address or zip code');

if (LocationCategory::get()->Count() > 0) {
$fields->push(DropdownField::create('category', '', LocationCategory::get()->map('Title', 'Title'))->setEmptyString('Select Category'));

$locals = Locator::getLocations($filter = array(), $exclude = array('CategoryID' => 0));
//debug::show($locals);
$categories = ArrayList::create();

foreach($locals as $local){
$categories->add($local->Category());
}

if($categories->count()>0){
$fields->push(
DropdownField::create(
'category',
'',
$categories->map('Title', 'Title')
)->setEmptyString('Select Category'));
}
}

$actions = FieldList::create(
Expand Down
2 changes: 1 addition & 1 deletion templates/LocationXML.ss
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<markers>
<% loop Locations %><marker name="$Title.XML" lat="$Lat.XML" lng="$Lng.XML" category="$Category.Name.XML" address="$Address.XML" address2="" city="$Suburb.XML" state="$State.XML" postal="$Postcode.XML" phone="$Phone.XML" web="$Website.XML" /><% end_loop %>
<% loop Locations %><marker name="$Title.XML" lat="$Lat.XML" lng="$Lng.XML" category="$Category.Name.XML" address="$Address.XML" address2="" city="$Suburb.XML" state="$State.XML" postal="$Postcode.XML" phone="$Phone.XML" web="$Website.XML" featured="$Feature.XML" /><% end_loop %>
</markers>
Loading

0 comments on commit 44b2295

Please sign in to comment.