a2g_maps/Classes/Hooks/MapEntryDataHandlerHooks.php

39 lines
1.9 KiB
PHP
Raw Permalink Normal View History

2023-12-04 16:36:56 +01:00
<?php
declare(strict_types=1);
namespace A2G\A2gMaps\Hooks;
use TYPO3\CMS\Core\DataHandling\DataHandler;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use A2G\A2gMaps\Utility\MapConfigUtility;
class MapEntryDataHandlerHooks {
/**
* @param string|int $id
*/
public function processDatamap_postProcessFieldArray(
string $status, // Status of the current operation, 'new' or 'update'
string $table, // The table currently processing data for
$id, // The record uid currently processing data for,
// [integer] or [string] (like 'NEW...')
array &$fieldArray, // The field array of a record, cleaned to only
// 'to-be-changed' values. Needs to be &$fieldArray to be considered reference.
DataHandler $dataHandler
): void
{
if ($table === 'tx_a2gmaps_domain_model_mapentry') {
if( ( $fieldArray['latitude'] === 0.0 || $fieldArray['longitude'] === 0.0 ) || $fieldArray['nav_to_url'] === ''){
if($fieldArray['nav_to_url'] === '' && ($fieldArray['latitude'] != 0.0 || $fieldArray['longitude'] != 0.0 )){
} else if($fieldArray['city'] !== '' && $fieldArray['zip'] !== '' && $fieldArray['addressline'] !== ''){
$latLon = MapConfigUtility::getLatLonFrom($fieldArray['addressline'], $fieldArray['zip'] === '' ? $fieldArray['city'] : $fieldArray['zip'].' '.$fieldArray['city']);
$fieldArray['latitude'] = (float)$latLon['lat'];
$fieldArray['longitude'] = (float)$latLon['lon'];
$fieldArray['nav_to_url'] = MapConfigUtility::getNavToLink($fieldArray['addressline'], $fieldArray['zip'] === '' ? $fieldArray['city'] : $fieldArray['zip'].' '.$fieldArray['city']);
}
}
}
}
}