forked from Snck3rs/contao-leaflet-maps
Copy map layer relations (Fix #89)
This commit is contained in:
@@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Duplicate map layer relations ([#89](https://github.com/netzmacht/contao-leaflet-maps/issues/89))
|
||||||
|
|
||||||
## [3.1.6] - 2020-01-03
|
## [3.1.6] - 2020-01-03
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|||||||
@@ -28,6 +28,9 @@ $GLOBALS['TL_DCA']['tl_leaflet_map'] = [
|
|||||||
'onsubmit_callback' => [
|
'onsubmit_callback' => [
|
||||||
['netzmacht.contao_leaflet.listeners.dca.leaflet', 'clearCache'],
|
['netzmacht.contao_leaflet.listeners.dca.leaflet', 'clearCache'],
|
||||||
],
|
],
|
||||||
|
'oncopy_callback' => [
|
||||||
|
['netzmacht.contao_leaflet.listeners.dca.map', 'copyLayerRelations'],
|
||||||
|
],
|
||||||
],
|
],
|
||||||
|
|
||||||
'list' => [
|
'list' => [
|
||||||
|
|||||||
@@ -226,4 +226,26 @@ class MapDcaListener extends AbstractListener
|
|||||||
->asTree()
|
->asTree()
|
||||||
->getOptions();
|
->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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user