/** * Process form data. Update and create new post. * * @param $form * @param $advertisement * @param $city */ private function processFormData($form, $advertisement) { if ($this->getRequest()->isPost()) { if ($form->isValid($_POST)) { // $isValid = $this->_helper->common->validReCaptcha ( $this->_getAllParams() ); // if ($isValid) { $password = $form->getValue('password'); if ($password != $advertisement->password) { throw new Exception('没有权限修改该帖子'); } $city_id = $form->getValue('city'); $id = $form->getValue('id'); $name = $form->getValue('name'); $email = $form->getValue('email'); $mobile = $form->getValue('mobile'); $type = $form->getValue('type'); $title = $form->getValue('title'); $address = $form->getValue('address'); $rent = $form->getValue('rent'); $rent_measurement = $form->getValue('rent_measurement'); $area = $form->getValue('area'); $numOfRomm = $form->getValue('num_of_room'); $start_date = $form->getValue('start_date'); if (empty($start_date)) { throw new Exception("您必须填写入住日期"); } $stop_date_tmp = $form->getValue('stop_date'); $stop_date = empty($stop_date_tmp) ? Constant::DEFAULT_CHECKOUT_DATE : $stop_date_tmp; $description = $form->getValue('description'); $category = $form->getValue('isBusiness') == 1 ? Category::SHOP : Category::APARTMENT; $currency = $form->getValue('currency'); if (!isset($currency) || $currency == 0) { throw new Exception("您必须选择货币"); } $db = Zend_Registry::get('db'); $db->beginTransaction(); $data = array('name' => trim($name), 'email' => trim($email), 'mobile' => trim($mobile)); $user = $this->user->addUser($data); $data = array('user_id' => $user->id, 'title' => $title, 'description' => isset($description) ? $description : null, 'area' => isset($area) ? $area : 0, 'address' => isset($address) ? $address : null, 'rent' => isset($rent) ? $rent : 0, 'rent_measurement' => $rent_measurement, 'type' => $type, 'num_of_room' => isset($numOfRomm) ? $numOfRomm : 0, 'start_date' => $start_date, 'stop_date' => $stop_date, 'city_id' => $city_id, 'created' => $this->_helper->generator->generateCurrentTime(), 'modified' => $this->_helper->generator->generateCurrentTime(), "category_id" => $category, "currency" => $currency); if (isset($advertisement)) { $data['id'] = $advertisement->id; $this->advertisement->addOrUpdateAdvertisement($data); } else { $data['password'] = $this->generatePassword($email); $advertisement = $this->advertisement->addOrUpdateAdvertisement($data); // send email to creator $message = MailTemplate::getCreationEmailMessage($advertisement); $this->mailQueue->addToQueue(MailType::USER, null, MailTemplate::SUBJECT_CREATE_POST, Constant::SYSTEM_MAIL, $email, $message, $this->_helper->generator->generateCurrentTime()); } $db->commit(); $this->_flashMessenger->addMessage("您的帖子已经成功发布。如果在十分钟内未收到系统邮件,请确认它未被归入您的垃圾邮件 -_-|| 谢谢!"); $this->_redirect('/' . strtolower($this->city->findById($city_id)->name) . '/bulletin/list'); // } } } }