Files
contao-leaflet-maps/src/Netzmacht/Contao/Leaflet/Mapper/Layer/GroupLayerMapper.php

84 lines
2.0 KiB
PHP
Raw Normal View History

2015-01-07 12:13:26 +01:00
<?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\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Layer;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
2015-01-12 19:03:29 +01:00
/**
* Class GroupLayerMapper maps the layer model to the group layer definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
2015-01-07 12:13:26 +01:00
class GroupLayerMapper extends AbstractLayerMapper
{
/**
* Class of the definition being created.
*
* @var string
*/
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Group\LayerGroup';
/**
* Layer type.
*
* @var string
*/
protected static $type = 'group';
/**
* {@inheritdoc}
*/
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
2015-01-07 12:13:26 +01:00
{
if ($model->groupType === 'feature') {
return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup';
}
2015-01-07 12:13:26 +01:00
2015-01-12 19:03:29 +01:00
return parent::getClassName($model, $mapper, $bounds);
2015-01-07 12:13:26 +01:00
}
/**
* {@inheritdoc}
*/
protected function build(
2015-01-07 12:13:26 +01:00
Definition $definition,
\Model $model,
DefinitionMapper $mapper,
LatLngBounds $bounds = null
) {
if (!$definition instanceof LayerGroup) {
return;
}
$collection = LayerModel::findBy(
array('pid=?', 'active=1'),
array($model->id),
array('order' => 'sorting')
);
if ($collection) {
foreach ($collection as $layerModel) {
$layer = $mapper->handle($layerModel);
2015-01-09 13:41:09 +01:00
if ($layer instanceof Layer) {
$definition->addLayer($layer);
}
2015-01-07 12:13:26 +01:00
}
}
}
}