Fix code style.

This commit is contained in:
David Molineus
2015-01-12 19:03:29 +01:00
parent 74c786c24b
commit 037c6c907d
77 changed files with 1068 additions and 398 deletions

View File

@@ -1,3 +1,5 @@
phpcs.standard=${basedir}/vendor/contao-community-alliance/coding-standard/phpcs/ContaoCommunityAlliance/ruleset.xml 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 phpmd.ruleset=${basedir}/vendor/contao-community-alliance/coding-standard/phpmd/ruleset.xml
ccabs.bin.dir = ${basedir}/bin

View File

@@ -25,7 +25,7 @@
"contao-community-alliance/url-builder":"~1.1", "contao-community-alliance/url-builder":"~1.1",
"netzmacht/contao-leaflet-libraries": "~0.7", "netzmacht/contao-leaflet-libraries": "~0.7",
"netzmacht/php-javascript-builder": "~1.0", "netzmacht/php-javascript-builder": "~1.0",
"netzmacht/php-leaflet": "dev-master", "netzmacht/php-leaflet": "~0.7",
"netzmacht/contao-dev-tools":"~1.0", "netzmacht/contao-dev-tools":"~1.0",
"bit3/contao-meta-palettes": "~1.5", "bit3/contao-meta-palettes": "~1.5",
"menatwork/contao-multicolumnwizard": "~3.2", "menatwork/contao-multicolumnwizard": "~3.2",

View File

