本文整理汇总了PHP中Chat::find方法的典型用法代码示例。如果您正苦于以下问题:PHP Chat::find方法的具体用法?PHP Chat::find怎么用?PHP Chat::find使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Chat
的用法示例。
在下文中一共展示了Chat::find方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: indexAction
public function indexAction()
{
if ($this->request->isAjax() && $this->request->getPost('chat_list') == 'y') {
$this->view->setRenderLevel(View::LEVEL_ACTION_VIEW);
}
// $this->view->disable();
if ($this->session->has('user_id')) {
$user_id = $this->session->get('user_id');
}
///////////////// Пагинация
if (!empty($_POST['page'])) {
$currentPage = $_POST["page"];
} else {
$currentPage = 1;
}
$paginator = new Phalcon\Paginator\Adapter\Model(array("data" => Chat::find(array('order' => 'creation_date DESC')), "limit" => 10, "page" => $currentPage));
$page = $paginator->getPaginate();
foreach ($page->items as $chat) {
$chats[$chat->id] = $chat->toArray();
$rt = $chat->messagechat->getLast();
if (!is_bool($rt)) {
//$this->elements->var_print(is_bool($rt));
$chat_s[$chat->id] = $rt->text;
// $chat_s[$chat->id] = false;
}
}
// echo '<pre>'; print_r($mes); echo '</pre>';
$this->view->setVars(array('chat_col' => $chat->count(), 'chats' => $chats, 'chat_s' => $cha = isset($chat_s) ? $chat_s : false, 'page_num' => $page->current, 'page_total' => $page->total_pages));
}
示例2: show
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$chat = Chat::find($id);
if (!isset($chat)) {
return Redirect::to('/community/chats')->with('flash_chat', 'That chat doesn\'t exist!')->with('alert_class', 'alert-danger');
}
$users = $chat->user->all();
//If the user isn't part of the conversation, don't let them view it
$inArray = false;
foreach ($users as $user) {
if ($user->id == Auth::user()->id) {
$inArray = true;
}
}
if (!$inArray) {
return Redirect::to('/community/chats')->with('flash_chat', 'You don\'t have permission to view this chat')->with('alert_class', 'alert-danger');
}
$replies = Reply::where('chat_id', '=', $chat->id)->get();
foreach ($replies as $reply) {
$notification = Notification::where('user_id', '=', Auth::user()->id)->where('reply_id', '=', $reply->id)->firstOrFail();
$notification->has_read = 1;
$notification->save();
}
return View::make('readOneChat')->with(array('chat' => $chat, 'users' => $chat->getOtherUsers(), 'replies' => $replies));
}
示例3: retrieveTypingStatus
public function retrieveTypingStatus()
{
$username = Input::get('username');
$chat = Chat::find(1);
if ($chat->user1 == $username) {
if ($chat->user2_is_typing) {
return $chat->user2;
}
} else {
if ($chat->user1_is_typing) {
return $chat->user1;
}
}
}
示例4: getChatWithUser
public function getChatWithUser($userId)
{
$result = null;
if (isset($this->id) && (int) $this->id > 0) {
$data = DB::select('select c.chat_id from chats_members c where c.chat_id in (select b.chat_id from chats_members b where b.chat_id in (select a.chat_id from chats_members a where a.user_id = ?) group by b.chat_id having count(b.user_id) = 2) and c.user_id = ?;', array($this->id, $userId));
if (count($data) > 0) {
$result = Chat::find($data[0]->chat_id);
}
}
return $result;
}
示例5: update
/**
* Update the chat info
*
* @param int|null $chatId Chat ID
* @return Response
*/
public function update($chatId = null)
{
$user = Auth::user();
if ((int) $chatId > 0 && !is_null($chat = Chat::find((int) $chatId)) && $chat->hasMember(Auth::user()->id)) {
if ((bool) Input::get('mark_as_read')) {
$this->markAsRead($chat, $user);
}
if (strlen($newTopic = (string) Input::get('topic')) > 0) {
$chat->topic = $newTopic;
$chat->save();
foreach ($chat->getMembersTokens() as $token) {
$state = new StateSender($token);
$state->setChatAsUpdated((int) $chatId, (int) Auth::user()->id);
$state->send();
}
}
if (Input::has('typing')) {
foreach ($chat->getMembersTokens() as $token) {
$state = new StateSender($token);
$state->setChatAsTyping($chatId, Auth::user()->id, (bool) Input::get('typing'));
$state->send();
}
}
if (Input::has('delivered')) {
$this->delivered($chat);
}
return $this->respondNoContent();
} else {
return $this->respondWithError('Chat doesn\'t exist');
}
}
示例6: newMessages
public function newMessages($chatId, $messageId, $size = 20)
{
$chat = Chat::find($chatId);
if (!$chat) {
return $this->respondNotFound();
}
if (!Message::find($messageId)) {
return $this->respondNotFound();
}
return $this->respond(['messages' => $chat->messages()->where('id', '>', $messageId)->take($size)->get()->transform(function ($message) {
return $message->getAsArray();
})]);
}