2015-01-07 17:59:56 +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-07 17:59:56 +01:00
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
2017-10-05 15:45:43 +02:00
|
|
|
* @copyright 2016-2017 netzmacht David Molineus. All rights reserved.
|
|
|
|
|
* @license LGPL-3.0 https://github.com/netzmacht/contao-leaflet-maps/blob/master/LICENSE
|
2015-01-07 17:59:56 +01:00
|
|
|
* @filesource
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
|
|
|
|
|
2017-10-11 14:27:37 +02:00
|
|
|
use Contao\Model;
|
2015-01-09 11:53:58 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Definition\Style;
|
2015-02-02 08:44:17 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Frontend\ValueFilter;
|
2015-01-07 17:59:56 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
|
|
|
|
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
2015-01-27 18:17:05 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Model\PopupModel;
|
2015-01-09 11:53:58 +01:00
|
|
|
use Netzmacht\Contao\Leaflet\Model\StyleModel;
|
2017-10-11 14:27:37 +02:00
|
|
|
use Netzmacht\Contao\Leaflet\Request\Request;
|
2015-01-07 17:59:56 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition;
|
2015-01-09 11:53:58 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition\HasPopup;
|
2015-01-27 18:17:05 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition\UI\Popup;
|
2015-01-09 11:53:58 +01:00
|
|
|
use Netzmacht\LeafletPHP\Definition\Vector\Path;
|
2015-01-07 17:59:56 +01:00
|
|
|
|
2015-01-12 19:03:29 +01:00
|
|
|
/**
|
|
|
|
|
* Class AbstractVectorMapper is the base class for the vector model definition mapping.
|
|
|
|
|
*
|
|
|
|
|
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
|
|
|
|
*/
|
2015-01-07 17:59:56 +01:00
|
|
|
class AbstractVectorMapper extends AbstractTypeMapper
|
|
|
|
|
{
|
|
|
|
|
/**
|
|
|
|
|
* Class of the model being build.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\VectorModel';
|
|
|
|
|
|
2015-02-02 08:44:17 +01:00
|
|
|
/**
|
|
|
|
|
* Frontend filter.
|
|
|
|
|
*
|
|
|
|
|
* @var ValueFilter
|
|
|
|
|
*/
|
|
|
|
|
protected $valueFilter;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct.
|
|
|
|
|
*
|
|
|
|
|
* @param ValueFilter $valueFilter Frontend filter.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct(ValueFilter $valueFilter)
|
|
|
|
|
{
|
|
|
|
|
parent::__construct();
|
|
|
|
|
|
|
|
|
|
$this->valueFilter = $valueFilter;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-09 13:41:09 +01:00
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2015-01-08 09:51:43 +01:00
|
|
|
protected function build(
|
2015-01-07 17:59:56 +01:00
|
|
|
Definition $definition,
|
2017-10-11 14:27:37 +02:00
|
|
|
Model $model,
|
2015-01-09 11:53:58 +01:00
|
|
|
DefinitionMapper $mapper,
|
2017-10-11 14:27:37 +02:00
|
|
|
Request $request = null,
|
2015-01-20 16:38:23 +01:00
|
|
|
Definition $parent = null
|
2015-01-07 17:59:56 +01:00
|
|
|
) {
|
2017-10-11 14:27:37 +02:00
|
|
|
parent::build($definition, $model, $mapper, $request);
|
2015-01-07 17:59:56 +01:00
|
|
|
|
2015-01-09 11:53:58 +01:00
|
|
|
if ($definition instanceof Path && $model->style) {
|
2016-10-05 09:45:31 +02:00
|
|
|
$styleModel = StyleModel::findActiveByPK($model->style);
|
2015-01-09 11:53:58 +01:00
|
|
|
|
|
|
|
|
if ($styleModel) {
|
|
|
|
|
$style = $mapper->handle($styleModel);
|
|
|
|
|
|
|
|
|
|
if ($style instanceof Style) {
|
|
|
|
|
$style->apply($definition);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-10-11 14:27:37 +02:00
|
|
|
$this->buildPopup($definition, $model, $mapper, $request);
|
2015-01-27 18:21:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Build the popup.
|
|
|
|
|
*
|
|
|
|
|
* @param Definition $definition The definition.
|
2017-10-11 14:27:37 +02:00
|
|
|
* @param Model $model The model.
|
2015-01-27 18:21:05 +01:00
|
|
|
* @param DefinitionMapper $mapper The definition mapper.
|
2017-10-11 14:27:37 +02:00
|
|
|
* @param Request $request Optional building request.
|
2015-01-27 18:21:05 +01:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2015-01-27 19:10:14 +01:00
|
|
|
protected function buildPopup(
|
|
|
|
|
Definition $definition,
|
2017-10-11 14:27:37 +02:00
|
|
|
Model $model,
|
2015-01-27 19:10:14 +01:00
|
|
|
DefinitionMapper $mapper,
|
2017-10-11 14:27:37 +02:00
|
|
|
Request $request = null
|
2015-01-27 19:10:14 +01:00
|
|
|
) {
|
2015-01-09 11:53:58 +01:00
|
|
|
if ($definition instanceof HasPopup && $model->addPopup) {
|
2015-01-27 18:17:05 +01:00
|
|
|
$popup = null;
|
2015-02-02 08:44:17 +01:00
|
|
|
$content = $this->valueFilter->filter($model->popupContent);
|
2015-01-22 12:24:22 +01:00
|
|
|
|
2015-01-27 18:17:05 +01:00
|
|
|
if ($model->popup) {
|
|
|
|
|
$popupModel = PopupModel::findActiveByPK($model->popup);
|
|
|
|
|
|
|
|
|
|
if ($popupModel) {
|
2017-10-11 14:27:37 +02:00
|
|
|
$popup = $mapper->handle($popupModel, $request, null, $definition);
|
2015-01-27 18:17:05 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($popup instanceof Popup) {
|
|
|
|
|
$definition->bindPopup($content, $popup->getOptions());
|
|
|
|
|
} else {
|
|
|
|
|
$definition->bindPopup($content);
|
|
|
|
|
}
|
2015-01-07 17:59:56 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|