Korrektes JSON zurückgeben

This commit is contained in:
Carsten Götzinger 2018-02-15 06:27:02 +01:00
parent 1ab4a1c6de
commit 01dc5be820

View File

@ -87,7 +87,7 @@ class RateIt extends \Frontend {
foreach ($arrRkey as $key) { foreach ($arrRkey as $key) {
if (!is_numeric($key)) { if (!is_numeric($key)) {
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']]; $return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
return new JsonResponse($return); return new JsonResponse(array('result' => 'error', 'data' => $return));
} }
$id = $rkey; $id = $rkey;
} }
@ -96,7 +96,7 @@ class RateIt extends \Frontend {
$id = $rkey; $id = $rkey;
} else { } else {
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']]; $return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
return new JsonResponse($return); return new JsonResponse(array('result' => 'error', 'data' => $return));
} }
} }
@ -105,13 +105,13 @@ class RateIt extends \Frontend {
$rating = $percent; $rating = $percent;
} else { } else {
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']]; $return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
return new JsonResponse($return); return new JsonResponse(array('result' => 'error', 'data' => $return));
} }
//Make sure that the ratable type is 'page' or 'ce' or 'module' //Make sure that the ratable type is 'page' or 'ce' or 'module'
if (!($type === 'page' || $type === 'article' || $type === 'ce' || $type === 'module' || $type === 'news' || $type === 'faq' || $type === 'galpic' || $type === 'news4ward')) { if (!($type === 'page' || $type === 'article' || $type === 'ce' || $type === 'module' || $type === 'news' || $type === 'faq' || $type === 'galpic' || $type === 'news4ward')) {
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_type']]; $return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_type']];
return new JsonResponse($return); return new JsonResponse(array('result' => 'error', 'data' => $return));
} }
$strHash = sha1(session_id() . (!$GLOBALS['TL_CONFIG']['disableIpCheck'] ? \Environment::get('ip') : '') . 'FE_USER_AUTH'); $strHash = sha1(session_id() . (!$GLOBALS['TL_CONFIG']['disableIpCheck'] ? \Environment::get('ip') : '') . 'FE_USER_AUTH');
@ -169,13 +169,13 @@ class RateIt extends \Frontend {
->execute(); ->execute();
} else { } else {
$return = [$GLOBALS['TL_LANG']['rateit']['error']['duplicate_vote']]; $return = [$GLOBALS['TL_LANG']['rateit']['error']['duplicate_vote']];
return new JsonResponse($return); return new JsonResponse(array('result' => 'error', 'data' => $return));
} }
$rating = $this->rateItFrontend->loadRating($id, $type); $rating = $this->rateItFrontend->loadRating($id, $type);
$return = [$this->rateItFrontend->getStarMessage($rating)]; $return = [$this->rateItFrontend->getStarMessage($rating)];
return new JsonResponse($return); return new JsonResponse(array('result' => 'success', 'data' => $return));
} }
} }
?> ?>