forked from Snck3rs/contao-leaflet-maps
Rework marker dca callbacks to a service listener.
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
* @filesource
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
namespace Netzmacht\Contao\Leaflet\Listener\Dca;
|
||||
|
||||
use Contao\Controller;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
||||
@@ -21,8 +23,35 @@ use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class MarkerCallbacks
|
||||
class MarkerDcaListener
|
||||
{
|
||||
/**
|
||||
* Database connection.
|
||||
*
|
||||
* @var Connection
|
||||
*/
|
||||
private $connection;
|
||||
|
||||
/**
|
||||
* MarkerDcaListener constructor.
|
||||
*
|
||||
* @param Connection $connection Database connection.
|
||||
*/
|
||||
public function __construct(Connection $connection)
|
||||
{
|
||||
$this->connection = $connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize the language files.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function initialize(): void
|
||||
{
|
||||
Controller::loadLanguageFile('leaflet');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the row label.
|
||||
*
|
||||
@@ -92,10 +121,7 @@ class MarkerCallbacks
|
||||
}
|
||||
}
|
||||
|
||||
\Database::getInstance()
|
||||
->prepare('UPDATE tl_leaflet_marker %s WHERE id=?')
|
||||
->set($combined)
|
||||
->execute($dataContainer->id);
|
||||
$this->connection->update('tl_leaflet_marker', $combined, ['id' => $dataContainer->id]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -112,21 +138,23 @@ class MarkerCallbacks
|
||||
*/
|
||||
public function loadCoordinates($value, $dataContainer)
|
||||
{
|
||||
$result = \Database::getInstance()
|
||||
->prepare('SELECT latitude, longitude, altitude FROM tl_leaflet_marker WHERE id=?')
|
||||
->execute($dataContainer->id);
|
||||
$query = 'SELECT latitude, longitude, altitude FROM tl_leaflet_marker WHERE id=:id';
|
||||
$statement = $this->connection->prepare($query);
|
||||
$statement->bindValue('id', $dataContainer->id);
|
||||
|
||||
if ($result->numRows) {
|
||||
$buffer = $result->latitude;
|
||||
$statement->execute();
|
||||
|
||||
if ($buffer && $result->longitude) {
|
||||
$buffer .= ',' . $result->longitude;
|
||||
if ($row = $statement->fetch()) {
|
||||
$buffer = $row['latitude'];
|
||||
|
||||
if ($buffer && $row['longitude']) {
|
||||
$buffer .= ',' . $row['longitude'];
|
||||
} else {
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
if ($buffer && $result->altitude) {
|
||||
$buffer .= ',' . $result->longitude;
|
||||
if ($buffer && $row['altitude']) {
|
||||
$buffer .= ',' . $row['altitude'];
|
||||
}
|
||||
|
||||
return $buffer;
|
||||
@@ -21,3 +21,8 @@ services:
|
||||
- '%netzmacht.contao_leaflet_maps.layers%'
|
||||
- '%netzmacht.contao_leaflet_maps.providers%'
|
||||
- '%netzmacht.contao_leaflet_maps.amenities%'
|
||||
|
||||
netzmacht.contao_leaflet_maps.listeners.dca.marker:
|
||||
class: Netzmacht\Contao\Leaflet\Listener\Dca\MarkerDcaListener
|
||||
arguments:
|
||||
- '@database_connection'
|
||||
|
||||
@@ -26,9 +26,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
)
|
||||
),
|
||||
'onload_callback' => array(
|
||||
function () {
|
||||
\Controller::loadLanguageFile('leaflet');
|
||||
}
|
||||
['netzmacht.contao_leaflet_maps.listeners.dca.marker', 'initialize'],
|
||||
),
|
||||
'onsubmit_callback' => [
|
||||
\Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('clearCache'),
|
||||
@@ -44,7 +42,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'flag' => 1,
|
||||
'panelLayout' => 'sort,filter;search,limit',
|
||||
'headerFields' => array('title', 'type'),
|
||||
'child_record_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'generateRow'),
|
||||
'child_record_callback' => array('netzmacht.contao_leaflet_maps.listeners.dca.marker\'', 'generateRow'),
|
||||
),
|
||||
'label' => array
|
||||
(
|
||||
@@ -195,10 +193,10 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'inputType' => 'text',
|
||||
'save_callback' => array(
|
||||
\Netzmacht\Contao\Leaflet\Dca\Validator::callback('validateCoordinates'),
|
||||
array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'saveCoordinates')
|
||||
array('netzmacht.contao_leaflet_maps.listeners.dca.marker', 'saveCoordinates')
|
||||
),
|
||||
'load_callback' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'loadCoordinates')
|
||||
array('netzmacht.contao_leaflet_maps.listeners.dca.marker', 'loadCoordinates')
|
||||
),
|
||||
'wizard' => array(
|
||||
Netzmacht\Contao\Leaflet\Dca\LeafletCallbacks::callback('getGeocoder')
|
||||
@@ -278,7 +276,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['popup'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getPopups'),
|
||||
'options_callback' => ['netzmacht.contao_leaflet_maps.listeners.dca.marker', 'getPopups'],
|
||||
'eval' => array(
|
||||
'mandatory' => false,
|
||||
'tl_class' => 'w50',
|
||||
@@ -309,7 +307,7 @@ $GLOBALS['TL_DCA']['tl_leaflet_marker'] = array
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_leaflet_marker']['icon'],
|
||||
'exclude' => true,
|
||||
'inputType' => 'select',
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\MarkerCallbacks', 'getIcons'),
|
||||
'options_callback' => array('netzmacht.contao_leaflet_maps.listeners.dca.marker', 'getIcons'),
|
||||
'eval' => array(
|
||||
'mandatory' => true,
|
||||
'tl_class' => 'w50',
|
||||
|
||||
Reference in New Issue
Block a user