* Fertigstellung Buchungsformular (#1321) (SternTours-CRM-API-Anbindung, Mailversand, Validierung, Dynamische Preisberechnung, Persistierung von Buchungsinformationen)

* Fehler bei der Preisberechnung behoben
* Farbschema geändert (Kevin Adametz)

git-svn-id: http://78.47.251.156/svn/dev/sterntours-3@3289 f459cee4-fb09-11de-96c3-f9c5f16c3c76
This commit is contained in:
uli 2017-02-14 11:26:49 +00:00
parent dde3b91724
commit 3a28866cd2
36 changed files with 2200 additions and 268 deletions

View file

@ -35,6 +35,108 @@ class Util
$prop->setValue($entity, $collection);
}
public static function formatPrice($value)
{
return number_format($value, 2, ',', '.') .' €';
}
static function httpRequest($url, $method = "GET", $data = "", $headers = array(), $withRespHeaders = false,
$cookieJar = null)
{
global $kernel;
$ch = curl_init();
$headerList = array();
//self::buildHttpQueryForCurl($headers, $headerList); //?
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_HEADER, $withRespHeaders);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if (isset($cookieJar))
{
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookieJar);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookieJar);
}
if (strtoupper($method) == 'POST')
{
$dataStr = is_array($data) ? http_build_query($data) : $data;
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $dataStr);
}
$response = curl_exec($ch);
$ret = [
'info' => curl_getinfo($ch),
'success' => true,
'status_code' => curl_getinfo($ch, CURLINFO_HTTP_CODE)
];
if ($withRespHeaders)
{
$respArray = explode("\r\n\r\n", $response);
$ret['response_headers'] = [];
// count() - 2 due to HTTP status 100 (continue) with multiple responses
$headers = is_array($respArray) && isset($respArray[count($respArray) - 2])
? explode("\r\n", $respArray[count($respArray) - 2])
: [];
// HTTP/1.1 200 OK
array_shift($headers);
foreach ($headers as $header)
{
$headerKV = explode(': ', $header);
$key = strtolower($headerKV[0]);
if (isset($ret['response_headers'][$key]))
{
if (is_array($ret['response_headers'][$key]))
{
$ret['response_headers'][$key][] = $headerKV[1];
}
else
{
$ret['response_headers'][$key] = array($ret['response_headers'][$key], $headerKV[1]);
}
}
else
{
$ret['response_headers'][$key] = $headerKV[1];
}
}
$ret['content'] = $respArray[count($respArray) - 1];
}
else
{
$ret['content'] = $response;
}
if (curl_errno($ch) > 0)
{
$ret['info']['curl_errno'] = curl_errno($ch);
$ret['success'] = false;
}
if (isset($kernel))
{
$logger = $kernel->getContainer()->get('logger');
$logger->warn('HTTP request to \''. $url .'\' with server response code '. $ret['status_code']);
}
curl_close($ch);
return $ret;
}
static function httpPost($url, $postData = '', $headers = array(), $withRespHeaders = true, $cookieJarPath = null)
{
return self::httpRequest($url, 'POST', $postData, $headers, $withRespHeaders, $cookieJarPath);
}
static function httpGet($url, $headers = array(), $withRespHeaders = false, $cookieJarPath = null)
{
return self::httpRequest($url, 'GET', '', $headers, $withRespHeaders, $cookieJarPath);
}
/**
* Prints formatted back-trace. CLI-output is colorized as well.
*