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);
     }
 }
Example #2
0
 public function getAnswers()
 {
     if (!$this->getId()) {
         return array();
     }
     if (is_null($this->_answers)) {
         $answer = new Comment_Model_Answer();
         $answer->setStatus($this);
         $this->_answers = $answer->findByComment($this->getId(), true);
         foreach ($this->_answers as $answer) {
             $answer->setComment($this);
         }
     }
     return $this->_answers;
 }
 public function deleteAction()
 {
     if ($this->getRequest()->getPost() and $this->getCurrentOptionValue()) {
         try {
             $answer_id = $this->getRequest()->getPost('answer_id');
             if (!$answer_id) {
                 throw new Exception('');
             }
             $answer = new Comment_Model_Answer();
             $answer->find($answer_id);
             if ($answer->getId() and $answer->getComment()->getValueId() != $this->getCurrentOptionValue()->getId()) {
                 throw new Exception('');
             }
             $answer->delete();
             $html = array('success' => 1);
         } catch (Exception $e) {
             $html = array('message' => $this->_('An error occurred while deleting this answer. Please try again later.'), 'message_button' => 1, 'message_loader' => 1);
         }
         $this->getLayout()->setHtml(Zend_Json::encode($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);
     }
 }
 public function flagcommentAction()
 {
     if ($value_id = $this->getRequest()->getParam('value_id') and $answer_id = $this->getRequest()->getParam('answer_id')) {
         $application = $this->getApplication();
         $answer = new Comment_Model_Answer();
         $answer->find($answer_id);
         $comment = new Comment_Model_Comment();
         $comment->find($answer->getCommentId());
         if ($answer->getId() and $comment->getValueId() == $value_id) {
             $answer->setFlag($answer->getFlag() + 1);
             $answer->save();
             $message = $this->_('Your flag has successfully been notified');
             $html = array('success' => 1, 'message' => $message);
             $this->_sendHtml($html);
         }
     }
 }