2015-01-07 09:38:05 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @package dev
|
|
|
|
|
* @author David Molineus <david.molineus@netzmacht.de>
|
|
|
|
|
* @copyright 2015 netzmacht creative David Molineus
|
|
|
|
|
* @license LGPL 3.0
|
|
|
|
|
* @filesource
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2015-01-10 15:33:46 +01:00
|
|
|
namespace Netzmacht\Contao\Leaflet\Frontend;
|
2015-01-07 09:38:05 +01:00
|
|
|
|
|
|
|
|
use ContaoCommunityAlliance\UrlBuilder\UrlBuilder;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class RequestUrl creates the request url.
|
|
|
|
|
*
|
|
|
|
|
* @package Netzmacht\Contao\Leaflet\Request
|
|
|
|
|
*/
|
|
|
|
|
class RequestUrl
|
|
|
|
|
{
|
2015-01-10 13:12:47 +01:00
|
|
|
const BASE = 'assets/leaflet/maps/data.php';
|
2015-01-07 09:38:05 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create the request url.
|
|
|
|
|
*
|
2015-01-12 19:03:29 +01:00
|
|
|
* @param int $dataId The data object id.
|
2015-01-07 09:38:05 +01:00
|
|
|
* @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
|
|
|
|
|
*/
|
2015-01-12 19:03:29 +01:00
|
|
|
public static function create($dataId, $type = null, $format = null)
|
2015-01-07 09:38:05 +01:00
|
|
|
{
|
2015-01-12 19:03:29 +01:00
|
|
|
return self::createBuilder($dataId, $type, $format)->getUrl();
|
2015-01-07 09:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Create the request builder.
|
|
|
|
|
*
|
2015-01-12 19:03:29 +01:00
|
|
|
* @param int $dataId The data object id.
|
2015-01-07 09:38:05 +01:00
|
|
|
* @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
|
|
|
|
|
*/
|
2015-01-12 19:03:29 +01:00
|
|
|
public static function createBuilder($dataId, $type = null, $format = null)
|
2015-01-07 09:38:05 +01:00
|
|
|
{
|
|
|
|
|
$path = \Config::get('websitePath') . '/' . static::BASE;
|
|
|
|
|
$builder = new UrlBuilder();
|
|
|
|
|
$builder
|
|
|
|
|
->setPath($path)
|
|
|
|
|
->setQueryParameter('type', $type ?: 'layer')
|
|
|
|
|
->setQueryParameter('format', $format ?: 'geojson')
|
2015-01-12 23:22:19 +01:00
|
|
|
->setQueryParameter('id', $dataId)
|
|
|
|
|
->setQueryParameter('page', rawurlencode(base64_encode(self::getRequestUri())));
|
2015-01-07 09:38:05 +01:00
|
|
|
|
|
|
|
|
return $builder;
|
|
|
|
|
}
|
2015-01-12 23:22:19 +01:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the request uri without leading slash.
|
|
|
|
|
*
|
|
|
|
|
* @return mixed
|
|
|
|
|
*/
|
|
|
|
|
protected static function getRequestUri()
|
|
|
|
|
{
|
|
|
|
|
$uri = \Environment::get('requestUri');
|
|
|
|
|
|
|
|
|
|
if (strpos($uri, '/') === 0) {
|
|
|
|
|
return substr($uri, 1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $uri;
|
|
|
|
|
}
|
2015-01-07 09:38:05 +01:00
|
|
|
}
|