Add reference layer.

This commit is contained in:
David Molineus
2015-01-09 15:24:34 +01:00
parent efb36256c7
commit 8e35dc1fef
15 changed files with 149 additions and 24 deletions

View File

@@ -57,6 +57,10 @@ class Layer
$icon = \Image::getHtml($src, $alt, sprintf('title="%s"', strip_tags($alt)));
if (!empty($this->layers[$row['type']]['label'])) {
$label = $this->layers[$row['type']]['label']($row, $label);
}
return $icon . ' ' . $label;
}
@@ -146,6 +150,15 @@ class Layer
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
}
public function getLayers($dataContainer)
{
$collection = LayerModel::findBy('id !', $dataContainer->id);
return OptionsBuilder::fromCollection($collection, 'id', 'title')
->asTree()
->getOptions();
}
/**
* @param $row
* @param $href

View File

@@ -52,7 +52,7 @@ class BuildDefinitionEvent extends Event
* @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in.
*/
public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null)
public function __construct(Definition $definition = null, \Model $model, LatLngBounds $bounds = null)
{
$this->definition = $definition;
$this->model = $model;

View File

@@ -0,0 +1,45 @@
<?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\Type\LatLngBounds;
/**
* Class ReferenceLayerMapper maps an reference layer to another
*
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/
class ReferenceLayerMapper extends AbstractLayerMapper
{
/**
* Layer type.
*
* @var string
*/
protected static $type = 'reference';
/**
* {@inheritdoc}
*/
public function handle($model, DefinitionMapper $mapper, LatLngBounds $bounds = null, $elementId = null)
{
$reference = LayerModel::findByPk($model->reference);
if (!$reference || !$reference->active) {
return null;
}
return $mapper->handle($reference, $bounds, $this->getElementId($model, $elementId));
}
}

View File

@@ -12,7 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Model;
trait ActiveTrait
abstract class AbstractActiveModel extends \Model
{
/**
*
@@ -28,14 +28,14 @@ trait ActiveTrait
/**
*
* @param int $modelId
* @param int $value
* @param array $options
*
* @return \Model|null
*/
public static function findActiveByPid($modelId, $options = array())
public static function findActiveBy($column, $value, $options = array())
{
return static::findBy('active=1 AND pid', $modelId, $options);
return static::findBy('active=1 AND ' . $column, $value, $options);
}
public static function findActivated($options = array())

View File

@@ -11,7 +11,7 @@
namespace Netzmacht\Contao\Leaflet\Model;
class ControlModel extends \Model
class ControlModel extends AbstractActiveModel
{
protected static $strTable = 'tl_leaflet_control';
}

View File

@@ -21,9 +21,7 @@ namespace Netzmacht\Contao\Leaflet\Model;
* @property mixed|null shadowRetinaImage
* @property mixed|null shadowImage
*/
class IconModel extends \Model
class IconModel extends AbstractActiveModel
{
use ActiveTrait;
protected static $strTable = 'tl_leaflet_icon';
}

View File

@@ -12,7 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Model;
class LayerModel extends \Model
class LayerModel extends AbstractActiveModel
{
protected static $strTable = 'tl_leaflet_layer';

View File

@@ -12,9 +12,7 @@
namespace Netzmacht\Contao\Leaflet\Model;
class StyleModel extends \Model
class StyleModel extends AbstractActiveModel
{
use ActiveTrait;
protected static $strTable = 'tl_leaflet_style';
}