2015-01-09 15:24:34 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-05 15:45:43 +02:00
|
|
|
* Leaflet maps for Contao CMS.
|
|
|
|
|
*
|
2016-10-11 10:40:15 +02:00
|
|
|
* @package contao-leaflet-maps
|
2015-01-09 15:24:34 +01:00
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
2017-10-11 15:00:48 +02:00
|
|
|
* @copyright 2014-2017 netzmacht David Molineus. All rights reserved.
|
2017-10-05 15:45:43 +02:00
|
|
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
2015-01-09 15:24:34 +01:00
|
|
|
* @filesource
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
|
|
|
|
|
|
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
2017-10-17 18:03:42 +02:00
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\Request;
|
2015-01-09 15:24:34 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
2017-10-19 08:45:39 +02:00
|
|
|
use Netzmacht\Contao\Toolkit\Data\Model\RepositoryManager;
|
2015-01-20 16:38:23 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition;
|
2015-01-09 15:24:34 +01:00
|
|
|
|
|
|
|
|
/**
|
2015-01-12 19:03:29 +01:00
|
|
|
* Class ReferenceLayerMapper maps an reference layer to another layer.
|
2015-01-09 15:24:34 +01:00
|
|
|
*
|
|
|
|
|
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
|
|
|
|
*/
|
|
|
|
|
class ReferenceLayerMapper extends AbstractLayerMapper
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Layer type.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected static $type = 'reference';
|
|
|
|
|
|
2017-10-19 08:45:39 +02:00
|
|
|
/**
|
|
|
|
|
* Repository manager.
|
|
|
|
|
*
|
|
|
|
|
* @var RepositoryManager
|
|
|
|
|
*/
|
|
|
|
|
private $repositoryManager;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct.
|
|
|
|
|
*
|
|
|
|
|
* @param RepositoryManager $repositoryManager Repository manager.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(RepositoryManager $repositoryManager)
|
|
|
|
|
{
|
|
|
|
|
$this->repositoryManager = $repositoryManager;
|
|
|
|
|
|
|
|
|
|
parent::__construct();
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 15:24:34 +01:00
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2015-01-20 17:43:41 +01:00
|
|
|
public function handle(
|
|
|
|
|
$model,
|
|
|
|
|
DefinitionMapper $mapper,
|
2017-10-11 14:27:37 +02:00
|
|
|
Request $request = null,
|
2015-01-20 17:43:41 +01:00
|
|
|
$elementId = null,
|
|
|
|
|
Definition $parent = null
|
|
|
|
|
) {
|
2017-10-19 08:45:39 +02:00
|
|
|
$repository = $this->repositoryManager->getRepository(LayerModel::class);
|
|
|
|
|
$reference = $repository->findByPk($model->reference);
|
2015-01-09 15:24:34 +01:00
|
|
|
|
|
|
|
|
if (!$reference || !$reference->active) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-12 09:29:48 +01:00
|
|
|
$elementId = $model->standalone ? $this->getElementId($model, $elementId) : null;
|
|
|
|
|
|
2017-10-11 14:27:37 +02:00
|
|
|
return $mapper->handle($reference, $request, $elementId);
|
2015-01-09 15:24:34 +01:00
|
|
|
}
|
|
|
|
|
}
|