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
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Class RequestUrl creates the request url.
|
|
|
|
|
*
|
|
|
|
|
* @package Netzmacht\Contao\Leaflet\Request
|
|
|
|
|
*/
|
2015-01-15 12:45:23 +01:00
|
|
|
class RequestUrl implements \JsonSerializable
|
2015-01-07 09:38:05 +01:00
|
|
|
{
|
2015-01-15 12:45:23 +01:00
|
|
|
/**
|
|
|
|
|
* The for param is the identifier to the responsible frontend module or content element.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2015-01-14 17:50:23 +01:00
|
|
|
private static $for;
|
|
|
|
|
|
2015-01-15 12:45:23 +01:00
|
|
|
/**
|
|
|
|
|
* The leaflet hash.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $hash;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* The request url as url path.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
private $url;
|
2015-01-07 09:38:05 +01:00
|
|
|
|
|
|
|
|
/**
|
2015-01-14 17:50:23 +01:00
|
|
|
* Create the request url.
|
2015-01-07 09:38:05 +01:00
|
|
|
*
|
2015-01-15 12:45:23 +01:00
|
|
|
* It combines the params and creates an hash for it.
|
|
|
|
|
*
|
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.
|
|
|
|
|
*
|
2015-01-15 12:45:23 +01:00
|
|
|
* @return RequestUrl
|
2015-01-12 23:22:19 +01:00
|
|
|
*/
|
2015-01-14 17:50:23 +01:00
|
|
|
public static function create($dataId, $type = null, $format = null)
|
2015-01-12 23:22:19 +01:00
|
|
|
{
|
2015-01-14 17:50:23 +01:00
|
|
|
$params = array(
|
|
|
|
|
'for' => static::$for,
|
|
|
|
|
'type' => $type != 'layer' ? $type : null,
|
|
|
|
|
'id' => $dataId,
|
2015-01-15 15:30:16 +01:00
|
|
|
'format' => $format != 'geojson' ? $format : null
|
2015-01-14 17:50:23 +01:00
|
|
|
);
|
2015-01-12 23:22:19 +01:00
|
|
|
|
2015-01-15 12:45:23 +01:00
|
|
|
$hash = base64_encode(implode(',', $params));
|
|
|
|
|
$url = \Config::get('websitePath') . '/' . \Frontend::addToUrl('leaflet=' . $hash, false);
|
|
|
|
|
|
|
|
|
|
return new static($url, $hash);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Set the for param.
|
|
|
|
|
*
|
2015-01-15 15:30:16 +01:00
|
|
|
* @param string $for The identifier which has the responsibility listen to the request.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
2015-01-15 12:45:23 +01:00
|
|
|
*/
|
|
|
|
|
public static function setFor($for)
|
|
|
|
|
{
|
|
|
|
|
static::$for = $for;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Construct.
|
|
|
|
|
*
|
|
|
|
|
* @param string $url The request url.
|
|
|
|
|
* @param string $hash The leaflet hash.
|
|
|
|
|
*/
|
|
|
|
|
public function __construct($url, $hash)
|
|
|
|
|
{
|
|
|
|
|
$this->url = $url;
|
|
|
|
|
$this->hash = $hash;
|
|
|
|
|
}
|
2015-01-12 23:22:19 +01:00
|
|
|
|
2015-01-15 12:45:23 +01:00
|
|
|
/**
|
|
|
|
|
* Get the leaflet url hash.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getHash()
|
|
|
|
|
{
|
|
|
|
|
return $this->hash;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Get the whole url.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function getUrl()
|
|
|
|
|
{
|
2015-01-15 15:30:16 +01:00
|
|
|
return $this->url;
|
2015-01-15 12:45:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Convert to string will always return the whole url.
|
|
|
|
|
*
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
public function __toString()
|
|
|
|
|
{
|
|
|
|
|
return $this->getUrl();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* {@inheritdoc}
|
|
|
|
|
*/
|
2015-01-15 15:30:16 +01:00
|
|
|
public function jsonSerialize()
|
2015-01-15 12:45:23 +01:00
|
|
|
{
|
|
|
|
|
return $this->getUrl();
|
2015-01-12 23:22:19 +01:00
|
|
|
}
|
2015-01-07 09:38:05 +01:00
|
|
|
}
|