Esempio n. 1
0
 /**
  * get's callend then online user does a pageview
  *
  * @param array $params            
  */
 public function onlineUserPageViewLogged($params)
 {
     if ($this->settings['enabled'] == true && $this->settings['online_visitors_tracking'] == true) {
         $onlineOptions = erLhcoreClassModelChatConfig::fetch('xmppservice_options')->data;
         if (isset($onlineOptions['track_online']) && $onlineOptions['track_online'] == true) {
             if (($xmppAccount = erLhcoreClassModelXMPPAccount::findOne(array('filter' => array('type' => erLhcoreClassModelXMPPAccount::USER_TYPE_VISITOR, 'user_id' => $params['ou']->id)))) !== false) {
                 if ($this->settings['handler'] == 'rpc' && is_object($params['tpl']) && $this->settings['online_visitors_tracking'] == true) {
                     /**
                      * In the future then websockets will support attatch method this could be used
                      * */
                     /* $xmppAccount->attach_data = erLhcoreClassExtensionXmppserviceHandler::prebindSession(array(
                            'username' => $xmppAccount->username,
                            'password' => $xmppAccount->password,
                            'host' => $this->settings['prebind_host'] . $xmppAccount->username_plain,
                        )); */
                     $params['tpl']->set('xmppAccount', $xmppAccount);
                 }
                 // Forward this information to NodeJS server
                 erLhcoreClassExtensionXmppserviceHandler::onlineUserPageViewLogged(array('xmpp_account' => $xmppAccount, 'ou' => $params['ou'], 'host_login' => $this->settings['host_login'], 'node_api_server' => $this->settings['node_api_server'], 'handler' => $this->settings['handler'], 'xmpp_host' => $this->settings['xmpp_host'], 'rpc_server' => $this->settings['rpc_server'], 'rpc_username' => $this->settings['rpc_username'], 'rpc_password' => $this->settings['rpc_password'], 'rpc_account_host' => $this->settings['rpc_account_host']));
             }
         }
     }
 }
 /**
  * handles messages from operator.
  * Workflow sounds like that
  * 1. Check that we can determine an operator
  * 2. Check to what messages was send, to chat or online visitor
  * 3. If message is send to online visitor check perphaps visitor has active chat
  * 4. If active chat found, send a message
  * 5. If active chat not found send message as proactive invitation
  *
  * @param array $params            
  *
  */
 public static function handleMessageFromOperator($params)
 {
     try {
         $parts = explode('.', $params['receiver']);
         if (isset($parts[1])) {
             $xmppUserLogin = $params['sender'] . '@' . $params['server'];
             $xmppUser = erLhcoreClassModelXMPPAccount::findOne(array('filter' => array('username' => $xmppUserLogin)));
             if ($xmppUser !== false) {
                 // It's message to online visitor
                 if (isset($parts[2]) && $parts[2] == 'chat') {
                     $chat = erLhcoreClassModelChat::fetch($parts[1]);
                     $user = $xmppUser->user;
                     // Messages to chat is only send if chat is not accepted or sender is chat owner
                     if ($chat->user_id == $user->id || $chat->user_id == 0) {
                         self::sendMessageToChat($chat, $xmppUser, $params['body']);
                     } else {
                         $xmppService = erLhcoreClassModule::getExtensionInstance('erLhcoreClassExtensionXmppservice');
                         $xmppService->sendMessageToOperatorAsUserByChat(array('xmpp_account_operator' => $xmppUser, 'chat' => $chat, 'msg' => '[[System Assistant]] Chat was already accepted by [' . $chat->user . '], your messages are now ignored'));
                     }
                 } else {
                     $visitorId = $parts[1];
                     $visitor = erLhcoreClassModelChatOnlineUser::fetch($visitorId);
                     // We do not have any active chat
                     if ($visitor->chat === false || !in_array($visitor->chat->status, array(erLhcoreClassModelChat::STATUS_ACTIVE_CHAT, erLhcoreClassModelChat::STATUS_PENDING_CHAT))) {
                         $visitor->operator_message = $params['body'];
                         $visitor->message_seen = 0;
                         $visitor->invitation_id = -1;
                         $visitor->operator_user_id = $xmppUser->user_id;
                         $visitor->saveThis();
                         // We have active chat
                     } else {
                         self::sendMessageToChat($visitor->chat, $xmppUser, $params['body']);
                     }
                 }
             } else {
                 throw new Exception('Could not find a operator');
             }
         } else {
             throw new Exception('Could not extract visitor ID');
         }
     } catch (Exception $e) {
         throw $e;
     }
 }