/** * @Request({"comment": "array", "id": "int"}, csrf=true) * @Response("json") */ public function saveAction($data, $id = 0) { try { $user = $this['user']; if (!$id || !($comment = $this->comments->find($id))) { if (!($parent = $this->comments->find((int) @$data['parent_id']))) { throw new Exception('Invalid comment reply.'); } $comment = new Comment(); $comment->setUserId((int) $user->getId()); $comment->setIp($this['request']->getClientIp()); $comment->setAuthor($user->getName()); $comment->setEmail($user->getEmail()); $comment->setUrl($user->getUrl()); $comment->setStatus(CommentInterface::STATUS_APPROVED); $comment->setPostId($parent->getPostId()); $comment->setParent($parent); } $this->comments->save($comment, $data); return ['message' => $id ? __('Comment saved.') : __('Comment created.')]; } catch (Exception $e) { return ['message' => $e->getMessage(), 'error' => true]; } }