Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
innomedia committed Jan 13, 2020
1 parent db8139f commit 988cece
Show file tree
Hide file tree
Showing 7 changed files with 1,228 additions and 0 deletions.
Empty file added _config.php
Empty file.
6 changes: 6 additions & 0 deletions _config/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
Name: GoogleMapsConfig
---
SilverStripe\SiteConfig\SiteConfig:
extensions:
- GMapsSiteConfigExtension
16 changes: 16 additions & 0 deletions composer.json
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": "[email protected]"
}
],
"autoload": {
"psr-4": {
"googlemaps\\": "src/"
}
}
}

66 changes: 66 additions & 0 deletions src/extension/GMapsDataObjectExtension.php
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"];
}
}
}
}
}
71 changes: 71 additions & 0 deletions src/extension/GMapsSiteConfigExtension.php
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"];
}
}
}
}
}
Loading

0 comments on commit 988cece

Please sign in to comment.