Update department main statistic for frontend
public static updateDepartmentStats ( $dep ) |
public function removeThis() { $q = ezcDbInstance::get()->createDeleteQuery(); // Messages $q->deleteFrom('lh_msg')->where($q->expr->eq('chat_id', $this->id)); $stmt = $q->prepare(); $stmt->execute(); // Transfered chats $q->deleteFrom('lh_transfer')->where($q->expr->eq('chat_id', $this->id)); $stmt = $q->prepare(); $stmt->execute(); // Delete user footprint $q->deleteFrom('lh_chat_online_user_footprint')->where($q->expr->eq('chat_id', $this->id)); $stmt = $q->prepare(); $stmt->execute(); // Delete screen sharing $q->deleteFrom('lh_cobrowse')->where($q->expr->eq('chat_id', $this->id)); $stmt = $q->prepare(); $stmt->execute(); // Delete speech settings $q->deleteFrom('lh_speech_chat_language')->where($q->expr->eq('chat_id', $this->id)); $stmt = $q->prepare(); $stmt->execute(); // Survey $q->deleteFrom('lh_abstract_survey_item')->where($q->expr->eq('chat_id', $this->id)); $stmt = $q->prepare(); $stmt->execute(); erLhcoreClassModelChatFile::deleteByChatId($this->id); erLhcoreClassChat::getSession()->delete($this); erLhcoreClassChat::updateActiveChats($this->user_id); if ($this->department !== false) { erLhcoreClassChat::updateDepartmentStats($this->department); } }
} } } else { $chat->status_sub = erLhcoreClassModelChat::STATUS_SUB_START_ON_KEY_UP; } // Set chat attributes for transfer workflow logic if ($chat->department !== false && $chat->department->department_transfer_id > 0) { $chat->transfer_if_na = 1; $chat->transfer_timeout_ts = time(); $chat->transfer_timeout_ac = $chat->department->transfer_timeout; } $chat->last_msg_id = $msg->id; $chat->last_user_msg_time = time(); $chat->saveThis(); erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chat_started', array('chat' => &$chat, 'msg' => $messageInitial)); erLhcoreClassChat::updateDepartmentStats($chat->department); $Result = erLhcoreClassModule::reRun(erLhcoreClassDesign::baseurlRerun('chat/chatwidgetchat') . '/' . $chat->id . '/' . $chat->hash . $modeAppendTheme . '/(cstarted)/chat_started_by_invitation_cb'); return true; } else { $tpl->set('errors', $Errors); } } $tpl->set('start_data_fields', $startDataFields); // User this only if not post if (!ezcInputForm::hasPostData()) { $definition = array('name' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'value' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'type' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY), 'size' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY), 'req' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY), 'sh' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY), 'hattr' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'string', null, FILTER_REQUIRE_ARRAY), 'value_items_admin' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY), 'via_hidden' => new ezcInputFormDefinitionElement(ezcInputFormDefinitionElement::OPTIONAL, 'unsafe_raw', null, FILTER_REQUIRE_ARRAY)); $form = new ezcInputForm(INPUT_GET, $definition); if ($form->hasValidData('name') && !empty($form->name)) { $inputData->name_items = $form->name; } if ($form->hasValidData('sh') && !empty($form->sh)) {
public static function automaticChatPurge() { $purgedChatsNumber = 0; $timeout = (int) erLhcoreClassModelChatConfig::fetch('autopurge_timeout')->current_value; if ($timeout > 0) { $delay = time() - $timeout * 60; foreach (erLhcoreClassChat::getList(array('limit' => 500, 'filtergt' => array('last_user_msg_time' => 0), 'filterlt' => array('last_user_msg_time' => $delay), 'filter' => array('status' => erLhcoreClassModelChat::STATUS_CLOSED_CHAT))) as $chat) { $chat->removeThis(); erLhcoreClassChat::updateActiveChats($chat->user_id); if ($chat->department !== false) { erLhcoreClassChat::updateDepartmentStats($chat->department); } $purgedChatsNumber++; } } return $purgedChatsNumber; }
$msg = new erLhcoreClassModelmsg(); $msg->msg = trim($responder->wait_message); $msg->chat_id = $chat->id; $msg->name_support = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/startchat', 'Live Support'); $msg->user_id = -2; $msg->time = time() + 5; erLhcoreClassChat::getSession()->save($msg); if ($chat->last_msg_id < $msg->id) { $chat->last_msg_id = $msg->id; } } $chat->saveThis(); erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.auto_responder_triggered', array('chat' => &$chat)); } } erLhcoreClassChat::updateDepartmentStats($params['chat']->department); erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.chat_started', array('chat' => &$chat, 'msg' => $messageInitial)); // Redirect user $Result = erLhcoreClassModule::reRun(erLhcoreClassDesign::baseurlRerun('chat/chatwidgetchat') . '/' . $chat->id . '/' . $chat->hash . $modeAppend . $modeAppendTheme . '/(cstarted)/online_chat_started_cb'); return true; } } else { // Show errors only if user is not switching form mode and not swithing language if ($Params['user_parameters_unordered']['switchform'] != 'true' && !isset($_POST['switchLang'])) { $tpl->set('errors', $Errors); } elseif (isset($_POST['switchLang'])) { $Result['additional_post_message'] = 'lhc_lang:' . erLhcoreClassSystem::instance()->WWWDirLang; } } } $tpl->set('start_data_fields', $startDataFields);
public static function changeStatus($params) { $changeStatus = $params['status']; $chat = $params['chat']; $userData = $params['user']; $allowCloseRemote = $params['allow_close_remote']; if ($changeStatus == erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) { if ($chat->status != erLhcoreClassModelChat::STATUS_ACTIVE_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_ACTIVE_CHAT; $chat->wait_time = time() - $chat->time; } if ($chat->user_id == 0) { $chat->user_id = $userData->id; } $chat->updateThis(); } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_PENDING_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_PENDING_CHAT; $chat->support_informed = 0; $chat->has_unread_messages = 1; $chat->updateThis(); } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_CLOSED_CHAT && $chat->user_id == $userData->id || $allowCloseRemote == true) { if ($chat->status != erLhcoreClassModelChat::STATUS_CLOSED_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_CLOSED_CHAT; $chat->chat_duration = erLhcoreClassChat::getChatDurationToUpdateChatID($chat->id); $msg = new erLhcoreClassModelmsg(); $msg->msg = (string) $userData . ' ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/closechatadmin', 'has closed the chat!'); $msg->chat_id = $chat->id; $msg->user_id = -1; $chat->last_user_msg_time = $msg->time = time(); erLhcoreClassChat::getSession()->save($msg); $chat->updateThis(); CSCacheAPC::getMem()->removeFromArray('lhc_open_chats', $chat->id); // Execute callback for close chat erLhcoreClassChat::closeChatCallback($chat, $userData); } } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_CHATBOX_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_CHATBOX_CHAT; erLhcoreClassChat::getSession()->update($chat); } elseif ($changeStatus == erLhcoreClassModelChat::STATUS_OPERATORS_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_OPERATORS_CHAT; erLhcoreClassChat::getSession()->update($chat); } erLhcoreClassChat::updateActiveChats($chat->user_id); if ($chat->department !== false) { erLhcoreClassChat::updateDepartmentStats($chat->department); } }
/** * Executed in erLhcoreClassExtensionXmppserviceHandler::handleMessageFromOperator send message to user from operator. * if provided message is a command to operator is send command response * * @param erLhcoreClassModelChat $chat * * @param erLhcoreClassModelXMPPAccount $xmppUser * * @param string $body * * @throws Exception */ public static function sendMessageToChat(erLhcoreClassModelChat $chat, erLhcoreClassModelXMPPAccount $xmppUser, $body) { $db = ezcDbInstance::get(); $db->beginTransaction(); try { $user = $xmppUser->user; $messageUserId = $user->id; $ignoreMessage = false; // Predefine $statusCommand = array('processed' => false, 'process_status' => ''); if (strpos(trim($body), '!') === 0) { $statusCommand = erLhcoreClassChatCommand::processCommand(array('no_ui_update' => true, 'msg' => $body, 'chat' => &$chat)); if ($statusCommand['processed'] === true) { $messageUserId = -1; // Message was processed set as internal message $body = '[b]' . $userData->name_support . '[/b]: ' . $body . ' ' . ($statusCommand['process_status'] != '' ? '|| ' . $statusCommand['process_status'] : ''); } if (isset($statusCommand['ignore']) && $statusCommand['ignore'] == true) { $ignoreMessage = true; } if (isset($statusCommand['info'])) { $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice'); $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] ' . $statusCommand['info'])); } } if ($ignoreMessage == false) { $msg = new erLhcoreClassModelmsg(); $msg->msg = $body; $msg->chat_id = $chat->id; $msg->user_id = $messageUserId; $msg->time = time(); $msg->name_support = $user->name_support; if ($messageUserId > 0 && $chat->chat_locale != '' && $chat->chat_locale_to != '') { erLhcoreClassTranslate::translateChatMsgOperator($chat, $msg); } erLhcoreClassChat::getSession()->save($msg); // Set last message ID if ($chat->last_msg_id < $msg->id) { $userChange = ''; // Assign operator if chat does not have one if ($chat->user_id == 0) { $userChange = ',user_id = :user_id'; } $stmt = $db->prepare("UPDATE lh_chat SET status = :status, user_status = :user_status, last_msg_id = :last_msg_id{$userChange} WHERE id = :id"); $stmt->bindValue(':id', $chat->id, PDO::PARAM_INT); $stmt->bindValue(':last_msg_id', $msg->id, PDO::PARAM_INT); $changeStatus = false; if ($user->invisible_mode == 0) { if ($chat->status == erLhcoreClassModelChat::STATUS_PENDING_CHAT) { $chat->status = erLhcoreClassModelChat::STATUS_ACTIVE_CHAT; $changeStatus = true; } } if ($chat->user_status == erLhcoreClassModelChat::USER_STATUS_CLOSED_CHAT) { $chat->user_status = erLhcoreClassModelChat::USER_STATUS_PENDING_REOPEN; if (($onlineuser = $chat->online_user) !== false) { $onlineuser->reopen_chat = 1; $onlineuser->saveThis(); } } $stmt->bindValue(':user_status', $chat->user_status, PDO::PARAM_INT); $stmt->bindValue(':status', $chat->status, PDO::PARAM_INT); if ($userChange != '') { $stmt->bindValue(':user_id', $msg->user_id, PDO::PARAM_INT); } $stmt->execute(); } // If chat status changes update statistic if ($changeStatus == true) { if ($chat->department !== false) { erLhcoreClassChat::updateDepartmentStats($chat->department); } erLhcoreClassChat::updateActiveChats($chat->user_id); } } $db->commit(); // Inform operator about command status if ($statusCommand['processed'] == true && $statusCommand['process_status'] != '') { $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice'); $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] ' . $statusCommand['process_status'])); } // For nodejs plugin erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.desktop_client_admin_msg', array('msg' => &$msg, 'chat' => &$chat)); // For general listeners erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.web_add_msg_admin', array('msg' => &$msg, 'chat' => &$chat)); } catch (Exception $e) { $db->rollback(); throw $e; } }