/**
  * View detail post action.
  */
 public function viewAction()
 {
     $config = Zend_Registry::get('config');
     $this->view->headScript()->appendFile($config->baseurl . '/js/jquery.validate.min.js');
     $this->view->headScript()->appendFile($config->baseurl . '/js/view.js');
     $this->view->class = "view";
     $city = $this->_getParam('city');
     $id = $this->_getParam('id');
     $advertisement = $this->advertisement->findById($id);
     if (isset($advertisement)) {
         $this->view->viewMode = 'detail';
         $this->view->advertisement = $advertisement;
         $form = new SendIntrestMail($advertisement, $city);
         $this->view->form = $form;
         $cityObj = $this->city->findByName($city);
         $this->view->pageTitle = $advertisement->title . "| 租个房子 - " . $cityObj->name_cn_long;
         $pageDesc = "";
         if ($advertisement->type == "want") {
             $this->view->pageImage = "want";
             $pageDesc = $pageDesc . "最高房租:" . $advertisement->rent . $this->_helper->RentFormat($advertisement) . " | ";
             $pageDesc = $pageDesc . "最小面积:" . $advertisement->area . "平方米  | ";
             $pageDesc = $pageDesc . "时间:" . $advertisement->start_date;
             if ($this->_helper->DateIsValid($advertisement->stop_date)) {
                 $pageDesc = $pageDesc . "到" . $advertisement->stop_date;
             } else {
                 $pageDesc = $pageDesc . "起长期";
             }
             $pageDesc = $pageDesc . "\n描述:" . $advertisement->description;
         } else {
             $this->view->pageImage = "lease";
             $pageDesc = $pageDesc . "地址:" . $advertisement->address . " | ";
             $pageDesc = $pageDesc . "房租: " . $advertisement->rent . $this->_helper->RentFormat($advertisement) . " | ";
             $pageDesc = $pageDesc . "时间:" . $advertisement->start_date;
             if ($this->_helper->DateIsValid($advertisement->stop_date)) {
                 $pageDesc = $pageDesc . "到" . $advertisement->stop_date;
             } else {
                 $pageDesc = $pageDesc . "起长期";
             }
             $pageDesc = $pageDesc . "\n描述:" . $advertisement->description;
         }
         if ($advertisement->category_id == Category::SHOP) {
             $this->view->pageImage = "business";
         }
         $this->view->pageDesc = $pageDesc;
         if ($this->getRequest()->isPost()) {
             if ($form->isValid($_POST)) {
                 //					$isValid = $this->_helper->common->validReCaptcha ($this->_getAllParams());
                 //					if ($isValid) {
                 $id = $form->getValue('id');
                 $city = $form->getValue('city');
                 // sender name
                 $name = $form->getValue('name');
                 // sender email
                 $email = $form->getValue('email');
                 // body
                 $body = $form->getValue('body');
                 $advertisement = $this->advertisement->findById($id);
                 $user = Advertisement::getUser($id);
                 //$this->_helper->swiftEmail->sendEmail($body, Advertisement::getUser($advertisement->id)->email, $email, '租个房子');
                 $db = Zend_Registry::get('db');
                 $db->beginTransaction();
                 $data = array('name' => trim($name), 'email' => trim($email));
                 $sendUser = $this->user->addUser($data);
                 $message = MailTemplate::getEmailMessage($name, $email, $user->email, $body, $advertisement, MailTemplate::SENDER_MAIL_BODY);
                 $subject = MailTemplate::getEmailSubject($advertisement->title, MailTemplate::SUBJECT_SEND_TO_OWNER);
                 $mailId = $this->mailQueue->addToQueue(MailType::USER, $name, $subject, $email, $user->email, $message, $this->_helper->generator->generateCurrentTime());
                 // add advertisement response
                 $this->advertisementResponse->addAdvertisementResponse($id, $sendUser->id, $mailId);
                 $message = MailTemplate::getEmailMessage($name, $email, $user->email, $body, $advertisement, MailTemplate::SENDER_RECIEPT_BODY);
                 $subject = MailTemplate::getEmailSubject($advertisement->title, MailTemplate::SUBJECT_SENDER_RECEIPT);
                 $this->mailQueue->addToQueue(MailType::USER, $name, $subject, Constant::SYSTEM_MAIL, $email, $message, $this->_helper->generator->generateCurrentTime());
                 $this->_flashMessenger->addMessage("您的邮件已成功发给贴主了!请等待回音!因为房源紧张,所以可能不会收到贴主的回复。请多找几处。最好电话联系!谢谢您的支持!!");
                 $db->commit();
                 $this->_redirect('/' . $city . '/bulletin/view/' . $advertisement->id);
                 //					} else {
                 ////						throw new Exception ( '验证码错误!' );
                 //					}
             }
         }
     } else {
         throw new Exception('帖子ID缺失或者帖子未找到!');
     }
 }