/** * Creates a new message in the db * @return 1 is message created successfully, 0 otherwise */ public static function sendMessage() { $post = Core\Input::post(); if (isset($post['senderId']) && isset($post['recipientId']) && isset($post['petId']) && isset($post['message'])) { $messageObj = new Message($post['senderId'], $post['recipientId'], 'new', $post['message'], time(), time(), 1, 1); $res = Model\Message::createMesage($messageObj); return $res; } }
<?php include_once '../../base.php'; if (!Yike\AccessControl::roleAllow(array(Yike\AccessControl::USER))) { //检查权限 header('HTTP/1.1 403 Forbidden'); header("location: /app/user/login.php"); exit; } $msgs = Model\Message::findUserMsg(); $myUnuses = Model\OwnedThing::myUnuseThing(10); $myRequires = Model\DemandThing::myRequireThing(10); $statuses = Model\Status::all(); ?> <!DOCTYPE html > <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>用户中心</title> <?php echo View\Home::$styles . "\n"; echo View\Home::addStyle("user/index.css"); ?> <style> </style> </head> <body> <?php echo View\Home::getNav();
<?php include '../../base.php'; if (!Yike\AccessControl::roleAllow(array(Yike\AccessControl::USER))) { $json['status'] = 0; $json['message'] = "请登陆"; } else { $json['status'] = 0; $id = intval($_REQUEST['id']); $msg = Model\Message::findByID($id); if ($msg) { if ($msg->receiver->user_id == CURRENT_YIKE) { //只能标记自己的信息 $msg->has_read = 1; $msg->save(); $json['status'] = 1; $json['message'] = "标记成功"; } else { $json['message'] = "无权限标记该信息"; } } else { $json['message'] = "该信息已经被标记"; } } echo json_encode($json);
/** * Update a new Message record in the database * @return int row id of newly created message row */ public function update() { return Model\Message::updateMessage($this); }
/** * Creates a message on conversation of given user * * @param Model\Message $message * @return Model\Message */ public function add(Model\Message $message) { $response = $this->client->request('/appusers/' . $this->appUser->id . '/conversation/messages', 'POST', $message->getPayload()); return new Model\Message($response['message']); }
<?php include '../../base.php'; if (!Yike\AccessControl::roleAllow(array(Yike\AccessControl::USER))) { $json['status'] = 0; $json['message'] = "无权限"; } else { $data = array_map('strip_tags', $_REQUEST); //过滤 PHP 和 HTML 标签 $data = array_map('trim', $data); //去除空白 $receiver_name = $data['receiver']; $receiver = Model\User::find_by_user_name($receiver_name); if (!$receiver) { $json['status'] = 0; $json['message'] = "找不到该用户"; } else { $msg = new Model\Message(); $msg->init(array('sender_id' => CURRENT_YIKE, 'receiver_id' => $receiver->user_id, 'message_title' => $data['msgtitle'], 'message_content' => $data['msgcontent'])); $msg->save(); $json['status'] = 1; $json['message'] = "消息发送成功"; } } echo json_encode($json);