Copy map layer relations (Fix #89)

This commit is contained in:
David Molineus
2020-08-28 16:56:11 +02:00
parent 515a191a66
commit e5263a6315
3 changed files with 29 additions and 0 deletions

View File

@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- Duplicate map layer relations ([#89](https://github.com/netzmacht/contao-leaflet-maps/issues/89))
## [3.1.6] - 2020-01-03
### Fixed

View File

@@ -28,6 +28,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = [
'onsubmit_callback' => [
['netzmacht.contao_leaflet.listeners.dca.leaflet', 'clearCache'],
],
'oncopy_callback' => [
['netzmacht.contao_leaflet.listeners.dca.map', 'copyLayerRelations'],
],
],
'list' => [

View File

@@ -226,4 +226,26 @@ class MapDcaListener extends AbstractListener
->asTree()
->getOptions();
}
/**
* Copy layer relations if a map is duplicated.
*
* @param string|int $insertId Insert id of the new map.
* @param DataContainer $dataContainer Data container driver.
*
* @return void
*/
public function copyLayerRelations($insertId, DataContainer $dataContainer): void
{
$statement = $this->connection->prepare('SELECT * FROM tl_leaflet_map_layer WHERE mid=:mid order BY sorting');
$statement->bindValue('mid', $dataContainer->id);
$statement->execute();
while ($row = $statement->fetch(PDO::FETCH_ASSOC)) {
unset($row['id']);
$row['tstamp'] = time();
$row['mid'] = $insertId;
$this->connection->insert('tl_leaflet_map_layer', $row);
}
}
}