示例#1
0
 public function delete(CommentDeleteEvent $event)
 {
     if (null !== ($comment = CommentQuery::create()->findPk($event->getId()))) {
         $comment->delete();
         $event->setComment($comment);
         if (Comment::ACCEPTED === $comment->getStatus()) {
             $this->dispatchRatingCompute($event->getDispatcher(), $comment->getRef(), $comment->getRefId());
         }
     }
 }
示例#2
0
 /**
  * Creates the delete event with the provided form data
  */
 protected function getDeleteEvent()
 {
     $event = new CommentDeleteEvent();
     $event->setId($this->getRequest()->get('comment_id'));
     return $event;
 }
示例#3
0
 public function deleteAction($commentId)
 {
     // only ajax
     $this->checkXmlHttpRequest();
     $messageData = ["success" => false];
     try {
         $customer = $this->getSecurityContext()->getCustomerUser();
         // find the comment
         $comment = CommentQuery::create()->findPk($commentId);
         if (null !== $comment) {
             if ($comment->getCustomerId() === $customer->getId()) {
                 $event = new CommentDeleteEvent();
                 $event->setId($commentId);
                 $this->dispatch(CommentEvents::COMMENT_DELETE, $event);
                 if (null !== $event->getComment()) {
                     $messageData["success"] = true;
                     $messageData["message"] = $this->getTranslator()->trans("Your comment has been deleted.", [], Comment::MESSAGE_DOMAIN);
                 }
             }
         }
     } catch (\Exception $ex) {
     }
     if (false === $messageData["success"]) {
         $messageData["message"] = $this->getTranslator()->trans("Comment could not be removed. Please try later.", [], Comment::MESSAGE_DOMAIN);
     }
     return $this->jsonResponse(json_encode($messageData));
 }