2017 © Pedro Peláez
 

typo3-cms-extension ujamii-geocoder

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

image

ujamii/ujamii-geocoder

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  • Wednesday, March 28, 2018
  • by mgrundkoetter
  • Repository
  • 1 Watchers
  • 0 Stars
  • 0 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 8 Versions
  • 0 % Grown

The README.md

ujamii-geocoder

Packagist, (*1)

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API. With this extension you can easily add geo data to records while they are changed by editors in the TYPO3 backend. You just have to configure how your entity "looks like" in the eyes of the geocoder via TCA anf that's it., (*2)

Installation

Currently only works in composer mode of TYPO3, so, (*3)

composer require ujamii/ujamii-geocoder

Usage

Just add a new config array to the ctrl section of your TCA., (*4)

..['ctrl']['geocoder'] = [
    'triggerFields' => ['street', 'zip', 'city'],
    'getAddressString' => 'Your\Namespace\Domain\Model\YourEntity->getAddressString'
];

And provide a method (e.g. in an entity or helper class) to generate a compound address string based on the database data of one entity (example below)., (*5)

Options

Those options are possible:, (*6)

triggerFields (mandatory), (*7)

Changes in those fields will trigger the process of geocoding., (*8)

getAddressString (mandatory), (*9)

A method called via TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction which is supposed to return a complete address string. The first parameter provided to this method is the merged data array (unchanged entity data from db + changed values from the backend form)., (*10)

Example:, (*11)

public function getAddressString($dataArray) {
    return $dataArray['location'];
}

locale (default: de), (*12)

The locale which is used in the geocoder., (*13)

latField (default: lat), (*14)

Name of the target field for the latitude value., (*15)

lngField (default: lng), (*16)

Name of the target field for the longitude value., (*17)

httpClientClass (default: \Http\Adapter\Guzzle6\Client::class), (*18)

Class name of the http client, see possible packages, (*19)

providerClass (default: \Geocoder\Provider\GoogleMaps\GoogleMaps::class), (*20)

Class name of the provider, see possible packages, (*21)

providerParams, (*22)

Optional parameters for the provider. (e.g. an API key for Google Maps), (*23)

geocoderClass (default: \Geocoder\StatefulGeocoder::class), (*24)

Class name of the geocoder., (*25)

Example

Let's assume the record is a news record in the database with 3 fields: location, lat and lng. The field location contains something like Alexanderplatz, Berlin, Deutschland and lat and lng are the fields you want to be filled automatically as soon as an editor changes the location., (*26)

Add this to your typo3conf/ext/your_extension/Configuration/TCA/Overrides/tx_news_domain_model_news.php or typo3conf/ext/your_extension/Configuration/TCA/tx_ext_domain_model_entity.php file., (*27)

$GLOBALS['TCA']['tx_news_domain_model_news']['ctrl']['geocoder'] = [
    'triggerFields' => ['street', 'zip', 'city'],
    'getAddressString' => 'Your\Namespace\Domain\Model\YourEntity->getAddressString',
    'providerParams' => [
        0 => null,
        1 => null,
        2 => '<GMAPS_API_KEY>'
    ]
];

In YourEntity, add a method like this:, (*28)

public function getAddressString($dataArray) {
    return sprintf('%s, %s %s', $dataArray['street'], $dataArray['zip'], $dataArray['city']);
}

Usage as command or in scheduler

The extension also provides command to populate rows with 0 values for the lat/lng fields. It reads the configuration from TCA and iterates through each configured table, searching with lat = 0 OR lng = 0. For each matching row, the geocoding process is executed and the values are then updated in the database. The command produces some log output to track what has been done., (*29)

As it is a default Symfony console command, this can also be called by a scheduler task., (*30)

vendor/bin/typo3 geocoder:fillmissingdata

TODOs

  • publish in TER
  • right now providerParams[0] is always filled with the httpClient, which may not work for all providers

The Versions

28/03 2018

dev-master

9999999-dev

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

MIT

The Requires

 

by Michael Grundkötter

28/03 2018

v0.2.4

0.2.4.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

MIT

The Requires

 

by Michael Grundkötter

28/03 2018

v0.2.3

0.2.3.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

MIT

The Requires

 

by Michael Grundkötter

28/03 2018

v0.2.2

0.2.2.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

The Requires

 

by Michael Grundkötter

28/03 2018

v0.2.1

0.2.1.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

The Requires

 

by Michael Grundkötter

28/03 2018

v0.2.0

0.2.0.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

The Requires

 

by Michael Grundkötter

28/03 2018

v0.1.1

0.1.1.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

The Requires

 

by Michael Grundkötter

28/03 2018

v0.1.0

0.1.0.0

Connecting http://geocoder-php.org/Geocoder with TYPO3 DataHandler API

  Sources   Download

The Requires

 

by Michael Grundkötter