forked from Snck3rs/contao-leaflet-maps
Adjust dca files and callbacks to work with toolkit v2.
This commit is contained in:
37
src/Netzmacht/Contao/Leaflet/Alias/UnderscoreFilter.php
Normal file
37
src/Netzmacht/Contao/Leaflet/Alias/UnderscoreFilter.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package netzmacht
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2016 netzmacht David Molineus. All rights reserved.
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Alias;
|
||||
|
||||
use Netzmacht\Contao\Toolkit\Data\Alias\Filter;
|
||||
|
||||
/**
|
||||
* Class UnderscoreFilter
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Alias
|
||||
*/
|
||||
class UnderscoreFilter extends Filter\AbstractFilter
|
||||
{
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function repeatUntilValid()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public function apply($model, $value, $separator)
|
||||
{
|
||||
return str_replace('-', '_', $value);
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Manager;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Toolkit\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
@@ -21,9 +22,21 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Control
|
||||
class ControlCallbacks extends Callbacks
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
/**
|
||||
* Name of the data container.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $name = 'tl_leaflet_control';
|
||||
|
||||
/**
|
||||
* Helper service name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $serviceName = 'leaflet.dca.control-callbacks';
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
@@ -34,10 +47,15 @@ class Control
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param Manager $manager Data container manager.
|
||||
* @param \Database $database Database connection.
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(Manager $manager, \Database $database)
|
||||
{
|
||||
$this->database = static::getServiceContainer()->getDatabaseConnection();
|
||||
parent::__construct($manager);
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -84,7 +102,7 @@ class Control
|
||||
{
|
||||
$collection = ControlModel::findBy('type', 'zoom', array('order' => 'title'));
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
return OptionsBuilder::fromCollection($collection, 'title')->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -30,7 +30,7 @@ class FrontendIntegration
|
||||
{
|
||||
$collection = MapModel::findAll();
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
return OptionsBuilder::fromCollection($collection, 'title')->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2015 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use Netzmacht\Contao\Toolkit\Dca;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Callback\GenerateAliasCallback;
|
||||
|
||||
/**
|
||||
* Helper class for dca functions.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Helper
|
||||
{
|
||||
/**
|
||||
* Generate an alias callback which creates a valid javascript var name.
|
||||
*
|
||||
* @param string $table The table.
|
||||
* @param string $column The value column.
|
||||
*
|
||||
* @return GenerateAliasCallback
|
||||
*/
|
||||
public static function createGenerateAliasCallback($table, $column)
|
||||
{
|
||||
$callback = Dca::createGenerateAliasCallback($table, $column);
|
||||
$callback->getGenerator()->addFilter(
|
||||
function ($value) {
|
||||
return str_replace('-', '_', $value);
|
||||
}
|
||||
);
|
||||
|
||||
return $callback;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Manager;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Toolkit\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
/**
|
||||
@@ -20,9 +21,21 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Layer
|
||||
class LayerCallbacks extends Callbacks
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
/**
|
||||
* Name of the data container.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $name = 'tl_leaflet_layer';
|
||||
|
||||
/**
|
||||
* Helper service name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $serviceName = 'leaflet.dca.layer-callbacks';
|
||||
|
||||
/**
|
||||
* Layers definition.
|
||||
@@ -41,12 +54,18 @@ class Layer
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param Manager $manager Data container manager.
|
||||
* @param \Database $database Database connection.
|
||||
* @param array $layers Leaflet layer configuration.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(Manager $manager, \Database $database, array $layers)
|
||||
{
|
||||
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
|
||||
$this->database = static::getServiceContainer()->getDatabaseConnection();
|
||||
parent::__construct($manager);
|
||||
|
||||
$this->layers = $layers;
|
||||
$this->database = $database;
|
||||
|
||||
\Controller::loadLanguageFile('leaflet_layer');
|
||||
|
||||
@@ -237,22 +256,6 @@ class Layer
|
||||
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all layers except of the current layer.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayers($dataContainer)
|
||||
{
|
||||
$collection = LayerModel::findBy('id !', $dataContainer->id);
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')
|
||||
->asTree()
|
||||
->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the relations when the layer is deleted.
|
||||
*
|
||||
@@ -22,7 +22,7 @@ use Netzmacht\LeafletPHP\Value\LatLng;
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Leaflet
|
||||
class LeafletCallbacks
|
||||
{
|
||||
/**
|
||||
* Validate a coordinate.
|
||||
@@ -11,16 +11,31 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use Netzmacht\Contao\Toolkit\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Callback\Callbacks;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Manager;
|
||||
use Netzmacht\Contao\Toolkit\Dca\Options\OptionsBuilder;
|
||||
|
||||
/**
|
||||
* Class Map is the helper class for the tl_leaflet_map dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Map
|
||||
class MapCallbacks extends Callbacks
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
/**
|
||||
* Name of the data container.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $name = 'tl_leaflet_map';
|
||||
|
||||
/**
|
||||
* Helper service name.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $serviceName = 'leaflet.dca.map-callbacks';
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
@@ -31,10 +46,15 @@ class Map
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param Manager $manager Data container manager.
|
||||
* @param \Database $database Database connection.
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(Manager $manager, \Database $database)
|
||||
{
|
||||
$this->database = static::getServiceContainer()->getDatabaseConnection();
|
||||
parent::__construct($manager);
|
||||
|
||||
$this->database = $database;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -120,4 +140,20 @@ class Map
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all layers except of the current layer.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayers($dataContainer)
|
||||
{
|
||||
$collection = LayerModel::findBy('id !', $dataContainer->id);
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'title')
|
||||
->asTree()
|
||||
->getOptions();
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Marker
|
||||
class MarkerCallbacks
|
||||
{
|
||||
/**
|
||||
* Generate the row label.
|
||||
@@ -44,7 +44,6 @@ class Marker
|
||||
$collection = IconModel::findAll(array('order' => 'title'));
|
||||
$builder = OptionsBuilder::fromCollection(
|
||||
$collection,
|
||||
'id',
|
||||
function ($model) {
|
||||
return sprintf('%s [%s]', $model['title'], $model['type']);
|
||||
}
|
||||
@@ -61,7 +60,7 @@ class Marker
|
||||
public function getPopups()
|
||||
{
|
||||
$collection = PopupModel::findAll(array('order' => 'title'));
|
||||
$builder = OptionsBuilder::fromCollection($collection, 'id', 'title');
|
||||
$builder = OptionsBuilder::fromCollection($collection, 'title');
|
||||
|
||||
return $builder->getOptions();
|
||||
}
|
||||
@@ -19,7 +19,7 @@ use Netzmacht\Contao\Leaflet\Model\StyleModel;
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Vector
|
||||
class VectorCallbacks
|
||||
{
|
||||
/**
|
||||
* Generate the row label.
|
||||
@@ -42,6 +42,6 @@ class Vector
|
||||
{
|
||||
$collection = StyleModel::findAll(array('order' => 'title'));
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
return OptionsBuilder::fromCollection($collection, 'title')->getOptions();
|
||||
}
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Subscriber;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Dca\Vector;
|
||||
use Netzmacht\Contao\Leaflet\Dca\VectorCallbacks;
|
||||
use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Value\GeoJson\Feature;
|
||||
@@ -83,7 +83,7 @@ class GeoJsonSubscriber implements EventSubscriberInterface
|
||||
$definition = $event->getDefinition();
|
||||
$model = $event->getModel();
|
||||
|
||||
if (($definition instanceof Marker || $definition instanceof Vector)
|
||||
if (($definition instanceof Marker || $definition instanceof VectorCallbacks)
|
||||
&& $model instanceof \Model && $feature instanceof Feature) {
|
||||
$this->setDataProperty($model, $feature);
|
||||
$this->setBoundsInformation($model, $feature);
|
||||
|
||||
Reference in New Issue
Block a user