echo json_encode($result); break; case 'BanUser': $chat->SetDatabase(); if (isset($_POST['channelId'])) { $channelId = $_POST['channelId']; } else { $channelId = 0; } $result = $chat->BanUser($_POST['banUserId'], $_POST['userName'], $_POST['duration'], $_POST['messageId'], $channelId); $result = array_merge($chat->user, $result); echo json_encode($result); break; case 'GetHistory': include 'history.php'; $history = new ChatHistory(); list($channelId, $startDate, $endDate, $nick) = GetHistoryParamsFromPost(); $result = $history->Get($channelId, $startDate, $endDate, $nick, IsModeratorRequest($chat->user)); echo json_encode($result); break; case 'GetAutoModerationHistory': include 'automoderation_history.php'; $history = new ChatAutomoderationHistory($memcache); list($channelId, $startDate, $endDate, $nick) = GetHistoryParamsFromPost(); if (isset($_POST['bannedNick'])) { $bannedNick = $_POST['bannedNick']; } else { $bannedNick = ''; } $result = $history->Get($channelId, $startDate, $endDate, $nick, $bannedNick, IsModeratorRequest($chat->user)); echo json_encode($result);
/** * Adds an object to the instance pool. * * Propel keeps cached copies of objects in an instance pool when they are retrieved * from the database. In some cases -- especially when you override doSelect*() * methods in your stub classes -- you may need to explicitly add objects * to the cache in order to ensure that the same objects are always returned by doSelect*() * and retrieveByPK*() calls. * * @param ChatHistory $value A ChatHistory object. * @param string $key (optional) key to use for instance map (for performance boost if key was already calculated externally). */ public static function addInstanceToPool(ChatHistory $obj, $key = null) { if (Propel::isInstancePoolingEnabled()) { if ($key === null) { $key = (string) $obj->getId(); } // if key === null self::$instances[$key] = $obj; } }
/** * Store a newly chat. * * @return Response */ public function create() { if (!is_null($user = User::find((int) Input::get('user_id')))) { if (!Auth::user()->isBlocked($user->id)) { $result = DB::select('select c.chat_id, count(c.chat_id) as count ' . '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 = ?) and b.user_id = ?) ' . 'group by c.chat_id having c.count = 2 limit 1;', array(Auth::user()->id, $user->id)); if (count($result) > 0) { $chatId = $result[0]->chat_id; $chat = Chat::find($chatId); } else { $chat = new Chat(); $chat->owner_id = Auth::user()->id; $chat->topic = ''; $chat->save(); $chatId = $chat->id; $chatMember = new ChatMember(); $chatMember->chat_id = $chatId; $chatMember->user_id = Auth::user()->id; $chatMember->save(); $chatMember = new ChatMember(); $chatMember->chat_id = $chatId; $chatMember->user_id = $user->id; $chatMember->save(); $chatHystory = new ChatHistory(); $chatHystory->chat_id = $chatId; $chatHystory->event = 'created'; $chatHystory->save(); $chat = Chat::find($chat->id); } return $this->respond(array('chat_id' => $chat->id, 'owner_id' => $chat->owner_id, 'topic' => $chat->topic, 'timestamp' => $chat->getTimestamp(), 'users' => $chat->getUsersArray())); } else { return $this->respondInsufficientPrivileges('Can\'t send message to the user'); } } else { return $this->respondNotFound('User doesn\'t exist'); } }