From 898ecc3055657ecc585ad00d7fb26552933f8cfd Mon Sep 17 00:00:00 2001 From: Dmitriy Simushev Date: Mon, 1 Oct 2012 11:39:58 +0000 Subject: [PATCH] Add Thread object creation to /operator/update.php Replace direct work with thread table's fields by Thread object --- src/messenger/webim/operator/update.php | 62 ++++++++++++++----------- 1 file changed, 36 insertions(+), 26 deletions(-) diff --git a/src/messenger/webim/operator/update.php b/src/messenger/webim/operator/update.php index 994db4af..d5f8af08 100644 --- a/src/messenger/webim/operator/update.php +++ b/src/messenger/webim/operator/update.php @@ -47,28 +47,31 @@ $threadstate_key = array( Thread::STATE_LOADING => "chat.thread.state_loading" ); -function thread_to_xml($thread) +function thread_to_xml($thread_info) { global $threadstate_to_string, $threadstate_key, $webim_encoding, $operator, $can_viewthreads, $can_takeover; - $state = $threadstate_to_string[$thread['istate']]; - $result = "state]; + $result = "id . "\" stateid=\"$state\""; if ($state == "closed") return $result . "/>"; - $state = getstring($threadstate_key[$thread['istate']]); - $nextagent = $thread['nextagent'] != 0 ? operator_by_id($thread['nextagent']) : null; + $state = getstring($threadstate_key[$thread->state]); + $nextagent = $thread->nextAgent != 0 ? operator_by_id($thread->nextAgent) : null; $threadoperator = $nextagent ? get_operator_name($nextagent) - : ($thread['agentName'] ? $thread['agentName'] : "-"); + : ($thread->agentName ? $thread->agentName : "-"); - if ($threadoperator == "-" && $thread['groupname']) { - $threadoperator = "- " . $thread['groupname'] . " -"; + if ($threadoperator == "-" && $thread_info['groupname']) { + $threadoperator = "- " . $thread_info['groupname'] . " -"; } - if (!($thread['istate'] == Thread::STATE_CHATTING && $thread['agentId'] != $operator['operatorid'] && !is_capable($can_takeover, $operator))) { + if (!($thread->state == Thread::STATE_CHATTING && $thread->agentId != $operator['operatorid'] && !is_capable($can_takeover, $operator))) { $result .= " canopen=\"true\""; } - if ($thread['agentId'] != $operator['operatorid'] && $thread['nextagent'] != $operator['operatorid'] + if ($thread->agentId != $operator['operatorid'] && $thread->nextAgent != $operator['operatorid'] && is_capable($can_viewthreads, $operator)) { $result .= " canview=\"true\""; } @@ -76,33 +79,35 @@ function thread_to_xml($thread) $result .= " canban=\"true\""; } - $banForThread = Settings::get('enableban') == "1" ? ban_for_addr($thread['remote']) : false; + $banForThread = Settings::get('enableban') == "1" ? ban_for_addr($thread->remote) : false; if ($banForThread) { $result .= " ban=\"blocked\" banid=\"" . $banForThread['banid'] . "\""; } - $result .= " state=\"$state\" typing=\"" . $thread['userTyping'] . "\">"; + $result .= " state=\"$state\" typing=\"" . $thread->userTyping . "\">"; $result .= ""; if ($banForThread) { $result .= htmlspecialchars(getstring('chat.client.spam.prefix')); } - $result .= htmlspecialchars(htmlspecialchars(get_user_name($thread['userName'], $thread['remote'], $thread['userid']))) . ""; - $result .= "" . htmlspecialchars(get_user_addr($thread['remote'])) . ""; + $result .= htmlspecialchars( + htmlspecialchars(get_user_name($thread->userName, $thread->remote, $thread->userId)) + ) . ""; + $result .= "" . htmlspecialchars(get_user_addr($thread->remote)) . ""; $result .= "" . htmlspecialchars(htmlspecialchars($threadoperator)) . ""; - $result .= ""; - $result .= "" . $thread['dtmmodified'] . "000"; + $result .= ""; + $result .= "" . $thread->modified . "000"; if ($banForThread) { $result .= "" . $banForThread['comment'] . ""; } - $userAgent = get_useragent_version($thread['userAgent']); + $userAgent = get_useragent_version($thread->userAgent); $result .= "" . $userAgent . ""; - if ($thread["shownmessageid"] != 0) { + if ($thread->shownMessageId != 0) { $db = Database::getInstance(); $line = $db->query( "select tmessage from {chatmessage} where messageid = ?", - array($thread["shownmessageid"]), + array($thread->shownMessageId), array('return_rows' => Database::RETURN_ONE_ROW) ); if ($line) { @@ -120,9 +125,8 @@ function print_pending_threads($groupids, $since) $db = Database::getInstance(); $revision = $since; - $query = "select threadid, userName, agentName, dtmcreated, userTyping, " . - "dtmmodified, lrevision, istate, remote, nextagent, agentId, " . - "userid, shownmessageid, userAgent, (select vclocalname from {chatgroup} where {chatgroup}.groupid = {chatthread}.groupid) as groupname " . + $query = "select {chatthread}.*, " . + "(select vclocalname from {chatgroup} where {chatgroup}.groupid = {chatthread}.groupid) as groupname " . "from {chatthread} where lrevision > :since " . ($since <= 0 ? "AND istate <> " . Thread::STATE_CLOSED . " AND istate <> " . Thread::STATE_LEFT . " " @@ -142,10 +146,16 @@ function print_pending_threads($groupids, $since) $output = array(); foreach ($rows as $row) { - $thread = thread_to_xml($row); - $output[] = $thread; - if ($row['lrevision'] > $revision) - $revision = $row['lrevision']; + $thread = Thread::createFromDbInfo($row); + $thread_info = array( + 'thread' => $thread, + 'groupName' => $row['groupname'] + ); + $thread_as_xml = thread_to_xml($thread_info); + $output[] = $thread_as_xml; + if ($thread->lastRevision > $revision) { + $revision = $thread->lastRevision; + } } echo "";