Event-Verarbeitung
This commit is contained in:
parent
38d4df8232
commit
107e32c3be
@ -66,12 +66,16 @@ class RateIt extends \Frontend {
|
|||||||
* @param integer percent - The rating in percentages.
|
* @param integer percent - The rating in percentages.
|
||||||
*/
|
*/
|
||||||
public function doVote(SimpleAjax $event) {
|
public function doVote(SimpleAjax $event) {
|
||||||
if ($this->Input->get('do') == 'rateit') {
|
$input = $event->getEnvironment()->getInputProvider();
|
||||||
|
|
||||||
|
if ((true === $input->hasParameter('do'))
|
||||||
|
&& ('rateit' === $input->getParameter('do'))
|
||||||
|
) {
|
||||||
$ip = $_SERVER['REMOTE_ADDR'];
|
$ip = $_SERVER['REMOTE_ADDR'];
|
||||||
|
|
||||||
$rkey = $this->Input->post('id');
|
$rkey = $input->getParameter('id');
|
||||||
$percent = $this->Input->post('vote');
|
$percent = $input->getParameter('vote');
|
||||||
$type = $this->Input->post('type');
|
$type = $input->getParameter('type');
|
||||||
|
|
||||||
//Make sure that the ratable ID is a number and not something crazy.
|
//Make sure that the ratable ID is a number and not something crazy.
|
||||||
if (strstr($rkey, '|')) {
|
if (strstr($rkey, '|')) {
|
||||||
@ -81,7 +85,7 @@ class RateIt extends \Frontend {
|
|||||||
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
|
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
|
||||||
$response = new JsonResponse($return);
|
$response = new JsonResponse($return);
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
return;
|
return $event;
|
||||||
}
|
}
|
||||||
$id = $rkey;
|
$id = $rkey;
|
||||||
}
|
}
|
||||||
@ -92,7 +96,7 @@ class RateIt extends \Frontend {
|
|||||||
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
|
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
|
||||||
$response = new JsonResponse($return);
|
$response = new JsonResponse($return);
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
return;
|
return $event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,7 +107,7 @@ class RateIt extends \Frontend {
|
|||||||
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
|
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_rating']];
|
||||||
$response = new JsonResponse($return);
|
$response = new JsonResponse($return);
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
return;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Make sure that the ratable type is 'page' or 'ce' or 'module'
|
//Make sure that the ratable type is 'page' or 'ce' or 'module'
|
||||||
@ -111,7 +115,7 @@ class RateIt extends \Frontend {
|
|||||||
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_type']];
|
$return = [$GLOBALS['TL_LANG']['rateit']['error']['invalid_type']];
|
||||||
$response = new JsonResponse($return);
|
$response = new JsonResponse($return);
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
return;
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
$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');
|
||||||
@ -168,9 +172,10 @@ class RateIt extends \Frontend {
|
|||||||
->set($arrSet)
|
->set($arrSet)
|
||||||
->execute();
|
->execute();
|
||||||
} else {
|
} else {
|
||||||
header(RETURN_AJAX_HEADER);
|
$return = [$GLOBALS['TL_LANG']['rateit']['error']['duplicate_vote']];
|
||||||
echo $GLOBALS['TL_LANG']['rateit']['error']['duplicate_vote'];
|
$response = new JsonResponse($return);
|
||||||
exit;
|
$event->setResponse($response);
|
||||||
|
return $event;
|
||||||
}
|
}
|
||||||
|
|
||||||
$rating = $this->rateItFrontend->loadRating($id, $type);
|
$rating = $this->rateItFrontend->loadRating($id, $type);
|
||||||
@ -178,6 +183,7 @@ class RateIt extends \Frontend {
|
|||||||
$return = [$this->rateItFrontend->getStarMessage($rating)];
|
$return = [$this->rateItFrontend->getStarMessage($rating)];
|
||||||
$response = new JsonResponse($return);
|
$response = new JsonResponse($return);
|
||||||
$event->setResponse($response);
|
$event->setResponse($response);
|
||||||
|
return $event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
use cgoIT\rateit\RateIt;
|
use cgoIT\rateit\RateIt;
|
||||||
|
use SimpleAjax\Event\SimpleAjax;
|
||||||
|
|
||||||
return array(
|
if (class_exists(SimpleAjax::class)) {
|
||||||
'contao.simpleajax' => array(
|
return array
|
||||||
array(new RateIt(), 'doVote')
|
(
|
||||||
),
|
SimpleAjax::NAME => array(
|
||||||
|
array(
|
||||||
|
array(new RateIt(), 'doVote'),
|
||||||
|
RateIt::PRIORITY
|
||||||
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array();
|
||||||
|
Loading…
Reference in New Issue
Block a user