public function abuseAction() { // only ajax $this->checkXmlHttpRequest(); $abuseForm = $this->createForm('comment.abuse.form'); $messageData = ["success" => false]; try { $form = $this->validateForm($abuseForm); $comment_id = $form->get("id")->getData(); $event = new CommentAbuseEvent(); $event->setId($comment_id); $this->dispatch(CommentEvents::COMMENT_ABUSE, $event); $messageData["success"] = true; $messageData["message"] = $this->getTranslator()->trans("Your request has been registered. Thank you.", [], Comment::MESSAGE_DOMAIN); } catch (\Exception $ex) { // all errors $messageData["message"] = $this->getTranslator()->trans("Your request could not be validated. Try it later", [], Comment::MESSAGE_DOMAIN); } return $this->jsonResponse(json_encode($messageData)); }
public function abuse(CommentAbuseEvent $event) { if (null !== ($comment = CommentQuery::create()->findPk($event->getId()))) { $comment->setAbuse($comment->getAbuse() + 1); $comment->save(); $event->setComment($comment); } }