diff --git a/src/Event/BuildDefinitionEvent.php b/src/Event/BuildDefinitionEvent.php index a463659..7e63160 100644 --- a/src/Event/BuildDefinitionEvent.php +++ b/src/Event/BuildDefinitionEvent.php @@ -12,8 +12,8 @@ namespace Netzmacht\Contao\Leaflet\Event; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; -use Netzmacht\LeafletPHP\Value\LatLngBounds; use Symfony\Component\EventDispatcher\Event; /** @@ -40,24 +40,24 @@ class BuildDefinitionEvent extends Event private $model; /** - * Optional bounds where elements should be in. + * Building request. * - * @var LatLngBounds + * @var Request|null */ - private $bounds; + private $request; /** * Construct. * * @param Definition $definition The leaflet definition. * @param \Model $model The definition model. - * @param LatLngBounds $bounds Optional bounds where elements should be in. + * @param Request|null $request Building request. */ - public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null) + public function __construct(Definition $definition, \Model $model, Request $request = null) { $this->definition = $definition; $this->model = $model; - $this->bounds = $bounds; + $this->request = $request; } /** @@ -83,10 +83,10 @@ class BuildDefinitionEvent extends Event /** * Get the bounds. * - * @return LatLngBounds|null + * @return Request|null */ - public function getBounds() + public function getRequest() { - return $this->bounds; + return $this->request; } } diff --git a/src/Frontend/RequestUrl.php b/src/Frontend/RequestUrl.php index 9fc849a..a6d38d9 100644 --- a/src/Frontend/RequestUrl.php +++ b/src/Frontend/RequestUrl.php @@ -13,6 +13,7 @@ namespace Netzmacht\Contao\Leaflet\Frontend; use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Request\Request; /** * Class RequestUrl creates the request url. @@ -21,13 +22,6 @@ use Netzmacht\Contao\Leaflet\Filter\Filter; */ class RequestUrl implements \JsonSerializable { - /** - * The for param is the identifier to the responsible frontend module or content element. - * - * @var string - */ - private static $for; - /** * The leaflet hash. * @@ -54,17 +48,17 @@ class RequestUrl implements \JsonSerializable * * It combines the params and creates an hash for it. * - * @param int $dataId The data object id. - * @param string|null $type Object type. If empty it assumes a layer. - * @param string|null $format Data format. If empty it assumes geojson. - * @param Filter $filter Optional filter. + * @param int $dataId The data object id. + * @param string|null $type Object type. If empty it assumes a layer. + * @param string|null $format Data format. If empty it assumes geojson. + * @param Request $request Optional building request. * * @return RequestUrl */ - public static function create($dataId, $type = null, $format = null, Filter $filter = null) + public static function create($dataId, $type = null, $format = null, Request $request = null) { $params = array( - 'for' => static::$for, + 'for' => $request ? $request->getMapIdentifier() : null, 'type' => $type != 'layer' ? $type : null, 'id' => $dataId, 'format' => $format != 'geojson' ? $format : null @@ -73,25 +67,14 @@ class RequestUrl implements \JsonSerializable $hash = base64_encode(implode(',', $params)); $query = 'leaflet=' . $hash; - if ($filter) { + if ($request && $request->getFilter()) { + $filter = $request->getFilter(); $query .= '&f=' . $filter->getName() . '&v=' . $filter->toRequest(); } $url = \Config::get('websitePath') . '/' . \Frontend::addToUrl($query, false); - return new static($url, $hash, $filter); - } - - /** - * Set the for param. - * - * @param string $for The identifier which has the responsibility listen to the request. - * - * @return void - */ - public static function setFor($for) - { - static::$for = $for; + return new static($url, $hash, $request); } /** diff --git a/src/MapProvider.php b/src/MapProvider.php index 38cbfa8..27ba28e 100644 --- a/src/MapProvider.php +++ b/src/MapProvider.php @@ -17,10 +17,10 @@ use Doctrine\Common\Cache\Cache; use Netzmacht\Contao\Leaflet\Event\GetJavascriptEvent; use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Frontend\DataController; -use Netzmacht\Contao\Leaflet\Frontend\RequestUrl; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\MapModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection; use Netzmacht\LeafletPHP\Definition\Map; use Netzmacht\LeafletPHP\Leaflet; @@ -139,9 +139,8 @@ class MapProvider $model = $this->getModel($mapId); } - RequestUrl::setFor($elementId ?: $mapId); - $definition = $this->mapper->reset()->handle($model, $filter, $elementId); - RequestUrl::setFor(null); + $request = new Request($elementId ?: $mapId, $filter); + $definition = $this->mapper->reset()->handle($model, $request, $elementId); return $definition; } @@ -241,8 +240,10 @@ class MapProvider throw new \InvalidArgumentException(sprintf('Could not find layer "%s"', $layerId)); } + $request = new Request('', $filter); + if (!$model->cache) { - return $this->mapper->handleGeoJson($model, $filter); + return $this->mapper->handleGeoJson($model, $request); } $cacheKey = 'feature_layer_' . $model->id; @@ -254,7 +255,7 @@ class MapProvider return $this->cache->fetch($cacheKey); } - $collection = $this->mapper->handleGeoJson($model, $filter); + $collection = $this->mapper->handleGeoJson($model, $request); $this->cache->save($cacheKey, $collection, $model->cacheLifeTime); return $collection; diff --git a/src/Mapper/AbstractMapper.php b/src/Mapper/AbstractMapper.php index b773ae7..b129f65 100644 --- a/src/Mapper/AbstractMapper.php +++ b/src/Mapper/AbstractMapper.php @@ -12,7 +12,8 @@ namespace Netzmacht\Contao\Leaflet\Mapper; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; /** @@ -63,14 +64,14 @@ abstract class AbstractMapper implements Mapper public function handle( $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null, Definition $parent = null ) { - $definition = $this->createInstance($model, $mapper, $filter, $elementId); + $definition = $this->createInstance($model, $mapper, $request, $elementId); $this->optionsBuilder->build($definition, $model); - $this->build($definition, $model, $mapper, $filter, $parent); + $this->build($definition, $model, $mapper, $request, $parent); return $definition; } @@ -78,7 +79,7 @@ abstract class AbstractMapper implements Mapper /** * {@inheritdoc} */ - public function match($model, Filter $filter = null) + public function match($model, Request $request = null) { $modelClass = static::$modelClass; @@ -98,9 +99,9 @@ abstract class AbstractMapper implements Mapper * Use for specific build methods. * * @param Definition $definition The definition being built. - * @param \Model $model The model. + * @param Model $model The model. * @param DefinitionMapper $mapper The definition mapper. - * @param Filter|null $filter Optional request filter. + * @param Request $request Optional building request. * @param Definition|null $parent The parent object. * * @return void @@ -109,9 +110,9 @@ abstract class AbstractMapper implements Mapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { } @@ -119,21 +120,21 @@ abstract class AbstractMapper implements Mapper /** * Create a new definition instance. * - * @param \Model $model The model. + * @param Model $model The model. * @param DefinitionMapper $mapper The definition mapper. - * @param Filter $filter Optional request filter. + * @param Request $request Optional building request. * @param string|null $elementId Optional element id. * * @return Definition */ protected function createInstance( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { - $reflector = new \ReflectionClass($this->getClassName($model, $mapper, $filter)); - $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $filter, $elementId)); + $reflector = new \ReflectionClass($this->getClassName($model, $mapper, $request)); + $instance = $reflector->newInstanceArgs($this->buildConstructArguments($model, $mapper, $request, $elementId)); return $instance; } @@ -141,9 +142,9 @@ abstract class AbstractMapper implements Mapper /** * Get construct arguments. * - * @param \Model $model The model. + * @param Model $model The model. * @param DefinitionMapper $mapper The definition mapper. - * @param Filter $filter Optional request filter. + * @param Request $request Optional building request. * @param string|null $elementId Optional element id. * * @return array @@ -151,9 +152,9 @@ abstract class AbstractMapper implements Mapper * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { return array( @@ -164,15 +165,15 @@ abstract class AbstractMapper implements Mapper /** * Get definition class name. * - * @param \Model $model The model. - * @param DefinitionMapper $mapper The definition mapper. - * @param Filter $filter Optional request filter. + * @param Model $model The model. + * @param DefinitionMapper $mapper The definition mapper. + * @param Request $request Optional building request. * * @return string * * @SuppressWarnings(PHPMD.UnusedFormalParameter) */ - protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null) { return static::$definitionClass; } @@ -180,12 +181,12 @@ abstract class AbstractMapper implements Mapper /** * Create element id for the model. * - * @param \Model $model The model being passed. + * @param Model $model The model being passed. * @param string|null $elementId Optional forced id. * * @return string */ - protected function getElementId(\Model $model, $elementId = null) + protected function getElementId(Model $model, $elementId = null) { if ($elementId) { return $elementId; diff --git a/src/Mapper/AbstractTypeMapper.php b/src/Mapper/AbstractTypeMapper.php index 81bc4e9..8df9034 100644 --- a/src/Mapper/AbstractTypeMapper.php +++ b/src/Mapper/AbstractTypeMapper.php @@ -12,7 +12,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Request\Request; /** * Class AbstractTypeMapper is the base mapper for tables containing different types of definitins. @@ -31,7 +31,7 @@ abstract class AbstractTypeMapper extends AbstractMapper /** * {@inheritdoc} */ - public function match($model, Filter $filter = null) + public function match($model, Request $request = null) { return parent::match($model) && $model->type === static::$type; } diff --git a/src/Mapper/Control/AttributionControlMapper.php b/src/Mapper/Control/AttributionControlMapper.php index f2613a2..3817069 100644 --- a/src/Mapper/Control/AttributionControlMapper.php +++ b/src/Mapper/Control/AttributionControlMapper.php @@ -12,8 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Control\Attribution; use Netzmacht\LeafletPHP\Definition\Map; @@ -54,9 +55,9 @@ class AttributionControlMapper extends AbstractControlMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if (!$definition instanceof Attribution) { diff --git a/src/Mapper/Control/LayersControlMapper.php b/src/Mapper/Control/LayersControlMapper.php index 78aade6..d7912f4 100644 --- a/src/Mapper/Control/LayersControlMapper.php +++ b/src/Mapper/Control/LayersControlMapper.php @@ -12,9 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\ControlModel; +use Netzmacht\Contao\Leaflet\Request\Request; /** * Class LayersControlMapper maps the control model to the layers control definition. @@ -41,12 +42,12 @@ class LayersControlMapper extends AbstractControlMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { - $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId); + $arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId); $arguments[1] = array(); $arguments[2] = array(); @@ -57,7 +58,7 @@ class LayersControlMapper extends AbstractControlMapper foreach ($collection as $layer) { $argument = ($layer->controlMode === 'overlay') ? 2 : 1; - $arguments[$argument][] = $mapper->handle($layer, $filter); + $arguments[$argument][] = $mapper->handle($layer, $request); } } diff --git a/src/Mapper/Control/LoadingControlMapper.php b/src/Mapper/Control/LoadingControlMapper.php index 76be93f..9e92f47 100644 --- a/src/Mapper/Control/LoadingControlMapper.php +++ b/src/Mapper/Control/LoadingControlMapper.php @@ -12,9 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\ControlModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Control\Zoom; use Netzmacht\LeafletPHP\Plugins\Loading\LoadingControl; @@ -37,7 +38,7 @@ class LoadingControlMapper extends AbstractControlMapper /** * {@inheritdoc} */ - protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null) { if ($model->spinjs) { return 'Netzmacht\LeafletPHP\Plugins\Loading\SpinJsLoadingControl'; @@ -61,12 +62,12 @@ class LoadingControlMapper extends AbstractControlMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof SpinJsLoadingControl && $model->spin) { $config = json_decode($model->spin, true); diff --git a/src/Mapper/DefinitionMapper.php b/src/Mapper/DefinitionMapper.php index 6522d99..54ce353 100644 --- a/src/Mapper/DefinitionMapper.php +++ b/src/Mapper/DefinitionMapper.php @@ -15,7 +15,7 @@ namespace Netzmacht\Contao\Leaflet\Mapper; use Netzmacht\Contao\Leaflet\Event\BuildDefinitionEvent; use Netzmacht\Contao\Leaflet\Event\ConvertToGeoJsonEvent; use Netzmacht\Contao\Leaflet\Event\GetHashEvent; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Value\GeoJson\ConvertsToGeoJsonFeature; use Netzmacht\LeafletPHP\Value\GeoJson\Feature; @@ -94,24 +94,24 @@ class DefinitionMapper * Build a model. * * @param mixed $model The definition model. - * @param Filter $filter Optional request filter. - * @param string $elementId Optional element id. If none given the mapId or alias is used. + * @param Request|null $request The map request. + * @param string|null $elementId Optional element id. If none given the model id or alias is used. * @param Definition|null $parent Optional pass the parent object. * * @return Definition|null * * @throws \RuntimeException If model could not be mapped to a definition. */ - public function handle($model, Filter $filter = null, $elementId = null, $parent = null) + public function handle($model, Request $request = null, $elementId = null, $parent = null) { $hash = $this->hash($model, $elementId); if (!isset($this->mapped[$hash])) { $mapper = $this->getMapper($model); - $definition = $mapper->handle($model, $this, $filter, $elementId, $parent); + $definition = $mapper->handle($model, $this, $request, $elementId, $parent); if ($definition) { - $event = new BuildDefinitionEvent($definition, $model, $filter); + $event = new BuildDefinitionEvent($definition, $model, $request); $this->eventDispatcher->dispatch($event::NAME, $event); } @@ -124,19 +124,19 @@ class DefinitionMapper /** * Build a model. * - * @param mixed $model The definition model. - * @param Filter $filter Optional request filter. + * @param mixed $model The definition model. + * @param Request $request Optional building request. * * @return FeatureCollection|Feature|null * * @throws \RuntimeException If a model could not be mapped to the GeoJSON representation. */ - public function handleGeoJson($model, Filter $filter = null) + public function handleGeoJson($model, Request $request = null) { $mapper = $this->getMapper($model); if ($mapper instanceof GeoJsonMapper) { - return $mapper->handleGeoJson($model, $this, $filter); + return $mapper->handleGeoJson($model, $this, $request); } throw new \RuntimeException( diff --git a/src/Mapper/GeoJsonMapper.php b/src/Mapper/GeoJsonMapper.php index f0ac257..322d061 100644 --- a/src/Mapper/GeoJsonMapper.php +++ b/src/Mapper/GeoJsonMapper.php @@ -12,7 +12,8 @@ namespace Netzmacht\Contao\Leaflet\Mapper; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Value\GeoJson\GeoJsonFeature; /** @@ -25,11 +26,11 @@ interface GeoJsonMapper /** * Hanle the GeoJSON creation. * - * @param \Model $model The model being mapped. - * @param DefinitionMapper $mapper The definition mapper. - * @param Filter $filter Optional request filter. + * @param Model $model The model being mapped. + * @param DefinitionMapper $mapper The definition mapper. + * @param Request $request Optional building request. * * @return GeoJsonFeature|null */ - public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null); + public function handleGeoJson(Model $model, DefinitionMapper $mapper, Request $request = null); } diff --git a/src/Mapper/Layer/GroupLayerMapper.php b/src/Mapper/Layer/GroupLayerMapper.php index 27d6987..172cdab 100644 --- a/src/Mapper/Layer/GroupLayerMapper.php +++ b/src/Mapper/Layer/GroupLayerMapper.php @@ -12,9 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Group\LayerGroup; use Netzmacht\LeafletPHP\Definition\Layer; @@ -36,7 +37,7 @@ class GroupLayerMapper extends AbstractLayerMapper /** * {@inheritdoc} */ - protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null) { if ($model->groupType === 'feature') { return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup'; @@ -50,9 +51,9 @@ class GroupLayerMapper extends AbstractLayerMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if (!$definition instanceof LayerGroup) { diff --git a/src/Mapper/Layer/MarkerClusterLayerMapper.php b/src/Mapper/Layer/MarkerClusterLayerMapper.php index b5b27f5..a71b8c2 100644 --- a/src/Mapper/Layer/MarkerClusterLayerMapper.php +++ b/src/Mapper/Layer/MarkerClusterLayerMapper.php @@ -12,11 +12,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; +use Contao\Model; use Netzmacht\Contao\Leaflet\ContaoAssets; -use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; -use Netzmacht\Contao\Toolkit\View\Assets\AssetsManager; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\JavascriptBuilder\Type\AnonymousFunction; use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; @@ -86,12 +86,12 @@ class MarkerClusterLayerMapper extends AbstractLayerMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter, $parent); + parent::build($definition, $model, $mapper, $request, $parent); /** @var MarkerClusterGroup $definition */ diff --git a/src/Mapper/Layer/MarkersLayerMapper.php b/src/Mapper/Layer/MarkersLayerMapper.php index a8731c8..79a8b5f 100644 --- a/src/Mapper/Layer/MarkersLayerMapper.php +++ b/src/Mapper/Layer/MarkersLayerMapper.php @@ -12,11 +12,12 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper; use Netzmacht\Contao\Leaflet\Model\MarkerModel; use Netzmacht\Contao\Leaflet\Frontend\RequestUrl; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection; @@ -39,7 +40,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper /** * {@inheritdoc} */ - protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null) { if ($model->deferred) { return 'Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson'; @@ -52,9 +53,9 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { if ($model->deferred) { @@ -71,7 +72,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper return array( $this->getElementId($model, $elementId), - RequestUrl::create($model->id, null, null, $filter), + RequestUrl::create($model->id, null, null, $request), array(), $layer ); @@ -79,11 +80,11 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper return array( $this->getElementId($model, $elementId), - RequestUrl::create($model->id, null, null, $filter) + RequestUrl::create($model->id, null, null, $request) ); } - return parent::buildConstructArguments($model, $mapper, $filter, $elementId); + return parent::buildConstructArguments($model, $mapper, $request, $elementId); } /** @@ -91,9 +92,9 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if ($definition instanceof GeoJson) { @@ -123,10 +124,10 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper /** * {@inheritdoc} */ - public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + public function handleGeoJson(Model $model, DefinitionMapper $mapper, Request $request = null) { $feature = new FeatureCollection(); - $collection = $this->loadMarkerModels($model, $filter); + $collection = $this->loadMarkerModels($model, $request); if ($collection) { foreach ($collection as $item) { @@ -145,15 +146,15 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper /** * Load all layer markers. * - * @param \Model $model The layer model. - * @param Filter $filter The request filter. + * @param Model $model The layer model. + * @param Request $request Optional building request. * * @return \Model\Collection|null */ - protected function loadMarkerModels(\Model $model, Filter $filter = null) + protected function loadMarkerModels(Model $model, Request $request = null) { if ($model->boundsMode == 'fit') { - return MarkerModel::findByFilter($model->id, $filter); + return MarkerModel::findByFilter($model->id, $request->getFilter()); } return MarkerModel::findByFilter($model->id); diff --git a/src/Mapper/Layer/OverpassLayerMapper.php b/src/Mapper/Layer/OverpassLayerMapper.php index 587b9d7..c830662 100644 --- a/src/Mapper/Layer/OverpassLayerMapper.php +++ b/src/Mapper/Layer/OverpassLayerMapper.php @@ -12,11 +12,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Model; +use Contao\Model; use Netzmacht\Contao\Leaflet\Definition\Layer\OverpassLayer; -use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; @@ -62,7 +62,7 @@ class OverpassLayerMapper extends AbstractLayerMapper Definition $definition, Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if (!$definition instanceof OverpassLayer) { diff --git a/src/Mapper/Layer/ProviderLayerMapper.php b/src/Mapper/Layer/ProviderLayerMapper.php index 2f9f40b..9da9870 100644 --- a/src/Mapper/Layer/ProviderLayerMapper.php +++ b/src/Mapper/Layer/ProviderLayerMapper.php @@ -12,9 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\OptionsBuilder; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; /** @@ -53,7 +54,7 @@ class ProviderLayerMapper extends AbstractLayerMapper /** * {@inheritdoc} */ - protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null) { if (isset($this->providers[$model->tile_provider]['class'])) { return $this->providers[$model->tile_provider]['class']; @@ -67,9 +68,9 @@ class ProviderLayerMapper extends AbstractLayerMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if (!empty($this->providers[$model->tile_provider]['options'])) { @@ -85,9 +86,9 @@ class ProviderLayerMapper extends AbstractLayerMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { return array( diff --git a/src/Mapper/Layer/ReferenceLayerMapper.php b/src/Mapper/Layer/ReferenceLayerMapper.php index 220e836..a45cb38 100644 --- a/src/Mapper/Layer/ReferenceLayerMapper.php +++ b/src/Mapper/Layer/ReferenceLayerMapper.php @@ -12,9 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\LayerModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; /** @@ -37,7 +37,7 @@ class ReferenceLayerMapper extends AbstractLayerMapper public function handle( $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null, Definition $parent = null ) { @@ -49,6 +49,6 @@ class ReferenceLayerMapper extends AbstractLayerMapper $elementId = $model->standalone ? $this->getElementId($model, $elementId) : null; - return $mapper->handle($reference, $filter, $elementId); + return $mapper->handle($reference, $request, $elementId); } } diff --git a/src/Mapper/Layer/TileLayerMapper.php b/src/Mapper/Layer/TileLayerMapper.php index dcfac16..03d407a 100644 --- a/src/Mapper/Layer/TileLayerMapper.php +++ b/src/Mapper/Layer/TileLayerMapper.php @@ -12,8 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; +use Contao\StringUtil; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Raster\TileLayer; use Netzmacht\LeafletPHP\Value\LatLngBounds; @@ -64,12 +66,12 @@ class TileLayerMapper extends AbstractLayerMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { - $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId); + $arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId); $arguments[] = $model->tileUrl; @@ -81,26 +83,26 @@ class TileLayerMapper extends AbstractLayerMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter, $parent); + parent::build($definition, $model, $mapper, $request, $parent); /** @var TileLayer $definition */ - $filter = deserialize($model->bounds); + $bounds = StringUtil::deserialize($model->bounds); - if ($filter[0] && $filter[1]) { - $filter = array_map( + if ($request[0] && $request[1]) { + $bounds = array_map( function ($value) { return explode(',', $value, 3); }, - $filter + $bounds ); - $filter = LatLngBounds::fromArray($filter); - $definition->setBounds($filter); + $bounds = LatLngBounds::fromArray($bounds); + $definition->setBounds($bounds); } } } diff --git a/src/Mapper/Layer/VectorsLayerMapper.php b/src/Mapper/Layer/VectorsLayerMapper.php index 7aa6d90..88e7e95 100644 --- a/src/Mapper/Layer/VectorsLayerMapper.php +++ b/src/Mapper/Layer/VectorsLayerMapper.php @@ -12,16 +12,17 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; +use Contao\Model\Collection; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\GeoJsonMapper; use Netzmacht\Contao\Leaflet\Model\VectorModel; use Netzmacht\Contao\Leaflet\Frontend\RequestUrl; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\JavascriptBuilder\Type\Expression; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Value\GeoJson\FeatureCollection; use Netzmacht\LeafletPHP\Definition\Group\GeoJson; -use Netzmacht\LeafletPHP\Definition\Vector; /** * Class VectorsLayerMapper maps the layer model for the Vectors layer definition. @@ -40,7 +41,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper /** * {@inheritdoc} */ - protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + protected function getClassName(Model $model, DefinitionMapper $mapper, Request $request = null) { if ($model->deferred) { return 'Netzmacht\LeafletPHP\Plugins\Omnivore\GeoJson'; @@ -53,9 +54,9 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { if ($model->deferred) { @@ -79,7 +80,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper return array( $this->getElementId($model, $elementId), - RequestUrl::create($model->id, null, null, $filter), + RequestUrl::create($model->id, null, null, $request), array(), $layer ); @@ -87,11 +88,11 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper return array( $this->getElementId($model, $elementId), - RequestUrl::create($model->id, null, null, $filter) + RequestUrl::create($model->id, null, null, $request) ); } - return parent::buildConstructArguments($model, $mapper, $filter, $elementId); + return parent::buildConstructArguments($model, $mapper, $request, $elementId); } /** @@ -99,9 +100,9 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if ($definition instanceof GeoJson) { @@ -129,7 +130,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper /** * {@inheritdoc} */ - public function handleGeoJson(\Model $model, DefinitionMapper $mapper, Filter $filter = null) + public function handleGeoJson(Model $model, DefinitionMapper $mapper, Request $request = null) { $definition = new FeatureCollection(); $collection = $this->loadVectorModels($model); @@ -151,13 +152,13 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper /** * Load vector models. * - * @param \Model $model The layer model. + * @param Model $model The layer model. * - * @return \Model\Collection|null + * @return Collection|null */ - protected function loadVectorModels(\Model $model) + protected function loadVectorModels(Model $model) { - return VectorModel::findActiveBy('pid', $model->id, array('order' => 'sorting')); + return VectorModel::findActiveBy('pid', $model->id, ['order' => 'sorting']); } /** diff --git a/src/Mapper/MapMapper.php b/src/Mapper/MapMapper.php index 334963d..84e4dde 100644 --- a/src/Mapper/MapMapper.php +++ b/src/Mapper/MapMapper.php @@ -12,10 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Model\ControlModel; use Netzmacht\Contao\Leaflet\Model\MapModel; -use Netzmacht\JavascriptBuilder\Type\Expression; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Control; use Netzmacht\LeafletPHP\Definition\Layer; @@ -60,15 +60,15 @@ class MapMapper extends AbstractMapper */ protected function build( Definition $map, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if ($map instanceof Map && $model instanceof MapModel) { $this->buildCustomOptions($map, $model); - $this->buildControls($map, $model, $mapper, $filter); - $this->buildLayers($map, $model, $mapper, $filter); + $this->buildControls($map, $model, $mapper, $request); + $this->buildLayers($map, $model, $mapper, $request); $this->buildBoundsCalculation($map, $model); $this->buildLocate($map, $model); } @@ -78,9 +78,9 @@ class MapMapper extends AbstractMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { return array( @@ -113,14 +113,14 @@ class MapMapper extends AbstractMapper /** * Build map controls. * - * @param Map $map The map being built. - * @param MapModel $model The map model. - * @param DefinitionMapper $mapper The definition mapper. - * @param Filter $filter Optional request filter. + * @param Map $map The map being built. + * @param MapModel $model The map model. + * @param DefinitionMapper $mapper The definition mapper. + * @param Request $request Optional building request. * * @return void */ - private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, Filter $filter = null) + private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, Request $request = null) { $collection = ControlModel::findActiveBy('pid', $model->id, array('order' => 'sorting')); @@ -129,7 +129,7 @@ class MapMapper extends AbstractMapper } foreach ($collection as $control) { - $control = $mapper->handle($control, $filter, null, $map); + $control = $mapper->handle($control, $request, null, $map); if ($control instanceof Control) { $control->addTo($map); @@ -140,14 +140,14 @@ class MapMapper extends AbstractMapper /** * Build map layers. * - * @param Map $map The map being built. - * @param MapModel $model The map model. - * @param DefinitionMapper $mapper Definition mapper. - * @param Filter $filter Optional request filter. + * @param Map $map The map being built. + * @param MapModel $model The map model. + * @param DefinitionMapper $mapper Definition mapper. + * @param Request $request Optional building request. * * @return void */ - private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, Filter $filter = null) + private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, Request $request = null) { $collection = $model->findActiveLayers(); @@ -157,7 +157,7 @@ class MapMapper extends AbstractMapper continue; } - $layer = $mapper->handle($layer, $filter, null, $map); + $layer = $mapper->handle($layer, $request, null, $map); if ($layer instanceof Layer) { $layer->addTo($map); } @@ -197,7 +197,6 @@ class MapMapper extends AbstractMapper } } - /** * Build map bounds calculations. * diff --git a/src/Mapper/Mapper.php b/src/Mapper/Mapper.php index f4a651f..c19caf7 100644 --- a/src/Mapper/Mapper.php +++ b/src/Mapper/Mapper.php @@ -12,7 +12,8 @@ namespace Netzmacht\Contao\Leaflet\Mapper; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; /** @@ -25,9 +26,9 @@ interface Mapper /** * Map model to the definition. * - * @param \Model|mixed $model The model being built. Usually a contao model, but can be anything. + * @param Model|mixed $model The model being built. Usually a contao model, but can be anything. * @param DefinitionMapper $mapper The definition builder. - * @param Filter $filter Optional filter bounds. + * @param Request $request Optional building request. * @param string $elementId Optional element. * @param Definition|null $parent Optional passed parent. * @@ -36,7 +37,7 @@ interface Mapper public function handle( $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null, Definition $parent = null ); @@ -44,10 +45,10 @@ interface Mapper /** * Check if mapper is responsible for the model. * - * @param \Model $model The model being build. - * @param Filter $filter Optional filter bounds. + * @param Model $model The model being build. + * @param Request $request Optional building request. * * @return bool */ - public function match($model, Filter $filter = null); + public function match($model, Request $request = null); } diff --git a/src/Mapper/OptionsBuilder.php b/src/Mapper/OptionsBuilder.php index 0f13cbd..76ad217 100644 --- a/src/Mapper/OptionsBuilder.php +++ b/src/Mapper/OptionsBuilder.php @@ -11,6 +11,7 @@ */ namespace Netzmacht\Contao\Leaflet\Mapper; +use Contao\Model; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\HasOptions; @@ -199,7 +200,7 @@ class OptionsBuilder * * @param array $options The options. * @param Definition $definition The definition being built. - * @param \Model $model The model. + * @param Model $model The model. * * @return void */ diff --git a/src/Mapper/Style/FixedStyleMapper.php b/src/Mapper/Style/FixedStyleMapper.php index 4fa1ed2..6212eb9 100644 --- a/src/Mapper/Style/FixedStyleMapper.php +++ b/src/Mapper/Style/FixedStyleMapper.php @@ -9,6 +9,7 @@ * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE * @filesource */ + namespace Netzmacht\Contao\Leaflet\Mapper\Style; /** diff --git a/src/Mapper/Type/DivIconMapper.php b/src/Mapper/Type/DivIconMapper.php index c7a596b..4509839 100644 --- a/src/Mapper/Type/DivIconMapper.php +++ b/src/Mapper/Type/DivIconMapper.php @@ -12,8 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Type; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\DivIcon; @@ -53,12 +54,12 @@ class DivIconMapper extends AbstractIconMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof DivIcon && $model->iconSize) { $definition->setIconSize(explode(',', $model->iconSize, 2)); diff --git a/src/Mapper/Type/ExtraMarkersIconMapper.php b/src/Mapper/Type/ExtraMarkersIconMapper.php index ac768dd..82660ae 100644 --- a/src/Mapper/Type/ExtraMarkersIconMapper.php +++ b/src/Mapper/Type/ExtraMarkersIconMapper.php @@ -12,8 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Type; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\DivIcon; @@ -53,12 +54,12 @@ class ExtraMarkersIconMapper extends AbstractIconMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof DivIcon && $model->iconSize) { $definition->setIconSize(explode(',', $model->iconSize, 2)); diff --git a/src/Mapper/Type/ImageIconMapper.php b/src/Mapper/Type/ImageIconMapper.php index 830a525..d444da9 100644 --- a/src/Mapper/Type/ImageIconMapper.php +++ b/src/Mapper/Type/ImageIconMapper.php @@ -12,9 +12,10 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Type; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; @@ -43,12 +44,12 @@ class ImageIconMapper extends AbstractIconMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { - $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId); + $arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId); if ($model->iconImage) { $file = \FilesModel::findByUuid($model->iconImage); @@ -66,9 +67,9 @@ class ImageIconMapper extends AbstractIconMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if ($definition instanceof ImageIcon) { diff --git a/src/Mapper/UI/MarkerMapper.php b/src/Mapper/UI/MarkerMapper.php index 1581100..a055f31 100644 --- a/src/Mapper/UI/MarkerMapper.php +++ b/src/Mapper/UI/MarkerMapper.php @@ -12,12 +12,13 @@ namespace Netzmacht\Contao\Leaflet\Mapper\UI; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\Contao\Leaflet\Model\PopupModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\UI\Marker; @@ -67,12 +68,12 @@ class MarkerMapper extends AbstractMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { - $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId); + $arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId); $arguments[] = array($model->latitude, $model->longitude, $model->altitude ?: null) ?: null; return $arguments; @@ -95,9 +96,9 @@ class MarkerMapper extends AbstractMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { if ($definition instanceof Marker) { @@ -109,7 +110,7 @@ class MarkerMapper extends AbstractMapper $popupModel = PopupModel::findActiveByPK($model->popup); if ($popupModel) { - $popup = $mapper->handle($popupModel, $filter, null, $definition); + $popup = $mapper->handle($popupModel, $request, null, $definition); } } diff --git a/src/Mapper/UI/PopupMapper.php b/src/Mapper/UI/PopupMapper.php index 48bd9bb..6b4eb05 100644 --- a/src/Mapper/UI/PopupMapper.php +++ b/src/Mapper/UI/PopupMapper.php @@ -12,10 +12,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\UI; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\PopupModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\UI\Popup; @@ -60,12 +61,12 @@ class PopupMapper extends AbstractMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter, $parent); + parent::build($definition, $model, $mapper, $request, $parent); /** @var Popup $definition */ /** @var PopupModel $model */ diff --git a/src/Mapper/Vector/AbstractVectorMapper.php b/src/Mapper/Vector/AbstractVectorMapper.php index 5fbce8f..23ee469 100644 --- a/src/Mapper/Vector/AbstractVectorMapper.php +++ b/src/Mapper/Vector/AbstractVectorMapper.php @@ -12,13 +12,14 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; +use Contao\Model; use Netzmacht\Contao\Leaflet\Definition\Style; -use Netzmacht\Contao\Leaflet\Filter\Filter; use Netzmacht\Contao\Leaflet\Frontend\ValueFilter; use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Model\PopupModel; use Netzmacht\Contao\Leaflet\Model\StyleModel; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\HasPopup; use Netzmacht\LeafletPHP\Definition\UI\Popup; @@ -62,12 +63,12 @@ class AbstractVectorMapper extends AbstractTypeMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof Path && $model->style) { $styleModel = StyleModel::findActiveByPK($model->style); @@ -81,24 +82,24 @@ class AbstractVectorMapper extends AbstractTypeMapper } } - $this->buildPopup($definition, $model, $mapper, $filter); + $this->buildPopup($definition, $model, $mapper, $request); } /** * Build the popup. * * @param Definition $definition The definition. - * @param \Model $model The model. + * @param Model $model The model. * @param DefinitionMapper $mapper The definition mapper. - * @param Filter $filter The filter. + * @param Request $request Optional building request. * * @return void */ protected function buildPopup( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null + Request $request = null ) { if ($definition instanceof HasPopup && $model->addPopup) { $popup = null; @@ -108,7 +109,7 @@ class AbstractVectorMapper extends AbstractTypeMapper $popupModel = PopupModel::findActiveByPK($model->popup); if ($popupModel) { - $popup = $mapper->handle($popupModel, $filter, null, $definition); + $popup = $mapper->handle($popupModel, $request, null, $definition); } } diff --git a/src/Mapper/Vector/CircleMapper.php b/src/Mapper/Vector/CircleMapper.php index d8cfa3e..2eff2df 100644 --- a/src/Mapper/Vector/CircleMapper.php +++ b/src/Mapper/Vector/CircleMapper.php @@ -12,12 +12,12 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Vector\CircleMarker; use Netzmacht\LeafletPHP\Value\LatLng; -use Netzmacht\LeafletPHP\Definition\Vector\Circle; /** * Class CircleMapper maps the database model to the circle definition. @@ -55,12 +55,12 @@ class CircleMapper extends AbstractVectorMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof CircleMarker) { $definition->setLatLng(LatLng::fromString($model->coordinates)); diff --git a/src/Mapper/Vector/MultiPolygonMapper.php b/src/Mapper/Vector/MultiPolygonMapper.php index 25642e9..db1309e 100644 --- a/src/Mapper/Vector/MultiPolygonMapper.php +++ b/src/Mapper/Vector/MultiPolygonMapper.php @@ -12,8 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Vector\Polygon; @@ -43,12 +44,12 @@ class MultiPolygonMapper extends MultiPolylineMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof Polygon) { $this->createLatLngs($definition, $model); diff --git a/src/Mapper/Vector/MultiPolylineMapper.php b/src/Mapper/Vector/MultiPolylineMapper.php index 93736a7..6d1ec0e 100644 --- a/src/Mapper/Vector/MultiPolylineMapper.php +++ b/src/Mapper/Vector/MultiPolylineMapper.php @@ -12,8 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition\Vector\Polyline; use Netzmacht\LeafletPHP\Value\LatLng; @@ -44,12 +45,12 @@ class MultiPolylineMapper extends AbstractVectorMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof Polyline) { $this->createLatLngs($definition, $model); @@ -60,11 +61,11 @@ class MultiPolylineMapper extends AbstractVectorMapper * Create lat lngs for the definition. * * @param Polyline $definition The multi polyline. - * @param \Model $model The definition model. + * @param Model $model The definition model. * * @return void */ - protected function createLatLngs(Polyline $definition, \Model $model) + protected function createLatLngs(Polyline $definition, Model $model) { foreach (deserialize($model->multiData, true) as $ring => $data) { $latLngs = array_map( diff --git a/src/Mapper/Vector/PolylineMapper.php b/src/Mapper/Vector/PolylineMapper.php index d7e3b09..57ab68f 100644 --- a/src/Mapper/Vector/PolylineMapper.php +++ b/src/Mapper/Vector/PolylineMapper.php @@ -12,8 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Value\LatLng; use Netzmacht\LeafletPHP\Definition\Vector\Polyline; @@ -44,12 +45,12 @@ class PolylineMapper extends AbstractVectorMapper */ protected function build( Definition $definition, - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, Definition $parent = null ) { - parent::build($definition, $model, $mapper, $filter); + parent::build($definition, $model, $mapper, $request); if ($definition instanceof Polyline) { array_map( diff --git a/src/Mapper/Vector/RectangleMapper.php b/src/Mapper/Vector/RectangleMapper.php index 3d4757c..4b178c7 100644 --- a/src/Mapper/Vector/RectangleMapper.php +++ b/src/Mapper/Vector/RectangleMapper.php @@ -12,9 +12,9 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Vector; -use Netzmacht\Contao\Leaflet\Filter\Filter; +use Contao\Model; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; -use Netzmacht\LeafletPHP\Definition; +use Netzmacht\Contao\Leaflet\Request\Request; use Netzmacht\LeafletPHP\Value\LatLng; use Netzmacht\LeafletPHP\Value\LatLngBounds; @@ -43,9 +43,9 @@ class RectangleMapper extends AbstractVectorMapper * {@inheritdoc} */ protected function buildConstructArguments( - \Model $model, + Model $model, DefinitionMapper $mapper, - Filter $filter = null, + Request $request = null, $elementId = null ) { $latLngs = array_map( @@ -55,7 +55,7 @@ class RectangleMapper extends AbstractVectorMapper deserialize($model->bounds, true) ); - $arguments = parent::buildConstructArguments($model, $mapper, $filter, $elementId); + $arguments = parent::buildConstructArguments($model, $mapper, $request, $elementId); $arguments[] = new LatLngBounds($latLngs[0], $latLngs[1]); return $arguments; diff --git a/src/Model/AbstractActiveModel.php b/src/Model/AbstractActiveModel.php index 7ec2c9a..c493711 100644 --- a/src/Model/AbstractActiveModel.php +++ b/src/Model/AbstractActiveModel.php @@ -12,6 +12,8 @@ namespace Netzmacht\Contao\Leaflet\Model; +use Contao\Model\Collection; + /** * Class AbstractActiveModel is the base model for models with an active field. * @@ -39,7 +41,7 @@ abstract class AbstractActiveModel extends \Model * @param mixed $value The column value. * @param array $options The options. * - * @return \Model|null + * @return Collection|null */ public static function findActiveBy($column, $value, $options = array()) { @@ -57,7 +59,7 @@ abstract class AbstractActiveModel extends \Model * * @param array $options The query options. * - * @return \Model\Collection|null + * @return Collection|null */ public static function findActives($options = array()) { diff --git a/src/Request/Request.php b/src/Request/Request.php new file mode 100644 index 0000000..5ae967d --- /dev/null +++ b/src/Request/Request.php @@ -0,0 +1,71 @@ + + * @copyright 2016-2017 netzmacht David Molineus. All rights reserved. + * @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE + * @filesource + */ + +declare(strict_types=1); + +namespace Netzmacht\Contao\Leaflet\Request; + +use Netzmacht\Contao\Leaflet\Filter\Filter; + +/** + * Class MapRequest + * + * @package Netzmacht\Contao\Leaflet\Request + */ +class Request +{ + /** + * Map identifier. + * + * @var string + */ + private $identifier; + + /** + * Request filter. + * + * @var Filter|null + */ + private $filter; + + /** + * Request constructor. + * + * @param string $identifier Map identifier. + * @param Filter|null $filter Filter. + */ + public function __construct($identifier, Filter $filter = null) + { + $this->identifier = $identifier; + $this->filter = $filter; + } + + /** + * Get the map identifier. + * + * @return string + */ + public function getMapIdentifier(): string + { + return $this->identifier; + } + + /** + * Get the filter. + * + * @return Filter|null + */ + public function getFilter() + { + return $this->filter; + } +}