@@ -1,5 +1,14 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
TemplateLoader::addFiles( TemplateLoader::addFiles(
array( array(
'ce_leaflet_map' => 'system/modules/leaflet/templates', 'ce_leaflet_map' => 'system/modules/leaflet/templates',

View File

@@ -1,5 +1,14 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
/* /*
* Backend module. * Backend module.
*/ */

View File

@@ -1,5 +1,13 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
return array( return array(
'Netzmacht\Contao\Leaflet\Subscriber\BootSubscriber', 'Netzmacht\Contao\Leaflet\Subscriber\BootSubscriber',
'Netzmacht\Contao\Leaflet\Subscriber\HashSubscriber', 'Netzmacht\Contao\Leaflet\Subscriber\HashSubscriber',

View File

@@ -1,5 +1,14 @@
<?php <?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. * Support all providers and variants which are supported by leaflet-providers.
* See https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js * See https://github.com/leaflet-extras/leaflet-providers/blob/master/leaflet-providers.js

View File

@@ -1,5 +1,14 @@
<?php <?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\Boot;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\MapService; use Netzmacht\Contao\Leaflet\MapService;

View File

@@ -1,5 +1,14 @@
<?php <?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( $GLOBALS['TL_DCA']['tl_content']['metapalettes']['leaflet'] = array(
'type' => array('type', 'headline'), 'type' => array('type', 'headline'),
'leaflet' => array('leaflet_map', 'leaflet_width', 'leaflet_height'), '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'], 'label' => &$GLOBALS['TL_LANG']['tl_content']['leaflet_map'],
'inputType' => 'select', 'inputType' => 'select',
'exclude' => true, 'exclude' => true,
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Content', 'getMaps'), 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getMaps'),
'wizard' => array( 'wizard' => array(
array('Netzmacht\Contao\Leaflet\Dca\Content', 'getEditMapLink'), array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getEditMapLink'),
), ),
'eval' => array( 'eval' => array(
'tl_class' => 'w50 wizard', 'tl_class' => 'w50 wizard',

View File

@@ -1,5 +1,13 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
\Controller::loadLanguageFile('leaflet'); \Controller::loadLanguageFile('leaflet');
$GLOBALS['TL_DCA']['tl_leaflet_control'] = array $GLOBALS['TL_DCA']['tl_leaflet_control'] = array

View File

@@ -1,5 +1,14 @@
<?php <?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 $GLOBALS['TL_DCA']['tl_leaflet_control_layer'] = array
( (
'config' => array( 'config' => array(

View File

@@ -1,5 +1,14 @@
<?php <?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 $GLOBALS['TL_DCA']['tl_leaflet_icon'] = array
( (
'config' => array( 'config' => array(

View File

@@ -1,5 +1,14 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
\Controller::loadLanguageFile('leaflet'); \Controller::loadLanguageFile('leaflet');
$GLOBALS['TL_DCA']['tl_leaflet_layer'] = array $GLOBALS['TL_DCA']['tl_leaflet_layer'] = array

View File

@@ -1,5 +1,14 @@
<?php <?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 $GLOBALS['TL_DCA']['tl_leaflet_map'] = array
( (
'config' => array( 'config' => array(

View File

@@ -1,5 +1,14 @@
<?php <?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 $GLOBALS['TL_DCA']['tl_leaflet_map_layer'] = array
( (
'config' => array( 'config' => array(

View File

@@ -1,5 +1,14 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
\Controller::loadLanguageFile('leaflet'); \Controller::loadLanguageFile('leaflet');

View File

@@ -1,5 +1,13 @@
<?php <?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 $GLOBALS['TL_DCA']['tl_leaflet_style'] = array
( (
'config' => array( 'config' => array(

View File

@@ -1,5 +1,14 @@
<?php <?php
/**
* @package dev
* @author David Molineus <david.molineus@netzmacht.de>
* @copyright 2014 netzmacht creative David Molineus
* @license LGPL 3.0
* @filesource
*
*/
\Controller::loadLanguageFile('leaflet'); \Controller::loadLanguageFile('leaflet');
$GLOBALS['TL_DCA']['tl_leaflet_vector'] = array $GLOBALS['TL_DCA']['tl_leaflet_vector'] = array

View File

@@ -1,5 +1,14 @@
<?php <?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( $GLOBALS['TL_DCA']['tl_module']['metapalettes']['leaflet'] = array(
'type' => array('name', 'type', 'headline'), 'type' => array('name', 'type', 'headline'),
'leaflet' => array('leaflet_map', 'leaflet_width', 'leaflet_height'), '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'], 'label' => &$GLOBALS['TL_LANG']['tl_module']['leaflet_map'],
'inputType' => 'select', 'inputType' => 'select',
'exclude' => true, 'exclude' => true,
'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\Module', 'getMaps'), 'options_callback' => array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getMaps'),
'wizard' => array( 'wizard' => array(
array('Netzmacht\Contao\Leaflet\Dca\Module', 'getEditMapLink'), array('Netzmacht\Contao\Leaflet\Dca\FrontendIntegration', 'getEditMapLink'),
), ),
'eval' => array( 'eval' => array(
'tl_class' => 'w50 wizard', 'tl_class' => 'w50 wizard',

View File

@@ -11,9 +11,18 @@
namespace Netzmacht\Contao\Leaflet\Backend; namespace Netzmacht\Contao\Leaflet\Backend;
/**
* Credits backend module.
*
* @package Netzmacht\Contao\Leaflet\Backend
*/
class Credits class Credits
{ {
/**
* Generate the backend view.
*
* @return string
*/
public function generate() public function generate()
{ {
$template = new \BackendTemplate('be_leaflet_credits'); $template = new \BackendTemplate('be_leaflet_credits');
@@ -26,6 +35,13 @@ class Credits
return $template->parse(); return $template->parse();
} }
/**
* Get list of all libraries.
*
* @return array
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
private function getLibraries() private function getLibraries()
{ {
return array_map( return array_map(
@@ -58,6 +74,11 @@ class Credits
); );
} }
/**
* Extract version and dependencies from composer.
*
* @return array
*/
private function extractFromComposer() private function extractFromComposer()
{ {
$local = TL_ROOT . '/composer/vendor/netzmacht/contao-leaflet-maps/composer.json'; $local = TL_ROOT . '/composer/vendor/netzmacht/contao-leaflet-maps/composer.json';

View File

@@ -14,18 +14,23 @@ namespace Netzmacht\Contao\Leaflet;
use Netzmacht\LeafletPHP\Assets; use Netzmacht\LeafletPHP\Assets;
/** /**
* Class ContaoAssets * Class ContaoAssets handles leaflet assets and integrate them into the Contao assets registry (Superglobals).
*
* @package Netzmacht\Contao\Leaflet * @package Netzmacht\Contao\Leaflet
*/ */
class ContaoAssets implements Assets class ContaoAssets implements Assets
{ {
/** /**
* @var * The map javascript.
*
* @var string
*/ */
private $map; private $map;
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/ */
public function addJavascript($script, $type = self::TYPE_SOURCE) public function addJavascript($script, $type = self::TYPE_SOURCE)
{ {
@@ -48,6 +53,8 @@ class ContaoAssets implements Assets
/** /**
* {@inheritdoc} * {@inheritdoc}
*
* @SuppressWarnings(PHPMD.Superglobals)
*/ */
public function addStylesheet($stylesheet, $type = self::TYPE_FILE) public function addStylesheet($stylesheet, $type = self::TYPE_FILE)
{ {

View File

@@ -11,26 +11,42 @@
namespace Netzmacht\Contao\Leaflet\Dca; namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder; use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\DevTools\ServiceContainerTrait; use Netzmacht\Contao\DevTools\ServiceContainerTrait;
use Netzmacht\Contao\Leaflet\Model\ControlModel; use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\LayerModel;
/**
* Class Control is the helper for the tl_leaflet_control dca.
*
* @package Netzmacht\Contao\Leaflet\Dca
*/
class Control class Control
{ {
use ServiceContainerTrait; use ServiceContainerTrait;
/** /**
* The database connection.
*
* @var \Database * @var \Database
*/ */
private $database; private $database;
/**
* Construct.
*/
public function __construct() public function __construct()
{ {
$this->database = static::getService('database.connection'); $this->database = static::getService('database.connection');
} }
/**
* Generate a row.
*
* @param array $row The data row.
*
* @return string
*/
public function generateRow($row) public function generateRow($row)
{ {
return sprintf( return sprintf(
@@ -40,6 +56,11 @@ class Control
); );
} }
/**
* Get layers for the layers control.
*
* @return array
*/
public function getLayers() public function getLayers()
{ {
$options = array(); $options = array();
@@ -54,6 +75,11 @@ class Control
return $options; return $options;
} }
/**
* Get the zoom controls for the reference value of the loading control.
*
* @return array
*/
public function getZoomControls() public function getZoomControls()
{ {
$collection = ControlModel::findBy('type', 'zoom', array('order' => 'title')); $collection = ControlModel::findBy('type', 'zoom', array('order' => 'title'));
@@ -61,6 +87,16 @@ class Control
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions(); 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) public function loadLayerRelations($value, $dataContainer)
{ {
$result = $this->database $result = $this->database
@@ -70,6 +106,14 @@ class Control
return $result->fetchAllAssoc(); 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) public function saveLayerRelations($layers, $dataContainer)
{ {
$new = deserialize($layers, true); $new = deserialize($layers, true);

View File

@@ -15,10 +15,11 @@ use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\Contao\Leaflet\Model\MapModel;
/** /**
* Class Content * Class Module is the helper for the tl_module dca.
*
* @package Netzmacht\Contao\Leaflet\Dca * @package Netzmacht\Contao\Leaflet\Dca
*/ */
class Content class FrontendIntegration
{ {
/** /**
* Get all leaflet maps. * Get all leaflet maps.
@@ -32,20 +33,31 @@ class Content
return OptionsBuilder::fromCollection($collection, 'id', 'title')->getOptions(); 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) public function getEditMapLink($dataContainer)
{ {
if ($dataContainer->value < 1) { if ($dataContainer->value < 1) {
return ''; return '';
} }
$pattern = 'title="%s" style="padding-left: 3px" onclick="Backend.openModalIframe(';
$pattern .= '{\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"';
return sprintf( return sprintf(
'<a href="%s%s&amp;popup=1&amp;rt=%s" %s>%s</a>', '<a href="%s%s&amp;popup=1&amp;rt=%s" %s>%s</a>',
'contao/main.php?do=leaflet&amp;table=tl_leaflet_map&amp;act=edit&amp;id=', 'contao/main.php?do=leaflet&amp;table=tl_leaflet_map&amp;act=edit&amp;id=',
$dataContainer->value, $dataContainer->value,
\RequestToken::get(), \RequestToken::get(),
sprintf( sprintf(
'title="%s" style="padding-left: 3px" ' $pattern,
. 'onclick="Backend.openModalIframe({\'width\':768,\'title\':\'%s\',\'url\':this.href});return false"',
specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)), specialchars(sprintf($GLOBALS['TL_LANG']['tl_content']['editalias'][1], $dataContainer->value)),
specialchars( specialchars(
str_replace( str_replace(
@@ -57,7 +69,8 @@ class Content
), ),
\Image::getHtml( \Image::getHtml(
'alias.gif', 'alias.gif',
$GLOBALS['TL_LANG']['tl_content']['editalias'][0], 'style="vertical-align:top"' $GLOBALS['TL_LANG']['tl_content']['editalias'][0],
'style="vertical-align:top"'
) )
); );
} }

View File

@@ -11,22 +11,38 @@
namespace Netzmacht\Contao\Leaflet\Dca; namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder; use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\DevTools\ServiceContainerTrait; use Netzmacht\Contao\DevTools\ServiceContainerTrait;
use Netzmacht\Contao\Leaflet\Model\LayerModel; 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 class Layer
{ {
use ServiceContainerTrait; use ServiceContainerTrait;
/**
* Layers definition.
*
* @var array
*/
private $layers; private $layers;
/** /**
* The database connection.
*
* @var \Database * @var \Database
*/ */
private $database; private $database;
/**
* Construct.
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
public function __construct() public function __construct()
{ {
$this->layers = &$GLOBALS['LEAFLET_LAYERS']; $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) public function getVariants($dataContainer)
{ {
if ($dataContainer->activeRecord if ($dataContainer->activeRecord
@@ -48,6 +73,16 @@ class Layer
return array(); 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) public function generateRow($row, $label)
{ {
$alt = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0]) $alt = empty($GLOBALS['TL_LANG']['leaflet_layer'][$row['type']][0])
@@ -74,11 +109,16 @@ class Layer
return $icon . ' ' . $label; return $icon . ' ' . $label;
} }
/**
* Get all marker cluster layers.
*
* @return array
*/
public function getMarkerClusterLayers() public function getMarkerClusterLayers()
{ {
$types = array_keys( $types = array_keys(
array_filter( array_filter(
$GLOBALS['LEAFLET_LAYERS'], $this->layers,
function ($item) { function ($item) {
return !empty($item['markerCluster']); return !empty($item['markerCluster']);
} }
@@ -89,7 +129,7 @@ class Layer
$builder = OptionsBuilder::fromCollection( $builder = OptionsBuilder::fromCollection(
$collection, $collection,
'id', 'id',
function($row) { function ($row) {
return sprintf('%s [%s]', $row['title'], $row['type']); return sprintf('%s [%s]', $row['title'], $row['type']);
} }
); );
@@ -97,7 +137,20 @@ class Layer
return $builder->getOptions(); 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) public function getPasteButtons($dataContainer, $row, $table, $whatever, $children)
{ {
$pasteAfterUrl = \Controller::addToUrl( $pasteAfterUrl = \Controller::addToUrl(
@@ -142,6 +195,18 @@ class Layer
return $buffer; 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) public function generateMarkersButton($row, $href, $label, $title, $icon, $attributes)
{ {
if (empty($this->layers[$row['type']]['markers'])) { if (empty($this->layers[$row['type']]['markers'])) {
@@ -151,6 +216,18 @@ class Layer
return $this->generateButton($row, $href, $label, $title, $icon, $attributes); 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) public function generateVectorsButton($row, $href, $label, $title, $icon, $attributes)
{ {
if (empty($this->layers[$row['type']]['vectors'])) { if (empty($this->layers[$row['type']]['vectors'])) {
@@ -160,6 +237,13 @@ class Layer
return $this->generateButton($row, $href, $label, $title, $icon, $attributes); 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) public function getLayers($dataContainer)
{ {
$collection = LayerModel::findBy('id !', $dataContainer->id); $collection = LayerModel::findBy('id !', $dataContainer->id);
@@ -169,7 +253,14 @@ class Layer
->getOptions(); ->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) public function deleteRelations($dataContainer, $undoId)
{ {
if ($undoId) { if ($undoId) {
@@ -212,12 +303,14 @@ class Layer
} }
/** /**
* @param $row * Generate a button.
* @param $href *
* @param $label * @param array $row Current row.
* @param $title * @param string $href The button href.
* @param $icon * @param string $label The button label.
* @param $attributes * @param string $title The button title.
* @param string $icon The button icon.
* @param string $attributes Optional attributes.
* *
* @return string * @return string
*/ */

View File

@@ -11,19 +11,23 @@
namespace Netzmacht\Contao\Leaflet\Dca; namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Mapper\MapMapper; use Netzmacht\Contao\Leaflet\Mapper\MapMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\Contao\Leaflet\Model\MapModel; use Netzmacht\Contao\Leaflet\Model\MapModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; use Netzmacht\LeafletPHP\Definition\Type\LatLng;
/**
* Class Leaflet is the base helper providing different methods.
*
* @package Netzmacht\Contao\Leaflet\Dca
*/
class Leaflet class Leaflet
{ {
/** /**
* Validate a coordinate. * Validate a coordinate.
* *
* @param $value * @param mixed $value The given value.
* *
* @return mixed * @return mixed
*/ */
@@ -38,13 +42,23 @@ class Leaflet
return $value; return $value;
} }
/**
* Create the zoom range.
*
* @return array
*/
public function getZoomLevels() public function getZoomLevels()
{ {
return range(1, 20); return range(1, 20);
} }
/**
* Get the geocoder wizard.
*
* @param \DataContainer $dataContainer The dataContainer driver.
*
* @return string
*/
public function getGeocoder($dataContainer) public function getGeocoder($dataContainer)
{ {
$template = new \BackendTemplate('be_leaflet_geocode'); $template = new \BackendTemplate('be_leaflet_geocode');
@@ -53,14 +67,19 @@ class Leaflet
try { try {
$latLng = LatLng::fromString($dataContainer->value); $latLng = LatLng::fromString($dataContainer->value);
$template->marker = json_encode($latLng); $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(); return $template->parse();
} }
/**
* Get all layers.
*
* @return array
*/
public function getLayers() public function getLayers()
{ {
$options = array(); $options = array();

View File

@@ -11,23 +11,42 @@
namespace Netzmacht\Contao\Leaflet\Dca; namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\ServiceContainerTrait; use Netzmacht\Contao\DevTools\ServiceContainerTrait;
/**
* Class Map is the helper class for the tl_leaflet_map dca.
*
* @package Netzmacht\Contao\Leaflet\Dca
*/
class Map class Map
{ {
use ServiceContainerTrait; use ServiceContainerTrait;
/** /**
* The database connection.
*
* @var \Database * @var \Database
*/ */
private $database; private $database;
/**
* Construct.
*/
public function __construct() public function __construct()
{ {
$this->database = static::getService('database.connection'); $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) public function loadLayerRelations($value, $dataContainer)
{ {
$result = $this->database $result = $this->database
@@ -37,6 +56,14 @@ class Map
return $result->fetchEach('lid'); 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) public function saveLayerRelations($layerId, $dataContainer)
{ {
$new = deserialize($layerId, true); $new = deserialize($layerId, true);
@@ -67,7 +94,8 @@ class Map
$sorting += 128; $sorting += 128;
} else { } 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 $this->database
->prepare('UPDATE tl_leaflet_map_layer %s WHERE id=?') ->prepare('UPDATE tl_leaflet_map_layer %s WHERE id=?')
->set(array('tstamp' => time(), 'sorting' => $sorting)) ->set(array('tstamp' => time(), 'sorting' => $sorting))

View File

@@ -11,28 +11,44 @@
namespace Netzmacht\Contao\Leaflet\Dca; namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder; use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\IconModel; 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 class Marker
{ {
/**
* Generate the row label.
*
* @param array $row Current data row.
*
* @return string
*/
public function generateRow($row) public function generateRow($row)
{ {
return $row['title']; return $row['title'];
} }
/**
* Get all icons.
*
* @return array
*/
public function getIcons() public function getIcons()
{ {
$collection = IconModel::findAll(array('order' => 'title')); $collection = IconModel::findAll(array('order' => 'title'));
$builder = OptionsBuilder::fromCollection( $builder = OptionsBuilder::fromCollection(
$collection, 'id', $collection,
function($model) { 'id',
function ($model) {
return sprintf('%s [%s]', $model['title'], $model['type']); return sprintf('%s [%s]', $model['title'], $model['type']);
} }
); );
return $builder->getOptions(); return $builder->getOptions();
} }
} }

View File

@@ -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&amp;popup=1&amp;rt=%s" %s>%s</a>',
'contao/main.php?do=leaflet&amp;table=tl_leaflet_map&amp;act=edit&amp;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"'
)
);
}
}

View File

@@ -11,12 +11,23 @@
namespace Netzmacht\Contao\Leaflet\Dca; namespace Netzmacht\Contao\Leaflet\Dca;
use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder; use Netzmacht\Contao\DevTools\Dca\Options\OptionsBuilder;
use Netzmacht\Contao\Leaflet\Model\StyleModel; use Netzmacht\Contao\Leaflet\Model\StyleModel;
/**
* Helper class for the tl_leaflet_vector dca.
*
* @package Netzmacht\Contao\Leaflet\Dca
*/
class Vector class Vector
{ {
/**
* Generate the row label.
*
* @param array $row Current data row.
*
* @return string
*/
public function generateRow($row) public function generateRow($row)
{ {
return sprintf('%s <span class="tl_gray">[%s]</span>', $row['title'], $row['type']); return sprintf('%s <span class="tl_gray">[%s]</span>', $row['title'], $row['type']);

View File

@@ -11,12 +11,16 @@
namespace Netzmacht\Contao\Leaflet\Definition\Style; namespace Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\Contao\Leaflet\Definition\Style; use Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\LeafletPHP\Definition\AbstractDefinition; use Netzmacht\LeafletPHP\Definition\AbstractDefinition;
use Netzmacht\LeafletPHP\Definition\OptionsTrait; use Netzmacht\LeafletPHP\Definition\OptionsTrait;
use Netzmacht\LeafletPHP\Definition\Vector\Path; 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 class FixedStyle extends AbstractDefinition implements Style
{ {
use OptionsTrait; use OptionsTrait;

View File

@@ -52,7 +52,7 @@ class BuildDefinitionEvent extends Event
* @param \Model $model The definition model. * @param \Model $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @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->definition = $definition;
$this->model = $model; $this->model = $model;

View File

@@ -15,7 +15,7 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\Event;
/** /**
* Class InitializeDefinitionMapperEvent * Class InitializeDefinitionMapperEvent is emitted when the definition mapper is created.
* *
* @package Netzmacht\Contao\Leaflet\Event * @package Netzmacht\Contao\Leaflet\Event
*/ */
@@ -24,6 +24,8 @@ class InitializeDefinitionMapperEvent extends Event
const NAME = 'leaflet.boot.initialize-definition-mapper'; const NAME = 'leaflet.boot.initialize-definition-mapper';
/** /**
* The definitino mapper.
*
* @var DefinitionMapper * @var DefinitionMapper
*/ */
private $definitionMapper; private $definitionMapper;

View File

@@ -11,32 +11,53 @@
namespace Netzmacht\Contao\Leaflet\Frontend; namespace Netzmacht\Contao\Leaflet\Frontend;
use Netzmacht\Contao\Leaflet\MapService; use Netzmacht\Contao\Leaflet\MapService;
/**
* The data controller handles ajax request for sub data.
*
* @package Netzmacht\Contao\Leaflet\Frontend
*/
class DataController class DataController
{ {
/** /**
* The map service.
*
* @var MapService * @var MapService
*/ */
private $mapService; private $mapService;
/** /**
* The user input object.
*
* @var \Input * @var \Input
*/ */
private $input; private $input;
/**
* Construct.
*
* @param MapService $mapService The map service.
* @param \Input $input The user input object.
*/
public function __construct(MapService $mapService, \Input $input) public function __construct(MapService $mapService, \Input $input)
{ {
$this->mapService = $mapService; $this->mapService = $mapService;
$this->input = $input; $this->input = $input;
} }
/**
* Execute the controller and create the data response.
*
* @return void
*
* @throws \Exception If anything went wrong.
*/
public function execute() public function execute()
{ {
$format = $this->input->get('format') ?: 'geojson'; $format = $this->getInput('format', 'geojson');
$type = $this->input->get('type') ?: 'layer'; $type = $this->getInput('type', 'layer');
$dataId = $this->input->get('id'); $dataId = $this->getInput('id');
try { try {
list($data, $error) = $this->loadData($type, $dataId); list($data, $error) = $this->loadData($type, $dataId);
@@ -55,8 +76,12 @@ class DataController
} }
/** /**
* @param $format * Enocode the data.
* @param $data *
* @param string $format The requested format.
* @param mixed $data The given data.
*
* @return void
*/ */
public function encodeData($format, $data) public function encodeData($format, $data)
{ {
@@ -65,12 +90,17 @@ class DataController
header('Content-Type: application/json'); header('Content-Type: application/json');
echo json_encode($data, JSON_UNESCAPED_SLASHES); echo json_encode($data, JSON_UNESCAPED_SLASHES);
break; break;
default:
// Blame the code sniffer.
} }
} }
/** /**
* @param $type * Load the data.
* @param $dataId *
* @param string $type The data type.
* @param mixed $dataId The data id.
* *
* @return array * @return array
*/ */
@@ -92,4 +122,17 @@ class DataController
return array($data, $error); 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;
}
} }

View 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&amp;table=tl_leaflet_map&amp;act=edit&amp;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;
}
}
}

View File

@@ -12,14 +12,19 @@
namespace Netzmacht\Contao\Leaflet\Frontend; namespace Netzmacht\Contao\Leaflet\Frontend;
use ContentElement; use ContentElement;
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
use Netzmacht\Contao\Leaflet\MapService; use Netzmacht\Contao\Leaflet\MapService;
use Netzmacht\Contao\Leaflet\Model\MapModel;
/** /**
* The content element for the leaflet map.
*
* @property int leaflet_map * @property int leaflet_map
*/ */
class MapElement extends \ContentElement class MapElement extends \ContentElement
{ {
use ServiceContainerTrait;
use HybridTrait;
/** /**
* Template name. * Template name.
* *
@@ -28,78 +33,10 @@ class MapElement extends \ContentElement
protected $strTemplate = 'ce_leaflet_map'; protected $strTemplate = 'ce_leaflet_map';
/** /**
* @var MapService * {@inheritdoc}
*/
private $mapService;
/**
* Construct.
*
* @param \ContentModel $objElement Content element model.
* @param string $strColumn Layout column.
*/ */
public function __construct($objElement, $strColumn = 'main') public function __construct($objElement, $strColumn = 'main')
{ {
parent::__construct($objElement, $strColumn); $this->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&amp;table=tl_leaflet_map&amp;act=edit&amp;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;
}
} }
} }

View File

@@ -11,12 +11,19 @@
namespace Netzmacht\Contao\Leaflet\Frontend; namespace Netzmacht\Contao\Leaflet\Frontend;
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
use Netzmacht\Contao\Leaflet\MapService; 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 class MapModule extends \Module
{ {
use ServiceContainerTrait;
use HybridTrait;
/** /**
* Template name. * Template name.
* *
@@ -25,77 +32,10 @@ class MapModule extends \Module
protected $strTemplate = 'mod_leaflet_map'; protected $strTemplate = 'mod_leaflet_map';
/** /**
* @var MapService * {@inheritdoc}
*/
private $mapService;
/**
* Construct.
*
* @param \ModuleModel $objElement Module model.
* @param string $strColumn Layout column.
*/ */
public function __construct($objElement, $strColumn = 'main') public function __construct($objElement, $strColumn = 'main')
{ {
parent::__construct($objElement, $strColumn); $this->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&amp;table=tl_leaflet_map&amp;act=edit&amp;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;
}
} }
} }

View File

@@ -25,27 +25,27 @@ class RequestUrl
/** /**
* Create the request url. * 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 $type Object type. If empty it assumes a layer.
* @param string|null $format Data format. If empty it assumes geojson. * @param string|null $format Data format. If empty it assumes geojson.
* *
* @return string * @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. * 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 $type Object type. If empty it assumes a layer.
* @param string|null $format Data format. If empty it assumes geojson. * @param string|null $format Data format. If empty it assumes geojson.
* *
* @return UrlBuilder * @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; $path = \Config::get('websitePath') . '/' . static::BASE;
$builder = new UrlBuilder(); $builder = new UrlBuilder();
@@ -53,7 +53,7 @@ class RequestUrl
->setPath($path) ->setPath($path)
->setQueryParameter('type', $type ?: 'layer') ->setQueryParameter('type', $type ?: 'layer')
->setQueryParameter('format', $format ?: 'geojson') ->setQueryParameter('format', $format ?: 'geojson')
->setQueryParameter('id', $id); ->setQueryParameter('id', $dataId);
return $builder; return $builder;
} }

View File

@@ -44,6 +44,8 @@ class MapService
private $leaflet; private $leaflet;
/** /**
* The event dispatcher.
*
* @var EventDispatcher * @var EventDispatcher
*/ */
private $eventDispatcher; private $eventDispatcher;
@@ -130,6 +132,8 @@ class MapService
* @param LatLngBounds $bounds Filter features in the bounds. * @param LatLngBounds $bounds Filter features in the bounds.
* *
* @return FeatureCollection * @return FeatureCollection
*
* @throws \InvalidArgumentException If a layer could not be found.
*/ */
public function getFeatureCollection($layerId, LatLngBounds $bounds = null) public function getFeatureCollection($layerId, LatLngBounds $bounds = null)
{ {

View File

@@ -190,6 +190,8 @@ abstract class AbstractMapper implements Mapper
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @param LatLngBounds $bounds Optional bounds where elements should be in.
* *
* @return void * @return void
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/ */
protected function build( protected function build(
Definition $definition, Definition $definition,
@@ -230,6 +232,8 @@ abstract class AbstractMapper implements Mapper
* @param string|null $elementId Optional element id. * @param string|null $elementId Optional element id.
* *
* @return array * @return array
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/ */
protected function buildConstructArguments( protected function buildConstructArguments(
\Model $model, \Model $model,
@@ -301,6 +305,8 @@ abstract class AbstractMapper implements Mapper
* @param array $options The options. * @param array $options The options.
* @param Definition $definition The definition being built. * @param Definition $definition The definition being built.
* @param \Model $model The model. * @param \Model $model The model.
*
* @return void
*/ */
protected function applyOptions($options, $definition, $model) protected function applyOptions($options, $definition, $model)
{ {
@@ -312,8 +318,7 @@ abstract class AbstractMapper implements Mapper
if (((bool) $model->$option) !== $default) { if (((bool) $model->$option) !== $default) {
$definition->$setter($model->$mapping); $definition->$setter($model->$mapping);
} }
} } elseif ($model->$mapping !== $default) {
elseif ($model->$mapping !== $default) {
$definition->$setter($model->$mapping); $definition->$setter($model->$mapping);
} }
} }
@@ -351,6 +356,8 @@ abstract class AbstractMapper implements Mapper
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @param LatLngBounds $bounds Optional bounds where elements should be in.
* *
* @return string * @return string
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/ */
protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) protected function getClassName(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{ {

View File

@@ -13,11 +13,23 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 abstract class AbstractTypeMapper extends AbstractMapper
{ {
/**
* The definition type.
*
* @var string
*/
protected static $type; protected static $type;
/**
* {@inheritdoc}
*/
public function match($model, LatLngBounds $bounds = null) public function match($model, LatLngBounds $bounds = null)
{ {
return parent::match($model) && $model->type === static::$type; return parent::match($model) && $model->type === static::$type;

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; 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 class AbstractControlMapper extends AbstractTypeMapper
{ {
/** /**

View File

@@ -11,12 +11,16 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Control; namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\ControlModel; use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 class LayersControlMapper extends AbstractControlMapper
{ {
/** /**

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Control; namespace Netzmacht\Contao\Leaflet\Mapper\Control;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\ControlModel; use Netzmacht\Contao\Leaflet\Model\ControlModel;
use Netzmacht\LeafletPHP\Definition; 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\LoadingControl;
use Netzmacht\LeafletPHP\Plugins\Loading\SpinJsLoadingControl; 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 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. // Only assign if zoom control is activated and part of the map.
$control = ControlModel::findOneBy( $control = ControlModel::findOneBy(
array('active=1', 'type=?', 'pid=?', 'id=?'), array('active=1', 'type=?', 'pid=?', 'id=?'),

View File

@@ -27,9 +27,9 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface as EventDispatche
class DefinitionMapper class DefinitionMapper
{ {
/** /**
* Registered builders. * Lit of all registered mappers.
* *
* @var AbstractMapper[][] * @var Mapper[][]
*/ */
private $builders = array(); private $builders = array();
@@ -41,6 +41,8 @@ class DefinitionMapper
private $eventDispatcher; private $eventDispatcher;
/** /**
* Cache of mapped definitions.
*
* @var array * @var array
*/ */
private $mapped = array(); private $mapped = array();
@@ -79,7 +81,9 @@ class DefinitionMapper
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @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. * @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) public function handle($model, LatLngBounds $bounds = null, $elementId = null)
{ {
@@ -90,7 +94,7 @@ class DefinitionMapper
} }
foreach ($this->builders as $builders) { foreach ($this->builders as $builders) {
foreach($builders as $builder) { foreach ($builders as $builder) {
if ($builder->match($model)) { if ($builder->match($model)) {
$definition = $builder->handle($model, $this, $bounds, $elementId); $definition = $builder->handle($model, $this, $bounds, $elementId);
@@ -121,7 +125,9 @@ class DefinitionMapper
* @param mixed $model The definition model. * @param mixed $model The definition model.
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @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) 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 * @return string
*
* @throws \RuntimeException If no hash was created.
*/ */
protected function getHash($model, $elementId) protected function getHash($model, $elementId)
{ {

View File

@@ -11,16 +11,24 @@
namespace Netzmacht\Contao\Leaflet\Mapper; namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition\GeoJson\GeoJsonFeature;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 interface GeoJsonMapper
{ {
/** /**
* @param \Model $model * Hanle the GeoJSON creation.
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
* *
* @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); public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null);
} }

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; 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 class AbstractLayerMapper extends AbstractTypeMapper
{ {
/** /**
@@ -22,6 +27,9 @@ class AbstractLayerMapper extends AbstractTypeMapper
*/ */
protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel'; protected static $modelClass = 'Netzmacht\Contao\Leaflet\Model\LayerModel';
/**
* {@inheritdoc}
*/
protected function initialize() protected function initialize()
{ {
parent::initialize(); parent::initialize();

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Layer; namespace Netzmacht\Contao\Leaflet\Mapper\Layer;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\LayerModel; use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
@@ -19,6 +18,11 @@ use Netzmacht\LeafletPHP\Definition\Group\LayerGroup;
use Netzmacht\LeafletPHP\Definition\Layer; use Netzmacht\LeafletPHP\Definition\Layer;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 class GroupLayerMapper extends AbstractLayerMapper
{ {
/** /**
@@ -44,7 +48,7 @@ class GroupLayerMapper extends AbstractLayerMapper
return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup'; return 'Netzmacht\LeafletPHP\Definition\Group\FeatureGroup';
} }
return parent::getClassName($model, $mapper, $bounds); // TODO: Change the autogenerated stub return parent::getClassName($model, $mapper, $bounds);
} }
/** /**

View File

@@ -24,6 +24,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker; use Netzmacht\LeafletPHP\Definition\UI\Marker;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax; 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 class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{ {
/** /**
@@ -81,11 +86,7 @@ class MarkersLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
} }
/** /**
* @param \Model $model * {@inheritdoc}
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/ */
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) 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 * @return \Model\Collection|null
*/ */
protected function loadMarkerModels(\Model $model) protected function loadMarkerModels(\Model $model)
{ {
$collection = MarkerModel::findBy( return MarkerModel::findActiveBy('pid', $model->id, array('order' => 'sorting'));
array('active=1', 'pid=?'),
array($model->id),
array('order' => 'sorting')
);
return $collection;
} }
} }

View File

@@ -15,6 +15,11 @@ use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 class ProviderLayerMapper extends AbstractLayerMapper
{ {
/** /**

View File

@@ -16,7 +16,7 @@ use Netzmacht\Contao\Leaflet\Model\LayerModel;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 * @package Netzmacht\Contao\Leaflet\Mapper\Layer
*/ */

View File

@@ -26,6 +26,11 @@ use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector; use Netzmacht\LeafletPHP\Definition\Vector;
use Netzmacht\LeafletPHP\Plugins\Ajax\GeoJsonAjax; 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 class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
{ {
/** /**
@@ -87,11 +92,7 @@ class VectorsLayerMapper extends AbstractLayerMapper implements GeoJsonMapper
} }
/** /**
* @param \Model $model * {@inheritdoc}
* @param DefinitionMapper $mapper
* @param LatLngBounds $bounds
*
* @return mixed
*/ */
public function handleGeoJson(\Model $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) 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 * @return \Model\Collection|null
*/ */
protected function loadVectorModels(\Model $model) protected function loadVectorModels(\Model $model)
{ {
$collection = VectorModel::findBy( return VectorModel::findActiveBy('pid', $model->id, array('order' => 'sorting'));
array('active=1', 'pid=?'),
array($model->id),
array('order' => 'sorting')
);
return $collection;
} }
} }

View File

@@ -20,7 +20,11 @@ use Netzmacht\LeafletPHP\Definition\Layer;
use Netzmacht\LeafletPHP\Definition\Map; use Netzmacht\LeafletPHP\Definition\Map;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 class MapMapper extends AbstractMapper
{ {
/** /**
@@ -38,7 +42,7 @@ class MapMapper extends AbstractMapper
protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Map'; protected static $definitionClass = 'Netzmacht\LeafletPHP\Definition\Map';
/** /**
* @inheritdoc * {@inheritdoc}
*/ */
protected function initialize() 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) 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( protected function buildConstructArguments(
\Model $model, \Model $model,
@@ -99,6 +103,8 @@ class MapMapper extends AbstractMapper
* @param MapModel $model The map model. * @param MapModel $model The map model.
* @param DefinitionMapper $mapper The definition mapper. * @param DefinitionMapper $mapper The definition mapper.
* @param LatLngBounds $bounds Optional bounds. * @param LatLngBounds $bounds Optional bounds.
*
* @return void
*/ */
private function buildControls(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) 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 MapModel $model The map model.
* @param DefinitionMapper $mapper Definition mapper. * @param DefinitionMapper $mapper Definition mapper.
* @param LatLngBounds $bounds Optional bounds. * @param LatLngBounds $bounds Optional bounds.
*
* @return void
*/ */
private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null) private function buildLayers(Map $map, MapModel $model, DefinitionMapper $mapper, LatLngBounds $bounds = null)
{ {

View File

@@ -14,12 +14,17 @@ namespace Netzmacht\Contao\Leaflet\Mapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 interface Mapper
{ {
/** /**
* Map model to the definition. * 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 DefinitionMapper $mapper The definition builder.
* @param LatLngBounds $bounds Optional bounds where elements should be in. * @param LatLngBounds $bounds Optional bounds where elements should be in.
* @param string $elementId Optional element id. * @param string $elementId Optional element id.

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Style;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; 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 abstract class AbstractStyleMapper extends AbstractTypeMapper
{ {
/** /**

View File

@@ -13,6 +13,11 @@ namespace Netzmacht\Contao\Leaflet\Mapper\Style;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
/**
* Class FixedStyleMapper maps the fixed style to the corresponding definition.
*
* @package Netzmacht\Contao\Leaflet\Mapper\Style
*/
class FixedStyleMapper extends AbstractStyleMapper class FixedStyleMapper extends AbstractStyleMapper
{ {
/** /**

View File

@@ -11,9 +11,13 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type; namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; 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 class AbstractIconMapper extends AbstractTypeMapper
{ {
/** /**

View File

@@ -11,12 +11,16 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type; namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\DivIcon; use Netzmacht\LeafletPHP\Definition\Type\DivIcon;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 class DivIconMapper extends AbstractIconMapper
{ {
/** /**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Type; namespace Netzmacht\Contao\Leaflet\Mapper\Type;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\IconModel; use Netzmacht\Contao\Leaflet\Model\IconModel;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\ImageIcon; use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; 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 class ImageIconMapper extends AbstractIconMapper
{ {
/** /**

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\UI; namespace Netzmacht\Contao\Leaflet\Mapper\UI;
use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper; use Netzmacht\Contao\Leaflet\Mapper\AbstractMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\Contao\Leaflet\Model\IconModel; 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\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\UI\Marker; 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 class MarkerMapper extends AbstractMapper
{ {
/** /**

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Definition\Style; use Netzmacht\Contao\Leaflet\Definition\Style;
use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper; use Netzmacht\Contao\Leaflet\Mapper\AbstractTypeMapper;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; 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\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Path; 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 class AbstractVectorMapper extends AbstractTypeMapper
{ {
/** /**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle; 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 class CircleMapper extends AbstractVectorMapper
{ {
/** /**
@@ -34,6 +38,9 @@ class CircleMapper extends AbstractVectorMapper
*/ */
protected static $type = 'circle'; protected static $type = 'circle';
/**
* {@inheritdoc}
*/
protected function initialize() protected function initialize()
{ {
parent::initialize(); parent::initialize();
@@ -41,6 +48,9 @@ class CircleMapper extends AbstractVectorMapper
$this->addOption('radius'); $this->addOption('radius');
} }
/**
* {@inheritdoc}
*/
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Circle; 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 class CircleMarkerMapper extends CircleMapper
{ {
/** /**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\MultiPolygon; 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 class MultiPolygonMapper extends MultiPolylineMapper
{ {
/** /**
@@ -34,6 +38,9 @@ class MultiPolygonMapper extends MultiPolylineMapper
*/ */
protected static $type = 'multiPolygon'; protected static $type = 'multiPolygon';
/**
* {@inheritdoc}
*/
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
@@ -43,18 +50,7 @@ class MultiPolygonMapper extends MultiPolylineMapper
parent::build($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolygon) { if ($definition instanceof MultiPolygon) {
$latLngs = array(); $this->createLatLngs($definition, $model);
foreach (deserialize($model->multiData, true) as $data) {
$latLngs[] = array_map(
function ($row) {
return LatLng::fromString($row);
},
explode("\n", $data)
);
}
$definition->setLatLngs($latLngs);
} }
} }
} }

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; 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\MultiPolyline;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline; 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 class MultiPolylineMapper extends AbstractVectorMapper
{ {
/** /**
@@ -35,7 +39,9 @@ class MultiPolylineMapper extends AbstractVectorMapper
*/ */
protected static $type = 'multiPolyline'; protected static $type = 'multiPolyline';
/**
* {@inheritdoc}
*/
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,
@@ -45,6 +51,20 @@ class MultiPolylineMapper extends AbstractVectorMapper
parent::build($definition, $model, $builder, $bounds); parent::build($definition, $model, $builder, $bounds);
if ($definition instanceof MultiPolyline) { if ($definition instanceof MultiPolyline) {
$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(); $latLngs = array();
foreach (deserialize($model->multiData, true) as $data) { foreach (deserialize($model->multiData, true) as $data) {
@@ -58,5 +78,4 @@ class MultiPolylineMapper extends AbstractVectorMapper
$definition->setLatLngs($latLngs); $definition->setLatLngs($latLngs);
} }
}
} }

View File

@@ -11,6 +11,11 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; 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 class PolygonMapper extends PolylineMapper
{ {
/** /**

View File

@@ -11,13 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; use Netzmacht\LeafletPHP\Definition\Type\LatLng;
use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds; use Netzmacht\LeafletPHP\Definition\Type\LatLngBounds;
use Netzmacht\LeafletPHP\Definition\Vector\Polyline; 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 class PolylineMapper extends AbstractVectorMapper
{ {
/** /**
@@ -34,7 +38,9 @@ class PolylineMapper extends AbstractVectorMapper
*/ */
protected static $type = 'polyline'; protected static $type = 'polyline';
/**
* {@inheritdoc}
*/
protected function build( protected function build(
Definition $definition, Definition $definition,
\Model $model, \Model $model,

View File

@@ -11,7 +11,6 @@
namespace Netzmacht\Contao\Leaflet\Mapper\Vector; namespace Netzmacht\Contao\Leaflet\Mapper\Vector;
use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper; use Netzmacht\Contao\Leaflet\Mapper\DefinitionMapper;
use Netzmacht\LeafletPHP\Definition; use Netzmacht\LeafletPHP\Definition;
use Netzmacht\LeafletPHP\Definition\Type\LatLng; 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\Circle;
use Netzmacht\LeafletPHP\Definition\Vector\Rectangle; 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 class RectangleMapper extends AbstractVectorMapper
{ {
/** /**
@@ -35,11 +39,9 @@ class RectangleMapper extends AbstractVectorMapper
*/ */
protected static $type = 'rectangle'; protected static $type = 'rectangle';
protected function initialize() /**
{ * {@inheritdoc}
parent::initialize(); */
}
protected function buildConstructArguments( protected function buildConstructArguments(
\Model $model, \Model $model,
DefinitionMapper $mapper, DefinitionMapper $mapper,
@@ -47,7 +49,7 @@ class RectangleMapper extends AbstractVectorMapper
$elementId = null $elementId = null
) { ) {
$latLngs = array_map( $latLngs = array_map(
function($latLng) { function ($latLng) {
return LatLng::fromString($latLng); return LatLng::fromString($latLng);
}, },
deserialize($model->bounds, true) deserialize($model->bounds, true)

View File

@@ -11,13 +11,18 @@
namespace Netzmacht\Contao\Leaflet\Model; 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 abstract class AbstractActiveModel extends \Model
{ {
/** /**
* Find an active model by its model id.
* *
* @param int $modelId * @param int $modelId The model id.
* @param array $options * @param array $options The query options.
* *
* @return \Model|null * @return \Model|null
*/ */
@@ -27,18 +32,33 @@ abstract class AbstractActiveModel extends \Model
} }
/** /**
* Find active models by a defined column.
* *
* @param int $value * @param string|array $column The query columns.
* @param array $options * @param mixed $value The column value.
* @param array $options The options.
* *
* @return \Model|null * @return \Model|null
*/ */
public static function findActiveBy($column, $value, $options = array()) 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;
} }
public static function findActivated($options = array()) return static::findBy($column, $value, $options);
}
/**
* 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); return static::findBy('active', '1', $options);
} }

View File

@@ -11,33 +11,70 @@
namespace Netzmacht\Contao\Leaflet\Model; 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 class ControlModel extends AbstractActiveModel
{ {
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_control'; protected static $strTable = 'tl_leaflet_control';
/** /**
* @return \Model\Collection * Find all related layers.
*
* @return Collection|null
*/ */
public function findLayers() 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() $result = \Database::getInstance()
->prepare($query) ->prepare($query)
->execute($this->id); ->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() 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() $result = \Database::getInstance()
->prepare($query) ->prepare($query)
->execute($this->id); ->execute($this->id);
return \Model\Collection::createFromDbResult($result, 'tl_leaflet_layer'); if ($result->numRows < 1) {
return null;
}
return Collection::createFromDbResult($result, 'tl_leaflet_layer');
} }
} }

View File

@@ -11,8 +11,9 @@
namespace Netzmacht\Contao\Leaflet\Model; namespace Netzmacht\Contao\Leaflet\Model;
/** /**
* IconModel class for the tl_leaflet_icon table.
*
* @property mixed|null iconImage * @property mixed|null iconImage
* @property mixed|null iconAnchor * @property mixed|null iconAnchor
* @property mixed|null popupAnchor * @property mixed|null popupAnchor
@@ -23,5 +24,10 @@ namespace Netzmacht\Contao\Leaflet\Model;
*/ */
class IconModel extends AbstractActiveModel class IconModel extends AbstractActiveModel
{ {
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_icon'; protected static $strTable = 'tl_leaflet_icon';
} }

View File

@@ -11,11 +11,30 @@
namespace Netzmacht\Contao\Leaflet\Model; 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 class LayerModel extends AbstractActiveModel
{ {
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_layer'; 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()) public static function findMultipleByTypes(array $types, $options = array())
{ {
if (empty($types)) { if (empty($types)) {
@@ -30,6 +49,7 @@ class LayerModel extends AbstractActiveModel
); );
$options['value'] = $types; $options['value'] = $types;
$options['return'] = 'Collection';
return static::find($options); return static::find($options);
} }

View File

@@ -11,13 +11,26 @@
namespace Netzmacht\Contao\Leaflet\Model; 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 class MapModel extends \Model
{ {
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_map'; protected static $strTable = 'tl_leaflet_map';
/** /**
* @return \Model\Collection * Find all related layers.
*
* @return Collection|null
*/ */
public function findLayers() public function findLayers()
{ {
@@ -26,19 +39,34 @@ class MapModel extends \Model
->prepare($query) ->prepare($query)
->execute($this->id); ->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() 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'; $query = <<<SQL
$result = \Database::getInstance() SELECT l.*
->prepare($query) FROM tl_leaflet_layer l
->execute($this->id); 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;
} }
} }

View File

@@ -11,9 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Model; namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class MarkerModel for the tl_leaflet_marker table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class MarkerModel extends AbstractActiveModel class MarkerModel extends AbstractActiveModel
{ {
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_marker'; protected static $strTable = 'tl_leaflet_marker';
} }

View File

@@ -11,8 +11,17 @@
namespace Netzmacht\Contao\Leaflet\Model; namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class StyleModel for the tl_leaflet_style table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class StyleModel extends AbstractActiveModel class StyleModel extends AbstractActiveModel
{ {
/**
* Model table.
*
* @var string
*/
protected static $strTable = 'tl_leaflet_style'; protected static $strTable = 'tl_leaflet_style';
} }

View File

@@ -11,7 +11,11 @@
namespace Netzmacht\Contao\Leaflet\Model; namespace Netzmacht\Contao\Leaflet\Model;
/**
* Class VectorModel for the tl_leaflet_vector table.
*
* @package Netzmacht\Contao\Leaflet\Model
*/
class VectorModel extends AbstractActiveModel class VectorModel extends AbstractActiveModel
{ {
/** /**

View File

@@ -23,7 +23,7 @@ use Netzmacht\LeafletPHP\Definition\Type\ImageIcon;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; use Symfony\Component\EventDispatcher\EventSubscriberInterface;
/** /**
* Class BootSubscriber * Class BootSubscriber provides handlers for leaflet boot process.
* *
* @package Netzmacht\Contao\Leaflet\Subscriber * @package Netzmacht\Contao\Leaflet\Subscriber
*/ */
@@ -111,6 +111,8 @@ class BootSubscriber implements EventSubscriberInterface
* Load Contao leaflet assets. * Load Contao leaflet assets.
* *
* @return void * @return void
*
* @SuppressWarnings(PHPMD.Superglobals)
*/ */
public function loadAssets() public function loadAssets()
{ {
@@ -123,7 +125,9 @@ class BootSubscriber implements EventSubscriberInterface
/** /**
* Load icons. * Load icons.
* *
* @throws \Netzmacht\Javascript\Exception\EncodeValueFailed * @return void
*
* @SuppressWarnings(PHPMD.Superglobals)
*/ */
public function loadIcons() public function loadIcons()
{ {
@@ -153,7 +157,9 @@ class BootSubscriber implements EventSubscriberInterface
$file->write($buffer); $file->write($buffer);
$file->close(); $file->close();
// @codingStandardsIgnoreStart
// TODO: Cache it. // TODO: Cache it.
// codingStandardsIgnoreEnd
$GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/js/icons.js' . (\Config::get('debugMode') $GLOBALS['TL_JAVASCRIPT'][] = 'assets/leaflet/js/icons.js' . (\Config::get('debugMode')
? '' ? ''
: '|static' : '|static'

View File

@@ -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) public function encodeIcons(EncodeValueEvent $event)
{ {
$value = $event->getValue(); $value = $event->getValue();

View File

@@ -11,10 +11,14 @@
namespace Netzmacht\Contao\Leaflet\Subscriber; namespace Netzmacht\Contao\Leaflet\Subscriber;
use Netzmacht\Contao\Leaflet\Event\GetHashEvent; use Netzmacht\Contao\Leaflet\Event\GetHashEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface; 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 class HashSubscriber implements EventSubscriberInterface
{ {
/** /**
@@ -33,7 +37,9 @@ class HashSubscriber implements EventSubscriberInterface
/** /**
* Get hash for a model object. * Get hash for a model object.
* *
* @param GetHashEvent $event * @param GetHashEvent $event The subscribed event.
*
* @return void
*/ */
public function getModelHash(GetHashEvent $event) public function getModelHash(GetHashEvent $event)
{ {
@@ -47,7 +53,9 @@ class HashSubscriber implements EventSubscriberInterface
/** /**
* Get hash fallback if no hash was created so far. * 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) public function getFallback(GetHashEvent $event)
{ {