Code style.

This commit is contained in:
David Molineus
2015-01-15 15:30:16 +01:00
parent 2a7d95b37a
commit 04c0c75e14
9 changed files with 82 additions and 29 deletions

View File

@@ -65,9 +65,8 @@ class DataController
$this->encodeData($this->input['format'], $data);
} catch (\Exception $e) {
if (\Config::get('debugMode') || \Config::get('displayErrors')) {
throw $e;
}
throw $e;
$error = true;
}

View File

@@ -47,18 +47,10 @@ class Hooks
return false;
}
$mapService = $this->getMapService();
$style = empty($parts[2]) ? 'width:400px;height:300px' : $parts[2];
$template = empty($parts[3]) ? 'leaflet_map_html' : $parts[3];
$style = empty($parts[2]) ? 'width:400px;height:300px' : $parts[2];
$template = empty($parts[3]) ? 'leaflet_map_html' : $parts[3];
try {
return $mapService->generate($parts[1], null, $parts[1], $template, $style);
} catch (\Exception $e) {
if (static::getService('config')->get('debugMode')) {
throw $e;
}
return false;
}
return $this->generateMap($parts[1], $template, $style);
}
/**
@@ -70,4 +62,30 @@ class Hooks
{
return static::getService('leaflet.map.service');
}
/**
* Generate the map.
*
* @param string|int $mapId The map id/alias.
* @param string $template The template.
* @param string $style Optional style attribute.
*
* @return bool|string
*
* @throws \Exception If debug mode is enabled and something went wrong.
*/
private function generateMap($mapId, $template, $style)
{
try {
$mapService = $this->getMapService();
return $mapService->generate($mapId, null, $mapId, $template, $style);
} catch (\Exception $e) {
if (static::getService('config')->get('debugMode')) {
throw $e;
}
return false;
}
}
}

View File

@@ -94,7 +94,7 @@ trait HybridTrait
*
* @return void
*
* @throws \Exception If something went wrong.
* @throws \Exception If the map could not be created.
*
* @SuppressWarnings(PHPMD.Superglobals)
*/
@@ -102,7 +102,7 @@ trait HybridTrait
{
try {
RequestUrl::setFor($this->getIdentifier());
$mapId = 'map_' . ($this->cssID[0] ?: ('ce_' . $this->id));
$mapId = 'map_' . ($this->cssID[0] ?: ($this->getIdentifier()));
$map = $this->mapService->generate($this->leaflet_map, null, $mapId);
RequestUrl::setFor(null);
@@ -131,7 +131,10 @@ trait HybridTrait
/**
* Handle ajax request if leaflet parameter is given.
*
* @throws \Exception
* @return void
*
* @throws \HttpRequestException If a bad leaflet param hash is given.
* @SuppressWarnings(ExitExpression)
*/
private function handleAjaxRequest()
{
@@ -139,7 +142,12 @@ trait HybridTrait
// Handle ajax request.
if ($input) {
$data = (array) explode(',', base64_decode($input));
$data = explode(',', base64_decode($input));
if (count($data) != 4) {
throw new \HttpRequestException('Bad request. Could not resolve query params');
}
$data = array_combine(array('for', 'type', 'id', 'format'), $data);
$data = array_filter($data);

View File

@@ -40,6 +40,11 @@ class MapElement extends \ContentElement
$this->construct($objElement, $strColumn);
}
/**
* Get the identifier.
*
* @return string
*/
protected function getIdentifier()
{
return 'ce_' . $this->id;

View File

@@ -39,6 +39,11 @@ class MapModule extends \Module
$this->construct($objElement, $strColumn);
}
/**
* Get the identifier.
*
* @return string
*/
protected function getIdentifier()
{
return 'mod_' . $this->id;

View File

@@ -56,7 +56,7 @@ class RequestUrl implements \JsonSerializable
'for' => static::$for,
'type' => $type != 'layer' ? $type : null,
'id' => $dataId,
'format' => $format != 'geojson' ? $format: null
'format' => $format != 'geojson' ? $format : null
);
$hash = base64_encode(implode(',', $params));
@@ -68,7 +68,9 @@ class RequestUrl implements \JsonSerializable
/**
* Set the for param.
*
* @param $for
* @param string $for The identifier which has the responsibility listen to the request.
*
* @return void
*/
public static function setFor($for)
{
@@ -104,7 +106,7 @@ class RequestUrl implements \JsonSerializable
*/
public function getUrl()
{
return ;
return $this->url;
}
/**
@@ -120,7 +122,7 @@ class RequestUrl implements \JsonSerializable
/**
* {@inheritdoc}
*/
function jsonSerialize()
public function jsonSerialize()
{
return $this->getUrl();
}