本文整理汇总了PHP中messages::save方法的典型用法代码示例。如果您正苦于以下问题:PHP messages::save方法的具体用法?PHP messages::save怎么用?PHP messages::save使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类messages
的用法示例。
在下文中一共展示了messages::save方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: sendAction
/**
* The Send Action: This checks that the HTTP request is post, decodes the JSON expected and then checks
* both the sending user's authentication (via their id and apiKey) and then checks the recipient exsits.
* Should both of these conditions be true, the method will save the message in the database and return
* with the message ID, Sender, Receiver, Content and Timestamp.
*/
public function sendAction()
{
$this->view->setRenderLevel(\Phalcon\Mvc\View::LEVEL_NO_RENDER);
$request = new \Phalcon\Http\Request();
if ($request->isPost()) {
$data = json_decode(file_get_contents('php://input'), true);
$user = users::findFirst(array("conditions" => 'id = :idVal: and apiKey = :keyVal:', 'bind' => array('idVal' => $data['userid'], 'keyVal' => $data['user_api_key'])));
$recipient = users::findFirst(array("conditions" => 'id = :idVal:', 'bind' => array('idVal' => $data['recipient'])));
if ($user && $recipient) {
$message = new messages();
$message->sender = $user->id;
$message->receiver = $recipient->id;
$message->content = $data['message'];
if ($message->save()) {
$data = array();
$data['id'] = $message->id;
$data['sender'] = $message->sender;
$data['receiver'] = $message->receiver;
$data['content'] = $message->content;
$data['timestamp'] = $message->timestamp;
if ($recipient->regID == "NULL") {
$data['type'] = "PULL";
} else {
$this->sendToGCM($message, $recipient);
$data['type'] = "PUSH";
}
$array = $data;
echo json_encode($array);
} else {
echo $message->getMessages();
}
$messageDownload = new downloadedmessages();
$messageDownload->messageID = $message->id;
$messageDownload->userID = $user->id;
$messageDownload->save();
}
}
}
示例2: create
public function create()
{
$users = User::where('username', Input::get('toId'))->orWhere('email', Input::get('toId'));
if ($users->count() == 0) {
echo $this->panelInit->language['userisntExist'];
exit;
}
$users = $users->first();
$messagesList = messagesList::where('userId', $this->data['users']->id)->where('toId', $users->id);
if ($messagesList->count() == 0) {
$messagesList = new messagesList();
$messagesList->userId = $this->data['users']->id;
$messagesList->toId = $users->id;
} else {
$messagesList = $messagesList->first();
}
$messagesList->lastMessage = Input::get('messageText');
$messagesList->lastMessageDate = time();
$messagesList->messageStatus = 0;
$messagesList->save();
$toReturnId = $messagesList->id;
$messagesList_ = messagesList::where('userId', $users->id)->where('toId', $this->data['users']->id);
if ($messagesList_->count() == 0) {
$messagesList_ = new messagesList();
$messagesList_->userId = $users->id;
$messagesList_->toId = $this->data['users']->id;
} else {
$messagesList_ = $messagesList_->first();
}
$messagesList_->lastMessage = Input::get('messageText');
$messagesList_->lastMessageDate = time();
$messagesList_->messageStatus = 1;
$messagesList_->save();
$toReturnId_ = $messagesList_->id;
$messages = new messages();
$messages->messageId = $toReturnId;
$messages->userId = $this->data['users']->id;
$messages->fromId = $this->data['users']->id;
$messages->toId = $users->id;
$messages->messageText = Input::get('messageText');
$messages->dateSent = time();
$messages->save();
$messages = new messages();
$messages->messageId = $toReturnId_;
$messages->userId = $users->id;
$messages->fromId = $this->data['users']->id;
$messages->toId = $users->id;
$messages->messageText = Input::get('messageText');
$messages->dateSent = time();
$messages->save();
return json_encode(array('messageId' => $toReturnId));
}