forked from Snck3rs/contao-leaflet-maps
Fix code style.
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
|
||||
phpcs.standard=${basedir}/vendor/contao-community-alliance/coding-standard/phpcs/ContaoCommunityAlliance/ruleset.xml
|
||||
phpmd.ruleset=${basedir}/vendor/contao-community-alliance/coding-standard/phpmd/ruleset.xml
|
||||
|
||||
ccabs.bin.dir = ${basedir}/bin
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
"contao-community-alliance/url-builder":"~1.1",
|
||||
"netzmacht/contao-leaflet-libraries": "~0.7",
|
||||
"netzmacht/php-javascript-builder": "~1.0",
|
||||
"netzmacht/php-leaflet": "dev-master",
|
||||
"netzmacht/php-leaflet": "~0.7",
|
||||
"netzmacht/contao-dev-tools":"~1.0",
|
||||
"bit3/contao-meta-palettes": "~1.5",
|
||||
"menatwork/contao-multicolumnwizard": "~3.2",
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
TemplateLoader::addFiles(
|
||||
array(
|
||||
'ce_leaflet_map' => 'system/modules/leaflet/templates',
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Backend module.
|
||||
*/
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
return array(
|
||||
'Netzmacht\Contao\Leaflet\Subscriber\BootSubscriber',
|
||||
'Netzmacht\Contao\Leaflet\Subscriber\HashSubscriber',
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Support all providers and variants which are supported by leaflet-providers.
|
||||
* See https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Boot;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\MapService;
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_content']['metapalettes']['leaflet'] = array(
|
||||
'type' => array('type', 'headline'),
|
||||
'leaflet' => array('leaflet_map', 'leaflet_width', 'leaflet_height'),
|
||||
@@ -13,9 +22,9 @@ $GLOBALS['TL_DCA']['tl_content']['fields']['leaflet_map'] = array(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_map'],
|
||||
'inputType' => 'select',
|
||||
'exclude' => true,
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Content', 'getMaps'),
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getMaps'),
|
||||
'wizard' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\Content', 'getEditMapLink'),
|
||||
array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getEditMapLink'),
|
||||
),
|
||||
'eval' => array(
|
||||
'tl_class' => 'w50 wizard',
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
\Controller::loadLanguageFile('leaflet');
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_control'] = array
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_control_layer'] = array
|
||||
(
|
||||
'config' => array(
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
|
||||
(
|
||||
'config' => array(
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
\Controller::loadLanguageFile('leaflet');
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_layer'] = array
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_map'] = array
|
||||
(
|
||||
'config' => array(
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_map_layer'] = array
|
||||
(
|
||||
'config' => array(
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
\Controller::loadLanguageFile('leaflet');
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,13 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_style'] = array
|
||||
(
|
||||
'config' => array(
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
\Controller::loadLanguageFile('leaflet');
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_leaflet_vector'] = array
|
||||
|
||||
@@ -1,5 +1,14 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
$GLOBALS['TL_DCA']['tl_module']['metapalettes']['leaflet'] = array(
|
||||
'type' => array('name', 'type', 'headline'),
|
||||
'leaflet' => array('leaflet_map', 'leaflet_width', 'leaflet_height'),
|
||||
@@ -13,9 +22,9 @@ $GLOBALS['TL_DCA']['tl_module']['fields']['leaflet_map'] = array(
|
||||
'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_map'],
|
||||
'inputType' => 'select',
|
||||
'exclude' => true,
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Module', 'getMaps'),
|
||||
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getMaps'),
|
||||
'wizard' => array(
|
||||
array('Netzmacht\Contao\Leaflet\Dca\Module', 'getEditMapLink'),
|
||||
array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getEditMapLink'),
|
||||
),
|
||||
'eval' => array(
|
||||
'tl_class' => 'w50 wizard',
|
||||
|
||||
@@ -11,21 +11,37 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Backend;
|
||||
|
||||
|
||||
/**
|
||||
* Credits backend module.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Backend
|
||||
*/
|
||||
class Credits
|
||||
{
|
||||
/**
|
||||
* Generate the backend view.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
$template = new \BackendTemplate('be_leaflet_credits');
|
||||
|
||||
$template->headline = 'Leaftlet maps integration for Contao CMS';
|
||||
$template->libraries = $this->getLibraries();
|
||||
$template->headline = 'Leaftlet maps integration for Contao CMS';
|
||||
$template->libraries = $this->getLibraries();
|
||||
|
||||
list($template->version, $template->dependencies) = $this->extractFromComposer();
|
||||
|
||||
return $template->parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get list of all libraries.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
private function getLibraries()
|
||||
{
|
||||
return array_map(
|
||||
@@ -58,6 +74,11 @@ class Credits
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract version and dependencies from composer.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private function extractFromComposer()
|
||||
{
|
||||
$local = TL_ROOT . '/composer/vendor/netzmacht/contao-leaflet-maps/composer.json';
|
||||
|
||||
@@ -14,18 +14,23 @@ namespace Netzmacht\Contao\Leaflet;
|
||||
use Netzmacht\LeafletPHP\Assets;
|
||||
|
||||
/**
|
||||
* Class ContaoAssets
|
||||
* Class ContaoAssets handles leaflet assets and integrate them into the Contao assets registry (Superglobals).
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet
|
||||
*/
|
||||
class ContaoAssets implements Assets
|
||||
{
|
||||
/**
|
||||
* @var
|
||||
* The map javascript.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private $map;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function addJavascript($script, $type = self::TYPE_SOURCE)
|
||||
{
|
||||
@@ -48,6 +53,8 @@ class ContaoAssets implements Assets
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function addStylesheet($stylesheet, $type = self::TYPE_FILE)
|
||||
{
|
||||
|
||||
@@ -11,26 +11,42 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
/**
|
||||
* Class Control is the helper for the tl_leaflet_control dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Control
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Database
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->database = static::getService('database.connection');
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a row.
|
||||
*
|
||||
* @param array $row The data row.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateRow($row)
|
||||
{
|
||||
return sprintf(
|
||||
@@ -40,6 +56,11 @@ class Control
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get layers for the layers control.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayers()
|
||||
{
|
||||
$options = array();
|
||||
@@ -54,6 +75,11 @@ class Control
|
||||
return $options;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the zoom controls for the reference value of the loading control.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZoomControls()
|
||||
{
|
||||
$collection = ControlModel::findBy('type', 'zoom', array('order' => 'title'));
|
||||
@@ -61,6 +87,16 @@ class Control
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Load layer relations.
|
||||
*
|
||||
* @param mixed $value The actual value.
|
||||
* @param \DataContainer $dataContainer The data container driver.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function loadLayerRelations($value, $dataContainer)
|
||||
{
|
||||
$result = $this->database
|
||||
@@ -70,6 +106,14 @@ class Control
|
||||
return $result->fetchAllAssoc();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save layer relations.
|
||||
*
|
||||
* @param $layers $layers The layer id values.
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function saveLayerRelations($layers, $dataContainer)
|
||||
{
|
||||
$new = deserialize($layers, true);
|
||||
|
||||
@@ -15,10 +15,11 @@ use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
/**
|
||||
* Class Content
|
||||
* Class Module is the helper for the tl_module dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Content
|
||||
class FrontendIntegration
|
||||
{
|
||||
/**
|
||||
* Get all leaflet maps.
|
||||
@@ -32,20 +33,31 @@ class Content
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get edit map link wizard.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function getEditMapLink($dataContainer)
|
||||
{
|
||||
if ($dataContainer->value < 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$pattern = 'title="%s" style="padding-left: 3px" onclick="Backend.openModalIframe(';
|
||||
$pattern .= '{\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"';
|
||||
|
||||
return sprintf(
|
||||
'<a href="%s%s&popup=1&rt=%s" %s>%s</a>',
|
||||
'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=',
|
||||
$dataContainer->value,
|
||||
\RequestToken::get(),
|
||||
sprintf(
|
||||
'title="%s" style="padding-left: 3px" '
|
||||
. 'onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"',
|
||||
$pattern,
|
||||
specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)),
|
||||
specialchars(
|
||||
str_replace(
|
||||
@@ -57,7 +69,8 @@ class Content
|
||||
),
|
||||
\Image::getHtml(
|
||||
'alias.gif',
|
||||
$GLOBALS['TL_LANG']['tl_content']['editalias'][0], 'style="vertical-align:top"'
|
||||
$GLOBALS['TL_LANG']['tl_content']['editalias'][0],
|
||||
'style="vertical-align:top"'
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -11,22 +11,38 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
|
||||
/**
|
||||
* Class Layer is the helper class for the tl_leaflet_layer dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Layer
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
|
||||
/**
|
||||
* Layers definition.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $layers;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Database
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->layers = &$GLOBALS['LEAFLET_LAYERS'];
|
||||
@@ -36,6 +52,15 @@ class Layer
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Get variants of the tile provider.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function getVariants($dataContainer)
|
||||
{
|
||||
if ($dataContainer->activeRecord
|
||||
@@ -48,6 +73,16 @@ class Layer
|
||||
return array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a row.
|
||||
*
|
||||
* @param array $row The data row.
|
||||
* @param string $label Current row label.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function generateRow($row, $label)
|
||||
{
|
||||
$alt = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0])
|
||||
@@ -74,11 +109,16 @@ class Layer
|
||||
return $icon . ' ' . $label;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all marker cluster layers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMarkerClusterLayers()
|
||||
{
|
||||
$types = array_keys(
|
||||
array_filter(
|
||||
$GLOBALS['LEAFLET_LAYERS'],
|
||||
$this->layers,
|
||||
function ($item) {
|
||||
return !empty($item['markerCluster']);
|
||||
}
|
||||
@@ -89,7 +129,7 @@ class Layer
|
||||
$builder = OptionsBuilder::fromCollection(
|
||||
$collection,
|
||||
'id',
|
||||
function($row) {
|
||||
function ($row) {
|
||||
return sprintf('%s [%s]', $row['title'], $row['type']);
|
||||
}
|
||||
);
|
||||
@@ -97,7 +137,20 @@ class Layer
|
||||
return $builder->getOptions();
|
||||
}
|
||||
|
||||
// Call paste_button_callback (&$dc, $row, $table, $cr, $childs, $previous, $next)
|
||||
/**
|
||||
* Get the paste buttons depending on the layer type.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
* @param array $row The data row.
|
||||
* @param string $table The table name.
|
||||
* @param null $whatever Who knows what the purpose of this var is.
|
||||
* @param array $children The child content.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function getPasteButtons($dataContainer, $row, $table, $whatever, $children)
|
||||
{
|
||||
$pasteAfterUrl = \Controller::addToUrl(
|
||||
@@ -142,6 +195,18 @@ class Layer
|
||||
return $buffer;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the markers button.
|
||||
*
|
||||
* @param array $row Current row.
|
||||
* @param string $href The button href.
|
||||
* @param string $label The button label.
|
||||
* @param string $title The button title.
|
||||
* @param string $icon The button icon.
|
||||
* @param string $attributes Optional attributes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateMarkersButton($row, $href, $label, $title, $icon, $attributes)
|
||||
{
|
||||
if (empty($this->layers[$row['type']]['markers'])) {
|
||||
@@ -151,6 +216,18 @@ class Layer
|
||||
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the vectors button.
|
||||
*
|
||||
* @param array $row Current row.
|
||||
* @param string $href The button href.
|
||||
* @param string $label The button label.
|
||||
* @param string $title The button title.
|
||||
* @param string $icon The button icon.
|
||||
* @param string $attributes Optional attributes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateVectorsButton($row, $href, $label, $title, $icon, $attributes)
|
||||
{
|
||||
if (empty($this->layers[$row['type']]['vectors'])) {
|
||||
@@ -160,6 +237,13 @@ class Layer
|
||||
return $this->generateButton($row, $href, $label, $title, $icon, $attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all layers except of the current layer.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayers($dataContainer)
|
||||
{
|
||||
$collection = LayerModel::findBy('id !', $dataContainer->id);
|
||||
@@ -169,7 +253,14 @@ class Layer
|
||||
->getOptions();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Delete the relations when the layer is deleted.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
* @param int $undoId The id of the undo entry.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function deleteRelations($dataContainer, $undoId)
|
||||
{
|
||||
if ($undoId) {
|
||||
@@ -212,12 +303,14 @@ class Layer
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $row
|
||||
* @param $href
|
||||
* @param $label
|
||||
* @param $title
|
||||
* @param $icon
|
||||
* @param $attributes
|
||||
* Generate a button.
|
||||
*
|
||||
* @param array $row Current row.
|
||||
* @param string $href The button href.
|
||||
* @param string $label The button label.
|
||||
* @param string $title The button title.
|
||||
* @param string $icon The button icon.
|
||||
* @param string $attributes Optional attributes.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
|
||||
@@ -11,19 +11,23 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\MapMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
|
||||
/**
|
||||
* Class Leaflet is the base helper providing different methods.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Leaflet
|
||||
{
|
||||
/**
|
||||
* Validate a coordinate.
|
||||
*
|
||||
* @param $value
|
||||
* @param mixed $value The given value.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
@@ -38,29 +42,44 @@ class Leaflet
|
||||
return $value;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create the zoom range.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getZoomLevels()
|
||||
{
|
||||
return range(1, 20);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the geocoder wizard.
|
||||
*
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getGeocoder($dataContainer)
|
||||
{
|
||||
$template = new \BackendTemplate('be_leaflet_geocode');
|
||||
$template = new \BackendTemplate('be_leaflet_geocode');
|
||||
$template->field = 'ctrl_' . $dataContainer->field;
|
||||
|
||||
try {
|
||||
$latLng = LatLng::fromString($dataContainer->value);
|
||||
$template->marker = json_encode($latLng);
|
||||
} catch(\Exception $e) {
|
||||
|
||||
} catch (\Exception $e) {
|
||||
// LatLng throws an exeption of value could not be created. Just let the value empty when.
|
||||
}
|
||||
|
||||
|
||||
return $template->parse();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all layers.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getLayers()
|
||||
{
|
||||
$options = array();
|
||||
|
||||
@@ -11,23 +11,42 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
|
||||
|
||||
/**
|
||||
* Class Map is the helper class for the tl_leaflet_map dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Map
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
|
||||
/**
|
||||
* The database connection.
|
||||
*
|
||||
* @var \Database
|
||||
*/
|
||||
private $database;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->database = static::getService('database.connection');
|
||||
}
|
||||
|
||||
/**
|
||||
* Load layer relations.
|
||||
*
|
||||
* @param mixed $value The actual value.
|
||||
* @param \DataContainer $dataContainer The data container driver.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
public function loadLayerRelations($value, $dataContainer)
|
||||
{
|
||||
$result = $this->database
|
||||
@@ -37,6 +56,14 @@ class Map
|
||||
return $result->fetchEach('lid');
|
||||
}
|
||||
|
||||
/**
|
||||
* Save layer relations.
|
||||
*
|
||||
* @param mixed $layerId The layer id values.
|
||||
* @param \DataContainer $dataContainer The dataContainer driver.
|
||||
*
|
||||
* @return null
|
||||
*/
|
||||
public function saveLayerRelations($layerId, $dataContainer)
|
||||
{
|
||||
$new = deserialize($layerId, true);
|
||||
@@ -67,7 +94,8 @@ class Map
|
||||
|
||||
$sorting += 128;
|
||||
} else {
|
||||
if ($values[$layerId]['sorting'] <= ($sorting - 128) || $values[$layerId]['sorting'] >= ($sorting + 128)) {
|
||||
if ($values[$layerId]['sorting'] <= ($sorting - 128)
|
||||
|| $values[$layerId]['sorting'] >= ($sorting + 128)) {
|
||||
$this->database
|
||||
->prepare('UPDATE tl_leaflet_map_layer %s WHERE id=?')
|
||||
->set(array('tstamp' => time(), 'sorting' => $sorting))
|
||||
|
||||
@@ -11,28 +11,44 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
|
||||
/**
|
||||
* Class Marker is the dca helper class for the tl_leaflet_marker dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Marker
|
||||
{
|
||||
/**
|
||||
* Generate the row label.
|
||||
*
|
||||
* @param array $row Current data row.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateRow($row)
|
||||
{
|
||||
return $row['title'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all icons.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getIcons()
|
||||
{
|
||||
$collection = IconModel::findAll(array('order' => 'title'));
|
||||
$builder = OptionsBuilder::fromCollection(
|
||||
$collection, 'id',
|
||||
function($model) {
|
||||
$collection,
|
||||
'id',
|
||||
function ($model) {
|
||||
return sprintf('%s [%s]', $model['title'], $model['type']);
|
||||
}
|
||||
);
|
||||
|
||||
return $builder->getOptions();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @package dev
|
||||
* @author David Molineus <david.molineus@netzmacht.de>
|
||||
* @copyright 2014 netzmacht creative David Molineus
|
||||
* @license LGPL 3.0
|
||||
* @filesource
|
||||
*
|
||||
*/
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
/**
|
||||
* Class Module
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Module
|
||||
{
|
||||
/**
|
||||
* Get all leaflet maps.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getMaps()
|
||||
{
|
||||
$collection = MapModel::findAll();
|
||||
|
||||
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions();
|
||||
}
|
||||
|
||||
public function getEditMapLink($dataContainer)
|
||||
{
|
||||
if ($dataContainer->value < 1) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
'<a href="%s%s&popup=1&rt=%s" %s>%s</a>',
|
||||
'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=',
|
||||
$dataContainer->value,
|
||||
\RequestToken::get(),
|
||||
sprintf(
|
||||
'title="%s" style="padding-left: 3px" '
|
||||
. 'onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"',
|
||||
specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)),
|
||||
specialchars(
|
||||
str_replace(
|
||||
"'",
|
||||
"\\'",
|
||||
sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)
|
||||
)
|
||||
)
|
||||
),
|
||||
\Image::getHtml(
|
||||
'alias.gif',
|
||||
$GLOBALS['TL_LANG']['tl_content']['editalias'][0], 'style="vertical-align:top"'
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -11,12 +11,23 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Dca;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
|
||||
use Netzmacht\Contao\Leaflet\Model\StyleModel;
|
||||
|
||||
/**
|
||||
* Helper class for the tl_leaflet_vector dca.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Dca
|
||||
*/
|
||||
class Vector
|
||||
{
|
||||
/**
|
||||
* Generate the row label.
|
||||
*
|
||||
* @param array $row Current data row.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generateRow($row)
|
||||
{
|
||||
return sprintf('%s <span class="tl_gray">[%s]</span>', $row['title'], $row['type']);
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Definition\Style;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Definition\Style;
|
||||
use Netzmacht\LeafletPHP\Definition\AbstractDefinition;
|
||||
use Netzmacht\LeafletPHP\Definition\OptionsTrait;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Path;
|
||||
|
||||
/**
|
||||
* Class FixedStyle is a style which simple has fixed definitions.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Definition\Style
|
||||
*/
|
||||
class FixedStyle extends AbstractDefinition implements Style
|
||||
{
|
||||
use OptionsTrait;
|
||||
|
||||
@@ -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 = null, \Model $model, LatLngBounds $bounds = null)
|
||||
public function __construct(Definition $definition, \Model $model, LatLngBounds $bounds = null)
|
||||
{
|
||||
$this->definition = $definition;
|
||||
$this->model = $model;
|
||||
|
||||
@@ -15,7 +15,7 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
|
||||
/**
|
||||
* Class InitializeDefinitionMapperEvent
|
||||
* Class InitializeDefinitionMapperEvent is emitted when the definition mapper is created.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Event
|
||||
*/
|
||||
@@ -24,6 +24,8 @@ class InitializeDefinitionMapperEvent extends Event
|
||||
const NAME = 'leaflet.boot.initialize-definition-mapper';
|
||||
|
||||
/**
|
||||
* The definitino mapper.
|
||||
*
|
||||
* @var DefinitionMapper
|
||||
*/
|
||||
private $definitionMapper;
|
||||
|
||||
@@ -11,32 +11,53 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Frontend;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\MapService;
|
||||
|
||||
/**
|
||||
* The data controller handles ajax request for sub data.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Frontend
|
||||
*/
|
||||
class DataController
|
||||
{
|
||||
/**
|
||||
* The map service.
|
||||
*
|
||||
* @var MapService
|
||||
*/
|
||||
private $mapService;
|
||||
|
||||
/**
|
||||
* The user input object.
|
||||
*
|
||||
* @var \Input
|
||||
*/
|
||||
private $input;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param MapService $mapService The map service.
|
||||
* @param \Input $input The user input object.
|
||||
*/
|
||||
public function __construct(MapService $mapService, \Input $input)
|
||||
{
|
||||
$this->mapService = $mapService;
|
||||
$this->input = $input;
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the controller and create the data response.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception If anything went wrong.
|
||||
*/
|
||||
public function execute()
|
||||
{
|
||||
$format = $this->input->get('format') ?: 'geojson';
|
||||
$type = $this->input->get('type') ?: 'layer';
|
||||
$dataId = $this->input->get('id');
|
||||
$format = $this->getInput('format', 'geojson');
|
||||
$type = $this->getInput('type', 'layer');
|
||||
$dataId = $this->getInput('id');
|
||||
|
||||
try {
|
||||
list($data, $error) = $this->loadData($type, $dataId);
|
||||
@@ -55,8 +76,12 @@ class DataController
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $format
|
||||
* @param $data
|
||||
* Enocode the data.
|
||||
*
|
||||
* @param string $format The requested format.
|
||||
* @param mixed $data The given data.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function encodeData($format, $data)
|
||||
{
|
||||
@@ -65,12 +90,17 @@ class DataController
|
||||
header('Content-Type: application/json');
|
||||
echo json_encode($data, JSON_UNESCAPED_SLASHES);
|
||||
break;
|
||||
|
||||
default:
|
||||
// Blame the code sniffer.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $type
|
||||
* @param $dataId
|
||||
* Load the data.
|
||||
*
|
||||
* @param string $type The data type.
|
||||
* @param mixed $dataId The data id.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
@@ -92,4 +122,17 @@ class DataController
|
||||
|
||||
return array($data, $error);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an input value.
|
||||
*
|
||||
* @param string $name The input name.
|
||||
* @param mixed $default Optional a default value if empty.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
protected function getInput($name, $default = null)
|
||||
{
|
||||
return $this->input->get($name) ?: $default;
|
||||
}
|
||||
}
|
||||
|
||||
110
src/Netzmacht/Contao/Leaflet/Frontend/HybridTrait.php
Normal file
110
src/Netzmacht/Contao/Leaflet/Frontend/HybridTrait.php
Normal file
@@ -0,0 +1,110 @@
|
||||
<?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\Frontend;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\MapService;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
/**
|
||||
* Class HybridTrait provides method required by the frontend module and content element the same time.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Frontend
|
||||
*/
|
||||
trait HybridTrait
|
||||
{
|
||||
/**
|
||||
* The map service.
|
||||
*
|
||||
* @var MapService
|
||||
*/
|
||||
private $mapService;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param \ContentModel $objElement Content element model.
|
||||
* @param string $strColumn Layout column.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function construct($objElement, $strColumn = 'main')
|
||||
{
|
||||
parent::__construct($objElement, $strColumn);
|
||||
|
||||
$this->mapService = static::getService('leaflet.map.service');
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the frontend integration generation.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function generate()
|
||||
{
|
||||
if (TL_MODE === 'BE') {
|
||||
$model = MapModel::findByPK($this->leaflet_map);
|
||||
|
||||
$template = new \BackendTemplate('be_wildcard');
|
||||
|
||||
if ($model) {
|
||||
$href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id;
|
||||
|
||||
$template->wildcard = '### LEAFLET MAP ' . $model->title . ' ###';
|
||||
$template->title = $this->headline;
|
||||
$template->id = $model->id;
|
||||
$template->link = $model->title;
|
||||
$template->href = $href;
|
||||
}
|
||||
|
||||
return $template->parse();
|
||||
}
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do the frontend integration compiling.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception If something went wrong.
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
protected function compile()
|
||||
{
|
||||
try {
|
||||
$mapId = 'map_' . ($this->cssID[0] ?: ('ce_' . $this->id));
|
||||
$map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId);
|
||||
|
||||
$GLOBALS['TL_BODY'][] = '<script>' . $map .'</script>';
|
||||
|
||||
$this->Template->mapId = $mapId;
|
||||
|
||||
$style = '';
|
||||
$height = deserialize($this->leaflet_height, true);
|
||||
$width = deserialize($this->leaflet_width, true);
|
||||
|
||||
if (!empty($width['value'])) {
|
||||
$style .= 'width:' . $width['value'] . $width['unit'] . ';';
|
||||
}
|
||||
|
||||
if (!empty($height['value'])) {
|
||||
$style .= 'height:' . $height['value'] . $height['unit'] . ';';
|
||||
}
|
||||
|
||||
$this->Template->mapStyle = $style;
|
||||
} catch (\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,14 +12,19 @@
|
||||
namespace Netzmacht\Contao\Leaflet\Frontend;
|
||||
|
||||
use ContentElement;
|
||||
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\MapService;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
/**
|
||||
* The content element for the leaflet map.
|
||||
*
|
||||
* @property int leaflet_map
|
||||
*/
|
||||
class MapElement extends \ContentElement
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
use HybridTrait;
|
||||
|
||||
/**
|
||||
* Template name.
|
||||
*
|
||||
@@ -28,78 +33,10 @@ class MapElement extends \ContentElement
|
||||
protected $strTemplate = 'ce_leaflet_map';
|
||||
|
||||
/**
|
||||
* @var MapService
|
||||
*/
|
||||
private $mapService;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param \ContentModel $objElement Content element model.
|
||||
* @param string $strColumn Layout column.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($objElement, $strColumn = 'main')
|
||||
{
|
||||
parent::__construct($objElement, $strColumn);
|
||||
|
||||
$this->mapService = $GLOBALS['container']['leaflet.map.service'];
|
||||
}
|
||||
|
||||
public function generate()
|
||||
{
|
||||
if (TL_MODE === 'BE') {
|
||||
$model = MapModel::findByPK($this->leaflet_map);
|
||||
|
||||
$template = new \BackendTemplate('be_wildcard');
|
||||
|
||||
if ($model) {
|
||||
$href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id;
|
||||
|
||||
$template->wildcard = '### LEAFLET MAP ' . $model->title . ' ###';
|
||||
$template->title = $this->headline;
|
||||
$template->id = $model->id;
|
||||
$template->link = $model->title;
|
||||
$template->href = $href;
|
||||
}
|
||||
|
||||
return $template->parse();
|
||||
}
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the content element.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function compile()
|
||||
{
|
||||
try {
|
||||
$mapId = 'map_' . ($this->cssID[0] ?: ('ce_' . $this->id));
|
||||
$map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId);
|
||||
|
||||
$GLOBALS['TL_BODY'][] = '<script>' . $map .'</script>';
|
||||
|
||||
$this->Template->mapId = $mapId;
|
||||
|
||||
$style = '';
|
||||
$height = deserialize($this->leaflet_height, true);
|
||||
$width = deserialize($this->leaflet_width, true);
|
||||
|
||||
if (!empty($width['value'])) {
|
||||
$style .= 'width:' . $width['value'] . $width['unit'] . ';';
|
||||
}
|
||||
|
||||
if (!empty($height['value'])) {
|
||||
$style .= 'height:' . $height['value'] . $height['unit'] . ';';
|
||||
}
|
||||
|
||||
$this->Template->mapStyle = $style;
|
||||
} catch(\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
$this->construct($objElement, $strColumn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,12 +11,19 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Frontend;
|
||||
|
||||
|
||||
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
|
||||
use Netzmacht\Contao\Leaflet\MapService;
|
||||
use Netzmacht\Contao\Leaflet\Model\MapModel;
|
||||
|
||||
/**
|
||||
* The frontend module for the Leaflet map.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Frontend
|
||||
*/
|
||||
class MapModule extends \Module
|
||||
{
|
||||
use ServiceContainerTrait;
|
||||
use HybridTrait;
|
||||
|
||||
/**
|
||||
* Template name.
|
||||
*
|
||||
@@ -25,77 +32,10 @@ class MapModule extends \Module
|
||||
protected $strTemplate = 'mod_leaflet_map';
|
||||
|
||||
/**
|
||||
* @var MapService
|
||||
*/
|
||||
private $mapService;
|
||||
|
||||
/**
|
||||
* Construct.
|
||||
*
|
||||
* @param \ModuleModel $objElement Module model.
|
||||
* @param string $strColumn Layout column.
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function __construct($objElement, $strColumn = 'main')
|
||||
{
|
||||
parent::__construct($objElement, $strColumn);
|
||||
|
||||
$this->mapService = $GLOBALS['container']['leaflet.map.service'];
|
||||
}
|
||||
|
||||
public function generate()
|
||||
{
|
||||
if (TL_MODE === 'BE') {
|
||||
$model = MapModel::findByPK($this->leaflet_map);
|
||||
$template = new \BackendTemplate('be_wildcard');
|
||||
|
||||
if ($model) {
|
||||
$href = 'contao/main.php?do=leaflet&table=tl_leaflet_map&act=edit&id=' . $model->id;
|
||||
|
||||
$template->wildcard = '### LEAFLET MAP ' . $model->title . ' ###';
|
||||
$template->title = $this->headline;
|
||||
$template->id = $model->id;
|
||||
$template->link = $model->title;
|
||||
$template->href = $href;
|
||||
}
|
||||
|
||||
return $template->parse();
|
||||
}
|
||||
|
||||
return parent::generate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Compile the content element.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function compile()
|
||||
{
|
||||
try {
|
||||
$mapId = 'map_' . ($this->cssID[0] ?: ('mod_' . $this->id));
|
||||
$map = $this->mapService->getJavascript($this->leaflet_map, null, $mapId);
|
||||
|
||||
$GLOBALS['TL_BODY'][] = '<script>' . $map .'</script>';
|
||||
|
||||
$this->Template->mapId = $mapId;
|
||||
|
||||
$style = '';
|
||||
$height = deserialize($this->leaflet_height, true);
|
||||
$width = deserialize($this->leaflet_width, true);
|
||||
|
||||
if (!empty($width['value'])) {
|
||||
$style .= 'width:' . $width['value'] . $width['unit'] . ';';
|
||||
}
|
||||
|
||||
if (!empty($height['value'])) {
|
||||
$style .= 'height:' . $height['value'] . $height['unit'] . ';';
|
||||
}
|
||||
|
||||
$this->Template->mapStyle = $style;
|
||||
} catch(\Exception $e) {
|
||||
throw $e;
|
||||
}
|
||||
$this->construct($objElement, $strColumn);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,27 +25,27 @@ class RequestUrl
|
||||
/**
|
||||
* Create the request url.
|
||||
*
|
||||
* @param int $id Object id.
|
||||
* @param int $dataId The data object id.
|
||||
* @param string|null $type Object type. If empty it assumes a layer.
|
||||
* @param string|null $format Data format. If empty it assumes geojson.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public static function create($id, $type = null, $format = null)
|
||||
public static function create($dataId, $type = null, $format = null)
|
||||
{
|
||||
return self::createBuilder($id, $type, $format)->getUrl();
|
||||
return self::createBuilder($dataId, $type, $format)->getUrl();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the request builder.
|
||||
*
|
||||
* @param int $id Object id.
|
||||
* @param int $dataId The data object id.
|
||||
* @param string|null $type Object type. If empty it assumes a layer.
|
||||
* @param string|null $format Data format. If empty it assumes geojson.
|
||||
*
|
||||
* @return UrlBuilder
|
||||
*/
|
||||
public static function createBuilder($id, $type = null, $format = null)
|
||||
public static function createBuilder($dataId, $type = null, $format = null)
|
||||
{
|
||||
$path = \Config::get('websitePath') . '/' . static::BASE;
|
||||
$builder = new UrlBuilder();
|
||||
@@ -53,7 +53,7 @@ class RequestUrl
|
||||
->setPath($path)
|
||||
->setQueryParameter('type', $type ?: 'layer')
|
||||
->setQueryParameter('format', $format ?: 'geojson')
|
||||
->setQueryParameter('id', $id);
|
||||
->setQueryParameter('id', $dataId);
|
||||
|
||||
return $builder;
|
||||
}
|
||||
|
||||
@@ -44,6 +44,8 @@ class MapService
|
||||
private $leaflet;
|
||||
|
||||
/**
|
||||
* The event dispatcher.
|
||||
*
|
||||
* @var EventDispatcher
|
||||
*/
|
||||
private $eventDispatcher;
|
||||
@@ -130,6 +132,8 @@ class MapService
|
||||
* @param LatLngBounds $bounds Filter features in the bounds.
|
||||
*
|
||||
* @return FeatureCollection
|
||||
*
|
||||
* @throws \InvalidArgumentException If a layer could not be found.
|
||||
*/
|
||||
public function getFeatureCollection($layerId, LatLngBounds $bounds = null)
|
||||
{
|
||||
|
||||
@@ -24,7 +24,7 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
abstract class AbstractMapper implements Mapper
|
||||
{
|
||||
const VALUE_NOT_EMPTY = '__value_not_empty__';
|
||||
const VALUE_EMPTY = '__value_empty__';
|
||||
const VALUE_EMPTY = '__value_empty__';
|
||||
|
||||
/**
|
||||
* Class of the model being build.
|
||||
@@ -190,6 +190,8 @@ abstract class AbstractMapper implements Mapper
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
@@ -224,12 +226,14 @@ abstract class AbstractMapper implements Mapper
|
||||
/**
|
||||
* Get construct arguments.
|
||||
*
|
||||
* @param \Model $model The model.
|
||||
* @param DefinitionMapper $mapper The definition mapper.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param \Model $model The model.
|
||||
* @param DefinitionMapper $mapper The definition mapper.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param string|null $elementId Optional element id.
|
||||
*
|
||||
* @return array
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
@@ -301,6 +305,8 @@ abstract class AbstractMapper implements Mapper
|
||||
* @param array $options The options.
|
||||
* @param Definition $definition The definition being built.
|
||||
* @param \Model $model The model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function applyOptions($options, $definition, $model)
|
||||
{
|
||||
@@ -312,8 +318,7 @@ abstract class AbstractMapper implements Mapper
|
||||
if (((bool) $model->$option) !== $default) {
|
||||
$definition->$setter($model->$mapping);
|
||||
}
|
||||
}
|
||||
elseif ($model->$mapping !== $default) {
|
||||
} elseif ($model->$mapping !== $default) {
|
||||
$definition->$setter($model->$mapping);
|
||||
}
|
||||
}
|
||||
@@ -351,6 +356,8 @@ abstract class AbstractMapper implements Mapper
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
|
||||
*/
|
||||
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
|
||||
@@ -13,11 +13,23 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
|
||||
/**
|
||||
* Class AbstractTypeMapper is the base mapper for tables containing different types of definitins.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper
|
||||
*/
|
||||
abstract class AbstractTypeMapper extends AbstractMapper
|
||||
{
|
||||
/**
|
||||
* The definition type.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $type;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function match($model, LatLngBounds $bounds = null)
|
||||
{
|
||||
return parent::match($model) && $model->type === static::$type;
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
|
||||
/**
|
||||
* Class AbstractControlMapper is the base mapper for the control model.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Control
|
||||
*/
|
||||
class AbstractControlMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class LayersControlMapper maps the control model to the layers control definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Control
|
||||
*/
|
||||
class LayersControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Control;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\ControlModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
@@ -20,6 +19,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Plugins\Loading\LoadingControl;
|
||||
use Netzmacht\LeafletPHP\Plugins\Loading\SpinJsLoadingControl;
|
||||
|
||||
/**
|
||||
* Class LoadingControlMapper maps the control model to the loading control definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Control
|
||||
*/
|
||||
class LoadingControlMapper extends AbstractControlMapper
|
||||
{
|
||||
/**
|
||||
@@ -77,7 +81,7 @@ class LoadingControlMapper extends AbstractControlMapper
|
||||
}
|
||||
}
|
||||
|
||||
if ($definition instanceof LoadingControl && !$definition->isSeparate() && $model->zoomControl ) {
|
||||
if ($definition instanceof LoadingControl && !$definition->isSeparate() && $model->zoomControl) {
|
||||
// Only assign if zoom control is activated and part of the map.
|
||||
$control = ControlModel::findOneBy(
|
||||
array('active=1', 'type=?', 'pid=?', 'id=?'),
|
||||
|
||||
@@ -27,9 +27,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatche
|
||||
class DefinitionMapper
|
||||
{
|
||||
/**
|
||||
* Registered builders.
|
||||
* Lit of all registered mappers.
|
||||
*
|
||||
* @var AbstractMapper[][]
|
||||
* @var Mapper[][]
|
||||
*/
|
||||
private $builders = array();
|
||||
|
||||
@@ -41,6 +41,8 @@ class DefinitionMapper
|
||||
private $eventDispatcher;
|
||||
|
||||
/**
|
||||
* Cache of mapped definitions.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
private $mapped = array();
|
||||
@@ -79,7 +81,9 @@ class DefinitionMapper
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param string $elementId Optional element id. If none given the mapId or alias is used.
|
||||
*
|
||||
* @return Definition
|
||||
* @return Definition|null
|
||||
*
|
||||
* @throws \RuntimeException If model could not be mapped to a definition.
|
||||
*/
|
||||
public function handle($model, LatLngBounds $bounds = null, $elementId = null)
|
||||
{
|
||||
@@ -90,7 +94,7 @@ class DefinitionMapper
|
||||
}
|
||||
|
||||
foreach ($this->builders as $builders) {
|
||||
foreach($builders as $builder) {
|
||||
foreach ($builders as $builder) {
|
||||
if ($builder->match($model)) {
|
||||
$definition = $builder->handle($model, $this, $bounds, $elementId);
|
||||
|
||||
@@ -118,10 +122,12 @@ class DefinitionMapper
|
||||
/**
|
||||
* Build a model.
|
||||
*
|
||||
* @param mixed $model The definition model.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param mixed $model The definition model.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
*
|
||||
* @return FeatureCollection|Feature
|
||||
* @return FeatureCollection|Feature|null
|
||||
*
|
||||
* @throws \RuntimeException If a model could not be mapped to the GeoJSON representation.
|
||||
*/
|
||||
public function handleGeoJson($model, LatLngBounds $bounds = null)
|
||||
{
|
||||
@@ -155,9 +161,14 @@ class DefinitionMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $model
|
||||
* Get the hash of a model.
|
||||
*
|
||||
* @param mixed $model The definition model.
|
||||
* @param string|null $elementId Optional defined extra element id.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @throws \RuntimeException If no hash was created.
|
||||
*/
|
||||
protected function getHash($model, $elementId)
|
||||
{
|
||||
|
||||
@@ -11,16 +11,24 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
|
||||
use Netzmacht\LeafletPHP\Definition\GeoJson\GeoJsonFeature;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Interface GeoJsonMapper describes mappers which can convert their definition to a GeoJSON representation.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper
|
||||
*/
|
||||
interface GeoJsonMapper
|
||||
{
|
||||
/**
|
||||
* @param \Model $model
|
||||
* @param DefinitionMapper $mapper
|
||||
* @param LatLngBounds $bounds
|
||||
* Hanle the GeoJSON creation.
|
||||
*
|
||||
* @return mixed
|
||||
* @param \Model $model The model being mapped.
|
||||
* @param DefinitionMapper $mapper The definition mapper.
|
||||
* @param LatLngBounds $bounds The requested bounds.
|
||||
*
|
||||
* @return GeoJsonFeature|null
|
||||
*/
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
|
||||
}
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
|
||||
/**
|
||||
* Class AbstractLayerMapper is the base mapper for the layer model.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
class AbstractLayerMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
@@ -22,6 +27,9 @@ class AbstractLayerMapper extends AbstractTypeMapper
|
||||
*/
|
||||
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
|
||||
use Netzmacht\LeafletPHP\Definition\Layer;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class GroupLayerMapper maps the layer model to the group layer definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
class GroupLayerMapper extends AbstractLayerMapper
|
||||
{
|
||||
/**
|
||||
@@ -44,7 +48,7 @@ class GroupLayerMapper extends AbstractLayerMapper
|
||||
return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup';
|
||||
}
|
||||
|
||||
return parent::getClassName($model, $mapper, $bounds); // TODO: Change the autogenerated stub
|
||||
return parent::getClassName($model, $mapper, $bounds);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -24,6 +24,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
|
||||
|
||||
/**
|
||||
* Class MarkersLayerMapper maps the layer model to the markers definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
{
|
||||
/**
|
||||
@@ -81,11 +86,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Model $model
|
||||
* @param DefinitionMapper $mapper
|
||||
* @param LatLngBounds $bounds
|
||||
*
|
||||
* @return mixed
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
@@ -106,18 +107,14 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Model $model
|
||||
* Load all layer markers.
|
||||
*
|
||||
* @param \Model $model The layer model.
|
||||
*
|
||||
* @return \Model\Collection|null
|
||||
*/
|
||||
protected function loadMarkerModels(\Model $model)
|
||||
{
|
||||
$collection = MarkerModel::findBy(
|
||||
array('active=1', 'pid=?'),
|
||||
array($model->id),
|
||||
array('order' => 'sorting')
|
||||
);
|
||||
|
||||
return $collection;
|
||||
return MarkerModel::findActiveBy('pid', $model->id, array('order' => 'sorting'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,6 +15,11 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class ProviderLayerMapper maps the layer model to the tile provider definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
class ProviderLayerMapper extends AbstractLayerMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -16,7 +16,7 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class ReferenceLayerMapper maps an reference layer to another
|
||||
* Class ReferenceLayerMapper maps an reference layer to another layer.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
|
||||
@@ -26,6 +26,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector;
|
||||
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax;
|
||||
|
||||
/**
|
||||
* Class VectorsLayerMapper maps the layer model for the Vectors layer definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Layer
|
||||
*/
|
||||
class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
{
|
||||
/**
|
||||
@@ -87,11 +92,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Model $model
|
||||
* @param DefinitionMapper $mapper
|
||||
* @param LatLngBounds $bounds
|
||||
*
|
||||
* @return mixed
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
@@ -114,19 +115,14 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \Model $model
|
||||
* Load vector models.
|
||||
*
|
||||
* @param \Model $model The layer model.
|
||||
*
|
||||
* @return \Model\Collection|null
|
||||
*/
|
||||
protected function loadVectorModels(\Model $model)
|
||||
{
|
||||
$collection = VectorModel::findBy(
|
||||
array('active=1', 'pid=?'),
|
||||
array($model->id),
|
||||
array('order' => 'sorting')
|
||||
);
|
||||
|
||||
return $collection;
|
||||
return VectorModel::findActiveBy('pid', $model->id, array('order' => 'sorting'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,11 @@ use Netzmacht\LeafletPHP\Definition\Layer;
|
||||
use Netzmacht\LeafletPHP\Definition\Map;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
|
||||
/**
|
||||
* Class MapMapper maps the database map model to the leaflet definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper
|
||||
*/
|
||||
class MapMapper extends AbstractMapper
|
||||
{
|
||||
/**
|
||||
@@ -38,7 +42,7 @@ class MapMapper extends AbstractMapper
|
||||
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Map';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
@@ -51,7 +55,7 @@ class MapMapper extends AbstractMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(Definition $map, \Model $model, DefinitionMapper $builder, LatLngBounds $bounds = null)
|
||||
{
|
||||
@@ -63,7 +67,7 @@ class MapMapper extends AbstractMapper
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
@@ -99,6 +103,8 @@ class MapMapper extends AbstractMapper
|
||||
* @param MapModel $model The map model.
|
||||
* @param DefinitionMapper $mapper The definition mapper.
|
||||
* @param LatLngBounds $bounds Optional bounds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
@@ -124,6 +130,8 @@ class MapMapper extends AbstractMapper
|
||||
* @param MapModel $model The map model.
|
||||
* @param DefinitionMapper $mapper Definition mapper.
|
||||
* @param LatLngBounds $bounds Optional bounds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
|
||||
{
|
||||
|
||||
@@ -14,12 +14,17 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Interface Mapper describes the Mapper which translates a given configuration to the Leaflet definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper
|
||||
*/
|
||||
interface Mapper
|
||||
{
|
||||
/**
|
||||
* Map model to the definition.
|
||||
*
|
||||
* @param \Model|mixed $model The model being built. Usually a contao model. but can be anything
|
||||
* @param \Model|mixed $model The model being built. Usually a contao model, but can be anything.
|
||||
* @param DefinitionMapper $mapper The definition builder.
|
||||
* @param LatLngBounds $bounds Optional bounds where elements should be in.
|
||||
* @param string $elementId Optional element id.
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Style;
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
|
||||
/**
|
||||
* Class AbstractStyleMapper is the base mapper for the style model.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Style
|
||||
*/
|
||||
abstract class AbstractStyleMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Style;
|
||||
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
|
||||
/**
|
||||
* Class FixedStyleMapper maps the fixed style to the corresponding definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Style
|
||||
*/
|
||||
class FixedStyleMapper extends AbstractStyleMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,9 +11,13 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
|
||||
/**
|
||||
* Class AbstractIconMapper is the base mapper for the icon model.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Type
|
||||
*/
|
||||
class AbstractIconMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,12 +11,16 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\DivIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class DivIconMapper maps the icon model to the div icon definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Type
|
||||
*/
|
||||
class DivIconMapper extends AbstractIconMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Type;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
|
||||
/**
|
||||
* Class ImageIconMapper maps the icon model to the image icon definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Type
|
||||
*/
|
||||
class ImageIconMapper extends AbstractIconMapper
|
||||
{
|
||||
/**
|
||||
@@ -74,7 +78,7 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
/**
|
||||
* Add icon image.
|
||||
*
|
||||
* @param ImageIcon $definition The icon definition.
|
||||
* @param ImageIcon $definition The icon definition.
|
||||
* @param IconModel $model The model.
|
||||
*
|
||||
* @return void
|
||||
@@ -116,7 +120,7 @@ class ImageIconMapper extends AbstractIconMapper
|
||||
/**
|
||||
* Add shadow if defined.
|
||||
*
|
||||
* @param ImageIcon $definition The icon definition.
|
||||
* @param ImageIcon $definition The icon definition.
|
||||
* @param IconModel $model The model.
|
||||
*
|
||||
* @return void
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\UI;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\Contao\Leaflet\Model\IconModel;
|
||||
@@ -20,6 +19,11 @@ use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\UI\Marker;
|
||||
|
||||
/**
|
||||
* Class MarkerMapper maps the marker model to the marker definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\UI
|
||||
*/
|
||||
class MarkerMapper extends AbstractMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Definition\Style;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
@@ -21,6 +20,11 @@ use Netzmacht\LeafletPHP\Definition\HasPopup;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Path;
|
||||
|
||||
/**
|
||||
* Class AbstractVectorMapper is the base class for the vector model definition mapping.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class AbstractVectorMapper extends AbstractTypeMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
|
||||
|
||||
/**
|
||||
* Class CircleMapper maps the database model to the circle definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class CircleMapper extends AbstractVectorMapper
|
||||
{
|
||||
/**
|
||||
@@ -34,6 +38,9 @@ class CircleMapper extends AbstractVectorMapper
|
||||
*/
|
||||
protected static $type = 'circle';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
@@ -41,6 +48,9 @@ class CircleMapper extends AbstractVectorMapper
|
||||
$this->addOption('radius');
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
|
||||
|
||||
/**
|
||||
* Class CircleMarkerMapper maps the database model to the circle marker definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class CircleMarkerMapper extends CircleMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon;
|
||||
|
||||
/**
|
||||
* Class MultiPolygonMapper maps the multi polygon database model to its definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class MultiPolygonMapper extends MultiPolylineMapper
|
||||
{
|
||||
/**
|
||||
@@ -34,6 +38,9 @@ class MultiPolygonMapper extends MultiPolylineMapper
|
||||
*/
|
||||
protected static $type = 'multiPolygon';
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
@@ -43,18 +50,7 @@ class MultiPolygonMapper extends MultiPolylineMapper
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
|
||||
if ($definition instanceof MultiPolygon) {
|
||||
$latLngs = array();
|
||||
|
||||
foreach (deserialize($model->multiData, true) as $data) {
|
||||
$latLngs[] = array_map(
|
||||
function ($row) {
|
||||
return LatLng::fromString($row);
|
||||
},
|
||||
explode("\n", $data)
|
||||
);
|
||||
}
|
||||
|
||||
$definition->setLatLngs($latLngs);
|
||||
$this->createLatLngs($definition, $model);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolyline;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
|
||||
|
||||
/**
|
||||
* Class MultiPolylineMapper maps the databse model it the multi polyline definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class MultiPolylineMapper extends AbstractVectorMapper
|
||||
{
|
||||
/**
|
||||
@@ -35,7 +39,9 @@ class MultiPolylineMapper extends AbstractVectorMapper
|
||||
*/
|
||||
protected static $type = 'multiPolyline';
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
@@ -45,18 +51,31 @@ class MultiPolylineMapper extends AbstractVectorMapper
|
||||
parent::build($definition, $model, $builder, $bounds);
|
||||
|
||||
if ($definition instanceof MultiPolyline) {
|
||||
$latLngs = array();
|
||||
|
||||
foreach (deserialize($model->multiData, true) as $data) {
|
||||
$latLngs[] = array_map(
|
||||
function ($row) {
|
||||
return LatLng::fromString($row);
|
||||
},
|
||||
explode("\n", $data)
|
||||
);
|
||||
}
|
||||
|
||||
$definition->setLatLngs($latLngs);
|
||||
$this->createLatLngs($definition, $model);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create lat lngs for the definition.
|
||||
*
|
||||
* @param MultiPolyline $definition The multi polyline.
|
||||
* @param \Model $model The definition model.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function createLatLngs(MultiPolyline $definition, \Model $model)
|
||||
{
|
||||
$latLngs = array();
|
||||
|
||||
foreach (deserialize($model->multiData, true) as $data) {
|
||||
$latLngs[] = array_map(
|
||||
function ($row) {
|
||||
return LatLng::fromString($row);
|
||||
},
|
||||
explode("\n", $data)
|
||||
);
|
||||
}
|
||||
|
||||
$definition->setLatLngs($latLngs);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,6 +11,11 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
/**
|
||||
* Class PolygonMapper maps the database model to the polygon definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class PolygonMapper extends PolylineMapper
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -11,13 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Polyline;
|
||||
|
||||
/**
|
||||
* Class PolylineMapper maps the database model to the polyline definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class PolylineMapper extends AbstractVectorMapper
|
||||
{
|
||||
/**
|
||||
@@ -34,7 +38,9 @@ class PolylineMapper extends AbstractVectorMapper
|
||||
*/
|
||||
protected static $type = 'polyline';
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function build(
|
||||
Definition $definition,
|
||||
\Model $model,
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
|
||||
use Netzmacht\LeafletPHP\Definition;
|
||||
use Netzmacht\LeafletPHP\Definition\Type\LatLng;
|
||||
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Circle;
|
||||
use Netzmacht\LeafletPHP\Definition\Vector\Rectangle;
|
||||
|
||||
/**
|
||||
* Class RectangleMapper maps a database model to its rectangle vector definition.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Mapper\Vector
|
||||
*/
|
||||
class RectangleMapper extends AbstractVectorMapper
|
||||
{
|
||||
/**
|
||||
@@ -35,11 +39,9 @@ class RectangleMapper extends AbstractVectorMapper
|
||||
*/
|
||||
protected static $type = 'rectangle';
|
||||
|
||||
protected function initialize()
|
||||
{
|
||||
parent::initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected function buildConstructArguments(
|
||||
\Model $model,
|
||||
DefinitionMapper $mapper,
|
||||
@@ -47,7 +49,7 @@ class RectangleMapper extends AbstractVectorMapper
|
||||
$elementId = null
|
||||
) {
|
||||
$latLngs = array_map(
|
||||
function($latLng) {
|
||||
function ($latLng) {
|
||||
return LatLng::fromString($latLng);
|
||||
},
|
||||
deserialize($model->bounds, true)
|
||||
|
||||
@@ -11,13 +11,18 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Class AbstractActiveModel is the base model for models with an active field.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
abstract class AbstractActiveModel extends \Model
|
||||
{
|
||||
/**
|
||||
* Find an active model by its model id.
|
||||
*
|
||||
* @param int $modelId
|
||||
* @param array $options
|
||||
* @param int $modelId The model id.
|
||||
* @param array $options The query options.
|
||||
*
|
||||
* @return \Model|null
|
||||
*/
|
||||
@@ -27,18 +32,33 @@ abstract class AbstractActiveModel extends \Model
|
||||
}
|
||||
|
||||
/**
|
||||
* Find active models by a defined column.
|
||||
*
|
||||
* @param int $value
|
||||
* @param array $options
|
||||
* @param string|array $column The query columns.
|
||||
* @param mixed $value The column value.
|
||||
* @param array $options The options.
|
||||
*
|
||||
* @return \Model|null
|
||||
*/
|
||||
public static function findActiveBy($column, $value, $options = array())
|
||||
{
|
||||
return static::findBy('active=1 AND ' . $column, $value, $options);
|
||||
if (is_array($column)) {
|
||||
$column[] = 'active=1';
|
||||
} else {
|
||||
$column = 'active=1 AND ' . $column;
|
||||
}
|
||||
|
||||
return static::findBy($column, $value, $options);
|
||||
}
|
||||
|
||||
public static function findActivated($options = array())
|
||||
/**
|
||||
* Find collection activated models.
|
||||
*
|
||||
* @param array $options The query options.
|
||||
*
|
||||
* @return \Model\Collection|null
|
||||
*/
|
||||
public static function findActives($options = array())
|
||||
{
|
||||
return static::findBy('active', '1', $options);
|
||||
}
|
||||
|
||||
@@ -11,33 +11,70 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
use Model\Collection;
|
||||
|
||||
/**
|
||||
* Class ControlModel for the tl_leaflet_vector table.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class ControlModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
* Model table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_control';
|
||||
|
||||
/**
|
||||
* @return \Model\Collection
|
||||
* Find all related layers.
|
||||
*
|
||||
* @return Collection|null
|
||||
*/
|
||||
public function findLayers()
|
||||
{
|
||||
$query = 'SELECT l.*, c.mode as controlMode FROM tl_leaflet_layer l LEFT JOIN tl_leaflet_control_layer c ON l.id = c.lid WHERE c.cid=?';
|
||||
$query = <<<SQL
|
||||
SELECT l.*, c.mode as controlMode
|
||||
FROM tl_leaflet_layer l
|
||||
LEFT JOIN tl_leaflet_control_layer c ON l.id = c.lid
|
||||
WHERE c.cid=?
|
||||
SQL;
|
||||
|
||||
$result = \Database::getInstance()
|
||||
->prepare($query)
|
||||
->execute($this->id);
|
||||
|
||||
return \Model\Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
if ($result->numRows < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Model\Collection
|
||||
* Find active layers.
|
||||
*
|
||||
* @return Collection|null
|
||||
*/
|
||||
public function findActiveLayers()
|
||||
{
|
||||
$query = 'SELECT l.*, c.mode as controlMode FROM tl_leaflet_layer l LEFT JOIN tl_leaflet_control_layer c ON l.id = c.lid WHERE c.cid=? AND l.active=1';
|
||||
$query = <<<SQL
|
||||
SELECT l.*, c.mode as controlMode
|
||||
FROM tl_leaflet_layer l
|
||||
LEFT JOIN tl_leaflet_control_layer
|
||||
c ON l.id = c.lid
|
||||
WHERE c.cid=? AND l.active=1
|
||||
SQL;
|
||||
|
||||
$result = \Database::getInstance()
|
||||
->prepare($query)
|
||||
->execute($this->id);
|
||||
|
||||
return \Model\Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
if ($result->numRows < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
/**
|
||||
* IconModel class for the tl_leaflet_icon table.
|
||||
*
|
||||
* @property mixed|null iconImage
|
||||
* @property mixed|null iconAnchor
|
||||
* @property mixed|null popupAnchor
|
||||
@@ -23,5 +24,10 @@ namespace Netzmacht\Contao\Leaflet\Model;
|
||||
*/
|
||||
class IconModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
* Model table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_icon';
|
||||
}
|
||||
|
||||
@@ -11,11 +11,30 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
use Model\Collection;
|
||||
|
||||
/**
|
||||
* Class LayerModel for the tl_leaflet_layer table.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class LayerModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
* Model table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_layer';
|
||||
|
||||
/**
|
||||
* Find multiple layers by given type.
|
||||
*
|
||||
* @param array $types List of layer types.
|
||||
* @param array $options Query options.
|
||||
*
|
||||
* @return Collection|null
|
||||
*/
|
||||
public static function findMultipleByTypes(array $types, $options = array())
|
||||
{
|
||||
if (empty($types)) {
|
||||
@@ -29,7 +48,8 @@ class LayerModel extends AbstractActiveModel
|
||||
)
|
||||
);
|
||||
|
||||
$options['value'] = $types;
|
||||
$options['value'] = $types;
|
||||
$options['return'] = 'Collection';
|
||||
|
||||
return static::find($options);
|
||||
}
|
||||
|
||||
@@ -11,13 +11,26 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
use Model\Collection;
|
||||
|
||||
/**
|
||||
* Class MapModel for the tl_leaflet_map table.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class MapModel extends \Model
|
||||
{
|
||||
/**
|
||||
* Model table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_map';
|
||||
|
||||
/**
|
||||
* @return \Model\Collection
|
||||
* Find all related layers.
|
||||
*
|
||||
* @return Collection|null
|
||||
*/
|
||||
public function findLayers()
|
||||
{
|
||||
@@ -26,19 +39,34 @@ class MapModel extends \Model
|
||||
->prepare($query)
|
||||
->execute($this->id);
|
||||
|
||||
return \Model\Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
if ($result->numRows < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Model\Collection
|
||||
* Find all active layers.
|
||||
*
|
||||
* @return Collection|null
|
||||
*/
|
||||
public function findActiveLayers()
|
||||
{
|
||||
$query = 'SELECT l.* FROM tl_leaflet_layer l LEFT JOIN tl_leaflet_map_layer m ON l.id = m.lid WHERE m.mid=? AND l.active=1';
|
||||
$result = \Database::getInstance()
|
||||
->prepare($query)
|
||||
->execute($this->id);
|
||||
$query = <<<SQL
|
||||
SELECT l.*
|
||||
FROM tl_leaflet_layer l
|
||||
LEFT JOIN tl_leaflet_map_layer m
|
||||
ON l.id = m.lid
|
||||
WHERE m.mid=? AND l.active=1
|
||||
SQL;
|
||||
|
||||
return \Model\Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
$result = \Database::getInstance()->prepare($query)->execute($this->id);
|
||||
|
||||
if ($result->numRows) {
|
||||
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,9 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Class MarkerModel for the tl_leaflet_marker table.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class MarkerModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
* Model table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_marker';
|
||||
|
||||
}
|
||||
|
||||
@@ -11,8 +11,17 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Class StyleModel for the tl_leaflet_style table.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class StyleModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
* Model table.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected static $strTable = 'tl_leaflet_style';
|
||||
}
|
||||
|
||||
@@ -11,7 +11,11 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Model;
|
||||
|
||||
|
||||
/**
|
||||
* Class VectorModel for the tl_leaflet_vector table.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Model
|
||||
*/
|
||||
class VectorModel extends AbstractActiveModel
|
||||
{
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Class BootSubscriber
|
||||
* Class BootSubscriber provides handlers for leaflet boot process.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Subscriber
|
||||
*/
|
||||
@@ -111,6 +111,8 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
* Load Contao leaflet assets.
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function loadAssets()
|
||||
{
|
||||
@@ -123,7 +125,9 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
/**
|
||||
* Load icons.
|
||||
*
|
||||
* @throws \Netzmacht\Javascript\Exception\EncodeValueFailed
|
||||
* @return void
|
||||
*
|
||||
* @SuppressWarnings(PHPMD.Superglobals)
|
||||
*/
|
||||
public function loadIcons()
|
||||
{
|
||||
@@ -153,7 +157,9 @@ class BootSubscriber implements EventSubscriberInterface
|
||||
$file->write($buffer);
|
||||
$file->close();
|
||||
|
||||
// @codingStandardsIgnoreStart
|
||||
// TODO: Cache it.
|
||||
// codingStandardsIgnoreEnd
|
||||
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/js/icons.js' . (\Config::get('debugMode')
|
||||
? ''
|
||||
: '|static'
|
||||
|
||||
@@ -77,6 +77,13 @@ class EncoderSubscriber implements EventSubscriberInterface
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Force that icons are encoded as reference to the ContaoLeaflet icon registry.
|
||||
*
|
||||
* @param EncodeValueEvent $event The subscribed event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function encodeIcons(EncodeValueEvent $event)
|
||||
{
|
||||
$value = $event->getValue();
|
||||
|
||||
@@ -11,10 +11,14 @@
|
||||
|
||||
namespace Netzmacht\Contao\Leaflet\Subscriber;
|
||||
|
||||
|
||||
use Netzmacht\Contao\Leaflet\Event\GetHashEvent;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
/**
|
||||
* Class HashSubscriber creates hashes for models and for data which does not have a hash created by other subscribers.
|
||||
*
|
||||
* @package Netzmacht\Contao\Leaflet\Subscriber
|
||||
*/
|
||||
class HashSubscriber implements EventSubscriberInterface
|
||||
{
|
||||
/**
|
||||
@@ -33,7 +37,9 @@ class HashSubscriber implements EventSubscriberInterface
|
||||
/**
|
||||
* Get hash for a model object.
|
||||
*
|
||||
* @param GetHashEvent $event
|
||||
* @param GetHashEvent $event The subscribed event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getModelHash(GetHashEvent $event)
|
||||
{
|
||||
@@ -47,7 +53,9 @@ class HashSubscriber implements EventSubscriberInterface
|
||||
/**
|
||||
* Get hash fallback if no hash was created so far.
|
||||
*
|
||||
* @param GetHashEvent $event
|
||||
* @param GetHashEvent $event The subscribed event.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function getFallback(GetHashEvent $event)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user