-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
innomedia
committed
Jan 13, 2020
1 parent
db8139f
commit 988cece
Showing
7 changed files
with
1,228 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
Name: GoogleMapsConfig | ||
--- | ||
SilverStripe\SiteConfig\SiteConfig: | ||
extensions: | ||
- GMapsSiteConfigExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name":"innomedia/googlemaps", | ||
"description": "Silverstripe 4 Google Maps Implementation", | ||
"authors": [ | ||
{ | ||
"name":"Innomedia AG", | ||
"email": "bk@innomedia.de" | ||
} | ||
], | ||
"autoload": { | ||
"psr-4": { | ||
"googlemaps\\": "src/" | ||
} | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
use SilverStripe\Forms\TextField; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\LiteralField; | ||
use SilverStripe\ORM\DataExtension; | ||
|
||
class GMapsDataObjectExtension extends DataExtension | ||
{ | ||
/** | ||
* Database fields | ||
* @var array | ||
*/ | ||
private static $db = [ | ||
'Address' => 'Text', | ||
'Longitude' => 'Text', | ||
'Latitude' => 'Text' | ||
]; | ||
/** | ||
* Update Fields | ||
* @return FieldList | ||
*/ | ||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$owner = $this->owner; | ||
$fields->addFieldsToTab( | ||
'Root.Maps', | ||
[ | ||
TextField::create( | ||
'Address', | ||
'Adresse ("ß" als "ss" schreiben)' | ||
), | ||
LiteralField::create( | ||
'Notice', | ||
'Longitude und Latitude wird mit angegebener Adresse automatisch befüllt' | ||
), | ||
TextField::create( | ||
'Longitude', | ||
'Longitude' | ||
), | ||
TextField::create( | ||
'Latitude', | ||
'Latitude' | ||
) | ||
] | ||
); | ||
return $fields; | ||
} | ||
/** | ||
* Event handler called before writing to the database. | ||
*/ | ||
public function onBeforeWrite() | ||
{ | ||
parent::onBeforeWrite(); | ||
|
||
if (array_key_exists("Address", $this->owner->getChangedFields(false, 1))) { | ||
if ($this->owner->getChangedFields(true, 1)["Address"]["after"] != "") { | ||
if ($this->owner->Address != "") { | ||
$geo = new simpleGMapGeocoder(); | ||
$result = $geo->getGeoCoords($this->owner->Address); | ||
$this->owner->Longitude = $result["lng"]; | ||
$this->owner->Latitude = $result["lat"]; | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
use SilverStripe\Forms\TextField; | ||
use SilverStripe\Forms\FieldList; | ||
use SilverStripe\Forms\LiteralField; | ||
use SilverStripe\ORM\DataExtension; | ||
|
||
class GMapsSiteConfigExtension extends DataExtension | ||
{ | ||
/** | ||
* Database fields | ||
* @var array | ||
*/ | ||
private static $db = [ | ||
'MapsAPIKey' => 'Text', | ||
'Address' => 'Text', | ||
'Longitude' => 'Text', | ||
'Latitude' => 'Text' | ||
]; | ||
/** | ||
* Update Fields | ||
* @return FieldList | ||
*/ | ||
public function updateCMSFields(FieldList $fields) | ||
{ | ||
$owner = $this->owner; | ||
$fields->addFieldsToTab( | ||
'Root.Maps', | ||
[ | ||
TextField::create( | ||
'MapsAPIKey', | ||
'API Key' | ||
), | ||
TextField::create( | ||
'Address', | ||
'Adresse ("ß" als "ss" schreiben)' | ||
), | ||
LiteralField::create( | ||
'Notice', | ||
'Longitude und Latitude wird mit angegebener Adresse automatisch befüllt' | ||
), | ||
TextField::create( | ||
'Longitude', | ||
'Longitude' | ||
), | ||
TextField::create( | ||
'Latitude', | ||
'Latitude' | ||
) | ||
] | ||
); | ||
return $fields; | ||
} | ||
/** | ||
* Event handler called before writing to the database. | ||
*/ | ||
public function onBeforeWrite() | ||
{ | ||
parent::onBeforeWrite(); | ||
|
||
if (array_key_exists("Address", $this->owner->getChangedFields(false, 1))) { | ||
if ($this->owner->getChangedFields(true, 1)["Address"]["after"] != "") { | ||
if ($this->owner->Address != "") { | ||
$geo = new simpleGMapGeocoder(); | ||
$result = $geo->getGeoCoords($this->owner->Address); | ||
$this->owner->Longitude = $result["lng"]; | ||
$this->owner->Latitude = $result["lat"]; | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.