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

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;
use ContentElement;
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
use Netzmacht\Contao\Leaflet\MapService;
use Netzmacht\Contao\Leaflet\Model\MapModel;
/**
* The content element for the leaflet map.
*
* @property int leaflet_map
*/
class MapElement extends \ContentElement
{
use ServiceContainerTrait;
use HybridTrait;
/**
* Template name.
*
@@ -28,78 +33,10 @@ class MapElement extends \ContentElement
protected $strTemplate = 'ce_leaflet_map';
/**
* @var MapService
*/
private $mapService;
/**
* Construct.
*
* @param \ContentModel $objElement Content element model.
* @param string $strColumn Layout column.
* {@inheritdoc}
*/
public function __construct($objElement, $strColumn = 'main')
{
parent::__construct($objElement, $strColumn);
$this->mapService = $GLOBALS['container']['leaflet.map.service'];
}
public function generate()
{
if (TL_MODE === 'BE') {
$model = MapModel::findByPK($this->leaflet_map);
$template = new \BackendTemplate('be_wildcard');
if ($model) {
$href = 'contao/main.php?do=leaflet&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;
}
$this->construct($objElement, $strColumn);
}
}

View File

@@ -11,12 +11,19 @@
namespace Netzmacht\Contao\Leaflet\Frontend;
use Netzmacht\Contao\DevTools\ServiceContainerTrait;
use Netzmacht\Contao\Leaflet\MapService;
use Netzmacht\Contao\Leaflet\Model\MapModel;
/**
* The frontend module for the Leaflet map.
*
* @package Netzmacht\Contao\Leaflet\Frontend
*/
class MapModule extends \Module
{
use ServiceContainerTrait;
use HybridTrait;
/**
* Template name.
*
@@ -25,77 +32,10 @@ class MapModule extends \Module
protected $strTemplate = 'mod_leaflet_map';
/**
* @var MapService
*/
private $mapService;
/**
* Construct.
*
* @param \ModuleModel $objElement Module model.
* @param string $strColumn Layout column.
* {@inheritdoc}
*/
public function __construct($objElement, $strColumn = 'main')
{
parent::__construct($objElement, $strColumn);
$this->mapService = $GLOBALS['container']['leaflet.map.service'];
}
public function generate()
{
if (TL_MODE === 'BE') {
$model = MapModel::findByPK($this->leaflet_map);
$template = new \BackendTemplate('be_wildcard');
if ($model) {
$href = 'contao/main.php?do=leaflet&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;
}
$this->construct($objElement, $strColumn);
}
}

View File

@@ -25,27 +25,27 @@ class RequestUrl
/**
* Create the request url.
*
* @param int $id Object id.
* @param int $dataId The data object id.
* @param string|null $type Object type. If empty it assumes a layer.
* @param string|null $format Data format. If empty it assumes geojson.
*
* @return string
*/
public static function create($id, $type = null, $format = null)
public static function create($dataId, $type = null, $format = null)
{
return self::createBuilder($id, $type, $format)->getUrl();
return self::createBuilder($dataId, $type, $format)->getUrl();
}
/**
* Create the request builder.
*
* @param int $id Object id.
* @param int $dataId The data object id.
* @param string|null $type Object type. If empty it assumes a layer.
* @param string|null $format Data format. If empty it assumes geojson.
*
* @return UrlBuilder
*/
public static function createBuilder($id, $type = null, $format = null)
public static function createBuilder($dataId, $type = null, $format = null)
{
$path = \Config::get('websitePath') . '/' . static::BASE;
$builder = new UrlBuilder();
@@ -53,7 +53,7 @@ class RequestUrl
->setPath($path)
->setQueryParameter('type', $type ?: 'layer')
->setQueryParameter('format', $format ?: 'geojson')
->setQueryParameter('id', $id);
->setQueryParameter('id', $dataId);
return $builder;
}