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

@@ -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);

View File

@@ -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&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"',
$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"'
)
);
}

View File

@@ -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
*/

View File

@@ -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();

View File

@@ -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))

View File

@@ -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();
}
}

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;
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']);