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

78 lines
1.9 KiB
PHP
Raw Normal View History

2015-01-07 12:13:26 +01:00
<?php
/**
2016-10-11 10:40:15 +02:00
* @package contao-leaflet-maps
2015-01-07 12:13:26 +01:00
* @author David Molineus <david.molineus@netzmacht.de>
2016-10-11 10:40:15 +02:00
* @copyright 2014-2016 netzmacht David Molineus
2015-01-07 12:13:26 +01:00
* @license LGPL 3.0
* @filesource
*
*/
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Filter\Filter;
2015-01-07 12:13:26 +01:00
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;
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
{
/**
* Layer type.
*
* @var string
*/
protected static $type = 'group';
/**
* {@inheritdoc}
*/
protected function getClassName(\Model $model, DefinitionMapper $mapper, Filter $filter = 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-22 11:59:19 +01:00
return 'Netzmacht\LeafletPHP\Definition\Group\LayerGroup';
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,
Filter $filter = null,
2015-01-20 16:38:23 +01:00
Definition $parent = null
2015-01-07 12:13:26 +01:00
) {
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
}
}
}
}