public function addAction() { if ($data = Zend_Json::decode($this->getRequest()->getRawBody())) { try { $customer_id = $this->getSession()->getCustomerId(); if (empty($customer_id) or empty($data['comment_id']) or empty($data['text'])) { throw new Exception($this->_("An error occurred while saving")); } $comment_id = $data['comment_id']; $text = $data['text']; $answer = new Comment_Model_Answer(); $answer->setCommentId($comment_id)->setCustomerId($customer_id)->setText($text)->save(); $html = array('success' => 1); $message = $this->_('Your message has been successfully saved.'); if (!$answer->isVisible()) { $message .= ' ' . $this->_('It will be visible only after validation by our team.'); } else { $customer = $this->getSession()->getCustomer(); $html["answer"] = array("author" => $customer->getFirstname() . ' ' . mb_substr($customer->getLastname(), 0, 1) . '.', "picture" => $customer->getImageLink(), "message" => $answer->getText(), "created_at" => $answer->getFormattedCreatedAt()); } $html["message"] = $message; } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }
public function addAction() { if ($datas = $this->getRequest()->getPost()) { try { $customer_id = $this->getSession()->getCustomerId(); if (empty($customer_id) or empty($datas['status_id']) or empty($datas['text'])) { throw new Exception('Erreur'); } $comment_id = $datas['status_id']; $text = $datas['text']; $comment = new Comment_Model_Answer(); $comment->setCommentId($comment_id)->setCustomerId($customer_id)->setText($text)->save(); $message = $this->_('Your message has been successfully saved.'); if (!$comment->isVisible()) { $message .= ' ' . $this->_('It will be visible only after validation by our team.'); } $html = array('success' => 1, 'message' => $message); } catch (Exception $e) { $html = array('error' => 1, 'message' => $e->getMessage()); } $this->_sendHtml($html); } }