当前位置: 首页>>代码示例>>PHP>>正文


PHP Chat::getChats方法代码示例

本文整理汇总了PHP中Chat::getChats方法的典型用法代码示例。如果您正苦于以下问题:PHP Chat::getChats方法的具体用法?PHP Chat::getChats怎么用?PHP Chat::getChats使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chat的用法示例。


在下文中一共展示了Chat::getChats方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: chatHeartbeat

function chatHeartbeat($slug, $pageId)
{
    //Add check for open chat boxes in order to keep track of multiple windows
    if (empty($_SESSION['openChatBoxes']["{$pageId}"])) {
        $_SESSION['openChatBoxes']["{$pageId}"] = 0;
        $lastRecord = 0;
    } else {
        $lastRecord = $_SESSION['openChatBoxes']["{$pageId}"];
    }
    //**JAG check that SLUG is not null
    $project = Project::getProjectFromSlug($slug);
    $projectName = $project->getTitle();
    //This line is used to track whether we are switching between projects and need to close down chat rooms
    $_SESSION['lastProjectID'] = $project->getID();
    //signed in user
    $userId = Session::getUserID();
    $chatBoxes = array();
    $chats = Chat::getChats($slug, $lastRecord);
    $numRows = count($chats);
    $rowIndex = 0;
    $items = '';
    if (is_array($chats)) {
        foreach ($chats as $row => $chat) {
            $rowIndex++;
            if (!isset($_SESSION['openChatBoxes'][$chat['recipient']]) && isset($_SESSION['chatHistory'][$chat['recipient']])) {
                $items = $_SESSION['chatHistory'][$chat['recipient']];
            }
            //Grab username if available (should always be available)
            $chatFrom = User::load($chat['sender'])->getUsername();
            $chat['message'] = sanitize($chat['message']);
            $message = str_replace('"', '\\"', formatParagraphs($chat['message'], true));
            //Since chatHeartbeat always returns records greater than the stored last id, the only time that
            // the returned id of a search will match the stored last id will be on the first post in an empty
            // chat room
            if ($chat['id'] !== $lastRecord) {
                $items .= <<<EOD
\t\t\t\t\t   {
\t\t\t"s": "0",
\t\t\t"f": "{$chatFrom}",
\t\t\t"m": "{$message}",
                        "r": "{$chat['id']}",
                        "t": "{$projectName}"
\t   },
EOD;
            }
            if (!isset($_SESSION['chatHistory'][$chat['recipient']])) {
                $_SESSION['chatHistory'][$chat['recipient']] = '';
            }
            $_SESSION['chatHistory'][$chat['recipient']] .= <<<EOD
\t\t\t\t\t\t   {
\t\t\t"s": "0",
\t\t\t"f": "{$chatFrom}",
\t\t\t"m": "{$message}",
                        "r": "{$chat['id']}",
                        "t": "{$projectName}"
\t   },
EOD;
            $_SESSION['openChatBoxes'][$chat['recipient']] = $chat['sent'];
            unset($_SESSION['tsChatBoxes'][$chat['recipient']]);
            if ($numRows == $rowIndex && $numRows > 0) {
                $_SESSION['openChatBoxes']["{$pageId}"] = $chat['id'];
            }
        }
    }
    //Update user record with heart beat (used to tell logged in members)
    Chat::updateUserLocation($userId, $project->getID());
    if ($items != '') {
        $items = substr($items, 0, -1);
    }
    header('Content-type: application/json');
    ?>
{
		"items": [
			<?php 
    echo $items;
    ?>
        ]
}

<?php 
    exit(0);
}
开发者ID:malimu,项目名称:Pipeline,代码行数:82,代码来源:chat.php

示例2: array

    $response = array();
    // Handling the supported actions:
    switch ($_GET['action']) {
        case 'login':
            $response = Chat::login($_POST['name'], $_POST['email']);
            break;
        case 'checkLogged':
            $response = Chat::checkLogged();
            break;
        case 'logout':
            $response = Chat::logout();
            break;
        case 'submitChat':
            $response = Chat::submitChat($_POST['chatText']);
            break;
        case 'getUsers':
            $response = Chat::getUsers();
            break;
        case 'getChats':
            $response = Chat::getChats($_GET['lastID']);
            break;
        default:
            throw new Exception('Wrong action');
    }
    echo json_encode($response);
} catch (Exception $e) {
    die(json_encode(array('error' => $e->getMessage())));
}
?>

开发者ID:avong886,项目名称:the-grid,代码行数:29,代码来源:ajax.php

示例3: switch

    // Handling the supported actions:
    switch ($_GET['action']) {
        case 'login':
            $response = Chat::login($_POST['name'], $_POST['email'], $_POST['user']);
            break;
        case 'checkLogged':
            $response = Chat::checkLogged();
            break;
        case 'logout':
            $response = Chat::logout();
            break;
        case 'submitChat':
            $response = Chat::submitChat($_POST['chatText'], $_POST['room'], $_POST['room_od']);
            break;
        case 'getUsers':
            $response = Chat::getUsers();
            break;
        case 'getChats':
            $response = Chat::getChats($_GET['lastID'], $_GET['room'], $_GET['room_od']);
            break;
        default:
            throw new Exception('Error');
    }
    if ($_GET['action'] == "getChats") {
        echo emot(json_encode($response));
    } else {
        echo json_encode($response);
    }
} catch (Exception $e) {
    die(json_encode(array('error' => $e->getMessage())));
}
开发者ID:kardi31,项目名称:ogl,代码行数:31,代码来源:ajax.php


注:本文中的Chat::getChats方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。