mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-02 04:53:56 +01:00
Add load callback.
This commit is contained in:
@@ -179,6 +179,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
|||||||
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate'),
|
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'validateCoordinate'),
|
||||||
array('Netzmacht\Contao\Leaflet\Dca\Marker', 'saveCoordinates')
|
array('Netzmacht\Contao\Leaflet\Dca\Marker', 'saveCoordinates')
|
||||||
),
|
),
|
||||||
|
'load_callback' => array(
|
||||||
|
array('Netzmacht\Contao\Leaflet\Dca\Marker', 'loadCoordinates')
|
||||||
|
),
|
||||||
'wizard' => array(
|
'wizard' => array(
|
||||||
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getGeocoder')
|
array('Netzmacht\Contao\Leaflet\Dca\Leaflet', 'getGeocoder')
|
||||||
),
|
),
|
||||||
@@ -188,7 +191,6 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
|||||||
'nullIfEmpty' => true,
|
'nullIfEmpty' => true,
|
||||||
'doNotSaveEmpty' => true,
|
'doNotSaveEmpty' => true,
|
||||||
),
|
),
|
||||||
'sql' => "varchar(255) NULL"
|
|
||||||
),
|
),
|
||||||
'latitude' => array
|
'latitude' => array
|
||||||
(
|
(
|
||||||
@@ -196,7 +198,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
|||||||
'exclude' => true,
|
'exclude' => true,
|
||||||
'inputType' => 'text',
|
'inputType' => 'text',
|
||||||
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
|
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
|
||||||
'sql' => "float NULL"
|
'sql' => "DECIMAL(10, 8)"
|
||||||
),
|
),
|
||||||
'longitude' => array
|
'longitude' => array
|
||||||
(
|
(
|
||||||
@@ -204,7 +206,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
|||||||
'exclude' => true,
|
'exclude' => true,
|
||||||
'inputType' => 'text',
|
'inputType' => 'text',
|
||||||
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
|
'eval' => array('mandatory' => false, 'maxlength' => 255, 'tl_class' => 'w50'),
|
||||||
'sql' => "float NULL"
|
'sql' => "DECIMAL(11, 8)"
|
||||||
),
|
),
|
||||||
'altitude' => array
|
'altitude' => array
|
||||||
(
|
(
|
||||||
|
|||||||
@@ -33,12 +33,17 @@ class migrate
|
|||||||
*/
|
*/
|
||||||
protected function createFields(\Database $database)
|
protected function createFields(\Database $database)
|
||||||
{
|
{
|
||||||
foreach (array('latitude', 'longitude', 'altitude') as $field) {
|
if (!$database->fieldExists('latitude', 'tl_leaflet_marker')) {
|
||||||
if (!$database->fieldExists('latitude', 'tl_leaflet_marker')) {
|
$database->execute('ALTER TABLE tl_leaflet_marker ADD latitude DECIMAL (10, 8) NULL;');
|
||||||
$database->execute(sprintf('ALTER TABLE tl_leaflet_marker ADD %s float NULL;', $field));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!$database->fieldExists('longitude', 'tl_leaflet_marker')) {
|
||||||
|
$database->execute('ALTER TABLE tl_leaflet_marker ADD longitude DECIMAL (11, 8) NULL;');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$database->fieldExists('altitude', 'tl_leaflet_marker')) {
|
||||||
|
$database->execute('ALTER TABLE tl_leaflet_marker ADD altitude float NULL;');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -82,6 +82,39 @@ class Marker
|
|||||||
->set($combined)
|
->set($combined)
|
||||||
->execute($dataContainer->id);
|
->execute($dataContainer->id);
|
||||||
|
|
||||||
return $value;
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load the coordinates.
|
||||||
|
*
|
||||||
|
* @param string $value The raw data.
|
||||||
|
* @param \DataContainer $dataContainer The data container driver.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function loadCoordinates($value, $dataContainer)
|
||||||
|
{
|
||||||
|
$result = \Database::getInstance()
|
||||||
|
->prepare('SELECT latitude, longitude, altitude FROM tl_leaflet_marker WHERE id=?')
|
||||||
|
->execute($dataContainer->id);
|
||||||
|
|
||||||
|
if ($result->numRows) {
|
||||||
|
$buffer = $result->latitude;
|
||||||
|
|
||||||
|
if ($buffer && $result->longitude) {
|
||||||
|
$buffer .= ',' . $result->longitude;
|
||||||
|
} else {
|
||||||
|
return $buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($buffer && $result->altitude) {
|
||||||
|
$buffer .= ',' . $result->longitude;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user