Fix code style.

This commit is contained in:
David Molineus
2015-01-12 19:03:29 +01:00
parent 74c786c24b
commit 037c6c907d
77 changed files with 1068 additions and 398 deletions

View File

@@ -24,7 +24,7 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
abstract class AbstractMapper implements Mapper
{
const VALUE_NOT_EMPTY = '__value_not_empty__';
const VALUE_EMPTY = '__value_empty__';
const VALUE_EMPTY = '__value_empty__';
/**
* Class of the model being build.
@@ -190,6 +190,8 @@ abstract class AbstractMapper implements Mapper
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function build(
Definition $definition,
@@ -224,12 +226,14 @@ abstract class AbstractMapper implements Mapper
/**
* Get construct arguments.
*
* @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param \Model $model The model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string|null $elementId Optional element id.
*
* @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function buildConstructArguments(
\Model $model,
@@ -301,6 +305,8 @@ abstract class AbstractMapper implements Mapper
* @param array $options The options.
* @param Definition $definition The definition being built.
* @param \Model $model The model.
*
* @return void
*/
protected function applyOptions($options, $definition, $model)
{
@@ -312,8 +318,7 @@ abstract class AbstractMapper implements Mapper
if (((bool) $model->$option) !== $default) {
$definition->$setter($model->$mapping);
}
}
elseif ($model->$mapping !== $default) {
} elseif ($model->$mapping !== $default) {
$definition->$setter($model->$mapping);
}
}
@@ -351,6 +356,8 @@ abstract class AbstractMapper implements Mapper
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return string
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{

View File

@@ -13,11 +13,23 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class AbstractTypeMapper is the base mapper for tables containing different types of definitins.
*
* @package Netzmacht\Contao\Leaflet\Mapper
*/
abstract class AbstractTypeMapper extends AbstractMapper
{
/**
* The definition type.
*
* @var string
*/
protected static $type;
/**
* {@inheritdoc}
*/
public function match($model, LatLngBounds $bounds = null)
{
return parent::match($model) && $model->type === static::$type;

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
/**
* Class AbstractControlMapper is the base mapper for the control model.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Control
*/
class AbstractControlMapper extends AbstractTypeMapper
{
/**

View File

@@ -11,12 +11,16 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class LayersControlMapper maps the control model to the layers control definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Control
*/
class LayersControlMapper extends AbstractControlMapper
{
/**

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\LeafletPHP\Definition;
@@ -20,6 +19,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Plugins\Loading\LoadingControl;
use Netzmacht\LeafletPHP\Plugins\Loading\SpinJsLoadingControl;
/**
* Class LoadingControlMapper maps the control model to the loading control definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Control
*/
class LoadingControlMapper extends AbstractControlMapper
{
/**
@@ -77,7 +81,7 @@ class LoadingControlMapper extends AbstractControlMapper
}
}
if ($definition instanceof LoadingControl && !$definition->isSeparate() && $model->zoomControl ) {
if ($definition instanceof LoadingControl && !$definition->isSeparate() && $model->zoomControl) {
// Only assign if zoom control is activated and part of the map.
$control = ControlModel::findOneBy(
array('active=1', 'type=?', 'pid=?', 'id=?'),

View File

@@ -27,9 +27,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatche
class DefinitionMapper
{
/**
* Registered builders.
* Lit of all registered mappers.
*
* @var AbstractMapper[][]
* @var Mapper[][]
*/
private $builders = array();
@@ -41,6 +41,8 @@ class DefinitionMapper
private $eventDispatcher;
/**
* Cache of mapped definitions.
*
* @var array
*/
private $mapped = array();
@@ -79,7 +81,9 @@ class DefinitionMapper
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. If none given the mapId or alias is used.
*
* @return Definition
* @return Definition|null
*
* @throws \RuntimeException If model could not be mapped to a definition.
*/
public function handle($model, LatLngBounds $bounds = null, $elementId = null)
{
@@ -90,7 +94,7 @@ class DefinitionMapper
}
foreach ($this->builders as $builders) {
foreach($builders as $builder) {
foreach ($builders as $builder) {
if ($builder->match($model)) {
$definition = $builder->handle($model, $this, $bounds, $elementId);
@@ -118,10 +122,12 @@ class DefinitionMapper
/**
* Build a model.
*
* @param mixed $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param mixed $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*
* @return FeatureCollection|Feature
* @return FeatureCollection|Feature|null
*
* @throws \RuntimeException If a model could not be mapped to the GeoJSON representation.
*/
public function handleGeoJson($model, LatLngBounds $bounds = null)
{
@@ -155,9 +161,14 @@ class DefinitionMapper
}
/**
* @param $model
* Get the hash of a model.
*
* @param mixed $model The definition model.
* @param string|null $elementId Optional defined extra element id.
*
* @return string
*
* @throws \RuntimeException If no hash was created.
*/
protected function getHash($model, $elementId)
{

View File

@@ -11,16 +11,24 @@
namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition\GeoJson\GeoJsonFeature;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Interface GeoJsonMapper describes mappers which can convert their definition to a GeoJSON representation.
*
* @package Netzmacht\Contao\Leaflet\Mapper
*/
interface GeoJsonMapper
{
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
* Hanle the GeoJSON creation.
*
* @return mixed
* @param \Model $model The model being mapped.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds The requested bounds.
*
* @return GeoJsonFeature|null
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
}

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
/**
* Class AbstractLayerMapper is the base mapper for the layer model.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
class AbstractLayerMapper extends AbstractTypeMapper
{
/**
@@ -22,6 +27,9 @@ class AbstractLayerMapper extends AbstractTypeMapper
*/
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
/**
* {@inheritdoc}
*/
protected function initialize()
{
parent::initialize();

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition;
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Layer;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class GroupLayerMapper maps the layer model to the group layer definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
class GroupLayerMapper extends AbstractLayerMapper
{
/**
@@ -44,7 +48,7 @@ class GroupLayerMapper extends AbstractLayerMapper
return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup';
}
return parent::getClassName($model, $mapper, $bounds); // TODO: Change the autogenerated stub
return parent::getClassName($model, $mapper, $bounds);
}
/**

View File

@@ -24,6 +24,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
/**
* Class MarkersLayerMapper maps the layer model to the markers definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{
/**
@@ -81,11 +86,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
}
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
* {@inheritdoc}
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
@@ -106,18 +107,14 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
}
/**
* @param \Model $model
* Load all layer markers.
*
* @param \Model $model The layer model.
*
* @return \Model\Collection|null
*/
protected function loadMarkerModels(\Model $model)
{
$collection = MarkerModel::findBy(
array('active=1', 'pid=?'),
array($model->id),
array('order' => 'sorting')
);
return $collection;
return MarkerModel::findActiveBy('pid', $model->id, array('order' => 'sorting'));
}
}

View File

@@ -15,6 +15,11 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class ProviderLayerMapper maps the layer model to the tile provider definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
class ProviderLayerMapper extends AbstractLayerMapper
{
/**

View File

@@ -16,7 +16,7 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class ReferenceLayerMapper maps an reference layer to another
* Class ReferenceLayerMapper maps an reference layer to another layer.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/

View File

@@ -26,6 +26,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
/**
* Class VectorsLayerMapper maps the layer model for the Vectors layer definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{
/**
@@ -87,11 +92,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
}
/**
* @param \Model $model
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
* {@inheritdoc}
*/
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
@@ -114,19 +115,14 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
}
/**
* @param \Model $model
* Load vector models.
*
* @param \Model $model The layer model.
*
* @return \Model\Collection|null
*/
protected function loadVectorModels(\Model $model)
{
$collection = VectorModel::findBy(
array('active=1', 'pid=?'),
array($model->id),
array('order' => 'sorting')
);
return $collection;
return VectorModel::findActiveBy('pid', $model->id, array('order' => 'sorting'));
}
}

View File

@@ -20,7 +20,11 @@ use Netzmacht\LeafletPHP\Definition\Layer;
use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class MapMapper maps the database map model to the leaflet definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper
*/
class MapMapper extends AbstractMapper
{
/**
@@ -38,7 +42,7 @@ class MapMapper extends AbstractMapper
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Map';
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function initialize()
{
@@ -51,7 +55,7 @@ class MapMapper extends AbstractMapper
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function build(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
{
@@ -63,7 +67,7 @@ class MapMapper extends AbstractMapper
}
/**
* @inheritdoc
* {@inheritdoc}
*/
protected function buildConstructArguments(
\Model $model,
@@ -99,6 +103,8 @@ class MapMapper extends AbstractMapper
* @param MapModel $model The map model.
* @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds.
*
* @return void
*/
private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{
@@ -124,6 +130,8 @@ class MapMapper extends AbstractMapper
* @param MapModel $model The map model.
* @param DefinitionMapper $mapper Definition mapper.
* @param LatLngBounds $bounds Optional bounds.
*
* @return void
*/
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{

View File

@@ -14,12 +14,17 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Interface Mapper describes the Mapper which translates a given configuration to the Leaflet definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper
*/
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 LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id.

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Style;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
/**
* Class AbstractStyleMapper is the base mapper for the style model.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Style
*/
abstract class AbstractStyleMapper extends AbstractTypeMapper
{
/**

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Style;
use Netzmacht\LeafletPHP\Definition;
/**
* Class FixedStyleMapper maps the fixed style to the corresponding definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Style
*/
class FixedStyleMapper extends AbstractStyleMapper
{
/**

View File

@@ -11,9 +11,13 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
/**
* Class AbstractIconMapper is the base mapper for the icon model.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Type
*/
class AbstractIconMapper extends AbstractTypeMapper
{
/**

View File

@@ -11,12 +11,16 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\DivIcon;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class DivIconMapper maps the icon model to the div icon definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Type
*/
class DivIconMapper extends AbstractIconMapper
{
/**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\IconModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
/**
* Class ImageIconMapper maps the icon model to the image icon definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Type
*/
class ImageIconMapper extends AbstractIconMapper
{
/**
@@ -74,7 +78,7 @@ class ImageIconMapper extends AbstractIconMapper
/**
* Add icon image.
*
* @param ImageIcon $definition The icon definition.
* @param ImageIcon $definition The icon definition.
* @param IconModel $model The model.
*
* @return void
@@ -116,7 +120,7 @@ class ImageIconMapper extends AbstractIconMapper
/**
* Add shadow if defined.
*
* @param ImageIcon $definition The icon definition.
* @param ImageIcon $definition The icon definition.
* @param IconModel $model The model.
*
* @return void

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\UI;
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\IconModel;
@@ -20,6 +19,11 @@ use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker;
/**
* Class MarkerMapper maps the marker model to the marker definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\UI
*/
class MarkerMapper extends AbstractMapper
{
/**

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
@@ -21,6 +20,11 @@ use Netzmacht\LeafletPHP\Definition\HasPopup;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Path;
/**
* Class AbstractVectorMapper is the base class for the vector model definition mapping.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class AbstractVectorMapper extends AbstractTypeMapper
{
/**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
/**
* Class CircleMapper maps the database model to the circle definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class CircleMapper extends AbstractVectorMapper
{
/**
@@ -34,6 +38,9 @@ class CircleMapper extends AbstractVectorMapper
*/
protected static $type = 'circle';
/**
* {@inheritdoc}
*/
protected function initialize()
{
parent::initialize();
@@ -41,6 +48,9 @@ class CircleMapper extends AbstractVectorMapper
$this->addOption('radius');
}
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
/**
* Class CircleMarkerMapper maps the database model to the circle marker definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class CircleMarkerMapper extends CircleMapper
{
/**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon;
/**
* Class MultiPolygonMapper maps the multi polygon database model to its definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class MultiPolygonMapper extends MultiPolylineMapper
{
/**
@@ -34,6 +38,9 @@ class MultiPolygonMapper extends MultiPolylineMapper
*/
protected static $type = 'multiPolygon';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
@@ -43,18 +50,7 @@ class MultiPolygonMapper extends MultiPolylineMapper
parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolygon) {
$latLngs = array();
foreach (deserialize($model->multiData, true) as $data) {
$latLngs[] = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
}
$definition->setLatLngs($latLngs);
$this->createLatLngs($definition, $model);
}
}
}

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolyline;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
/**
* Class MultiPolylineMapper maps the databse model it the multi polyline definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class MultiPolylineMapper extends AbstractVectorMapper
{
/**
@@ -35,7 +39,9 @@ class MultiPolylineMapper extends AbstractVectorMapper
*/
protected static $type = 'multiPolyline';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,
@@ -45,18 +51,31 @@ class MultiPolylineMapper extends AbstractVectorMapper
parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolyline) {
$latLngs = array();
foreach (deserialize($model->multiData, true) as $data) {
$latLngs[] = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
}
$definition->setLatLngs($latLngs);
$this->createLatLngs($definition, $model);
}
}
/**
* Create lat lngs for the definition.
*
* @param MultiPolyline $definition The multi polyline.
* @param \Model $model The definition model.
*
* @return void
*/
protected function createLatLngs(MultiPolyline $definition, \Model $model)
{
$latLngs = array();
foreach (deserialize($model->multiData, true) as $data) {
$latLngs[] = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
}
$definition->setLatLngs($latLngs);
}
}

View File

@@ -11,6 +11,11 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
/**
* Class PolygonMapper maps the database model to the polygon definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class PolygonMapper extends PolylineMapper
{
/**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
/**
* Class PolylineMapper maps the database model to the polyline definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class PolylineMapper extends AbstractVectorMapper
{
/**
@@ -34,7 +38,9 @@ class PolylineMapper extends AbstractVectorMapper
*/
protected static $type = 'polyline';
/**
* {@inheritdoc}
*/
protected function build(
Definition $definition,
\Model $model,

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
use Netzmacht\LeafletPHP\Definition\Vector\Rectangle;
/**
* Class RectangleMapper maps a database model to its rectangle vector definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
*/
class RectangleMapper extends AbstractVectorMapper
{
/**
@@ -35,11 +39,9 @@ class RectangleMapper extends AbstractVectorMapper
*/
protected static $type = 'rectangle';
protected function initialize()
{
parent::initialize();
}
/**
* {@inheritdoc}
*/
protected function buildConstructArguments(
\Model $model,
DefinitionMapper $mapper,
@@ -47,7 +49,7 @@ class RectangleMapper extends AbstractVectorMapper
$elementId = null
) {
$latLngs = array_map(
function($latLng) {
function ($latLng) {
return LatLng::fromString($latLng);
},
deserialize($model->bounds, true)