/** * sends a message * @param string $message_text * @param Model_User $user_from * @param Model_User $user_to * @param integer $id_ad * @param integer $id_message_parent * @param integer $price negotiate price optionsl * @return bool / model_message */ private static function send($message_text, $user_from, $user_to, $id_ad = NULL, $id_message_parent = NULL, $price = NULL) { //cant be the same... if ($user_to->id_user !== $user_from->id_user) { $notify = TRUE; $message = new Model_Message(); $message->message = $message_text; $message->id_user_from = $user_from->id_user; $message->id_user_to = $user_to->id_user; //message to an ad. we have verified before the ad, and pass the correct user if (is_numeric($id_ad)) { $message->id_ad = $id_ad; } //we trust this since comes fom a function where we validate tihs user can post in that thread if (is_numeric($id_message_parent)) { //set current message the correct thread, $message->id_message_parent = $id_message_parent; //if user is the TO check status of first message to and if its deleted or spam do not mark it as unread, no email and no notification $message_parent = new Model_Message($id_message_parent); if ($user_to->id_user == $message_parent->id_user_to and ($message_parent->status_to == Model_Message::STATUS_SPAM or $message_parent->status_to == Model_Message::STATUS_DELETED)) { $message->status_to = $message_parent->status_to; $notify = FALSE; } } //has some price? if (is_numeric($price)) { $message->price = $price; } try { $message->save(); //didnt have a parent so we set the parent for the same if (!is_numeric($id_message_parent)) { $message->id_message_parent = $message->id_message; $message->save(); } if ($notify === TRUE) { //notify user $data = array('id_message' => $message->id_message_parent, 'title' => sprintf(__('New Message from %s'), $message->from->name)); $message->to->push_notification($message_text, $data); } return $message; } catch (Exception $e) { return FALSE; } } return FALSE; }
/** * sends a message * @param string $message_text * @param integer $id_user_from * @param integer $id_user_to * @param integer $id_ad * @param integer $id_message_parent * @param integer $price negotiate price optionsl * @return bool / model_message */ private static function send($message_text, $id_user_from, $id_user_to, $id_ad = NULL, $id_message_parent = NULL, $price = NULL) { //cant be the same... if ($id_user_to !== $id_user_from) { $message = new Model_Message(); $message->message = $message_text; $message->id_user_from = $id_user_from; $message->id_user_to = $id_user_to; //message to an ad. we have verified before the ad, and pass the correct user if (is_numeric($id_ad)) { $message->id_ad = $id_ad; } //set current message the correct thread, //we trust this since comes fom a function where we validate tihs user can post in that thread if (is_numeric($id_message_parent)) { $message->id_message_parent = $id_message_parent; } //has some price? if (is_numeric($price)) { $message->price = $price; } try { $message->save(); //didnt have a parent so we set the parent for the same if (!is_numeric($id_message_parent)) { $message->id_message_parent = $message->id_message; $message->save(); } //send email? //notify user $data = array('id_message' => $message->id_message_parent, 'title' => sprintf(__('New Message from %s'), $message->from->name)); $message->to->push_notification($message_text, $data); return $message; } catch (Exception $e) { return FALSE; } } return FALSE; }
public function noticeAction() { if ($this->_request->isPost()) { $data = $this->_request->getParams(); unset($data["action"]); unset($data["controller"]); unset($data["module"]); $data["sender"] = $this->admin->{"username"}; $data["user_id"] = -1; $data["type"] = 1; $data["message"] = "1|" . $data["message"]; $notice_modle = new Model_Message(); $notice_modle->save($data); echo "<h2>Created !!!</h2>"; } }