mirror of
https://github.com/netzmacht/contao-leaflet-maps.git
synced 2025-12-01 04:24:02 +01:00
Add undo relations deleting callback.
This commit is contained in:
@@ -13,17 +13,27 @@ namespace Netzmacht\Contao\Leaflet\Dca;
|
|||||||
|
|
||||||
|
|
||||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||||
|
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
|
||||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||||
|
|
||||||
class Layer
|
class Layer
|
||||||
{
|
{
|
||||||
|
use ServiceContainerTrait;
|
||||||
|
|
||||||
private $layers;
|
private $layers;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @var \Database
|
||||||
|
*/
|
||||||
|
private $database;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
|
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
|
||||||
|
$this->database = static::getService('database.connection');
|
||||||
|
|
||||||
\Controller::loadLanguageFile('leaflet_layer');
|
\Controller::loadLanguageFile('leaflet_layer');
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getVariants($dataContainer)
|
public function getVariants($dataContainer)
|
||||||
@@ -159,6 +169,48 @@ class Layer
|
|||||||
->getOptions();
|
->getOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function deleteRelations($dataContainer, $undoId)
|
||||||
|
{
|
||||||
|
if ($undoId) {
|
||||||
|
$undo = $this->database
|
||||||
|
->prepare('SELECT * FROM tl_undo WHERE id=?')
|
||||||
|
->limit(1)
|
||||||
|
->execute($undoId)
|
||||||
|
->row();
|
||||||
|
|
||||||
|
$result = $this->database
|
||||||
|
->prepare('SELECT * FROM tl_leaflet_map_layer WHERE lid=?')
|
||||||
|
->execute($dataContainer->id);
|
||||||
|
|
||||||
|
$undo['data'] = deserialize($undo['data'], true);
|
||||||
|
|
||||||
|
while ($result->next()) {
|
||||||
|
$undo['data']['tl_leaflet_map_layer'][] = $result->row();
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = $this->database
|
||||||
|
->prepare('SELECT * FROM tl_leaflet_control_layer WHERE lid=?')
|
||||||
|
->execute($dataContainer->id);
|
||||||
|
|
||||||
|
while ($result->next()) {
|
||||||
|
$undo['data']['tl_leaflet_control_layer'][] = $result->row();
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->database->prepare('UPDATE tl_undo %s WHERE id=?')
|
||||||
|
->set(array('data' => $undo['data']))
|
||||||
|
->execute($undo['id']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->database
|
||||||
|
->prepare('DELETE FROM tl_leaflet_map_layer WHERE lid=?')
|
||||||
|
->execute($dataContainer->id);
|
||||||
|
|
||||||
|
$this->database
|
||||||
|
->prepare('DELETE FROM tl_leaflet_control_layer WHERE lid=?')
|
||||||
|
->execute($dataContainer->id);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $row
|
* @param $row
|
||||||
* @param $href
|
* @param $href
|
||||||
|
|||||||
Reference in New Issue
Block a user