erLhcoreClassChatWorkflow::presendCannedMsg PHP Méthode

presendCannedMsg() public static méthode

public static presendCannedMsg ( $chat )
    public static function presendCannedMsg($chat)
    {
        $session = erLhcoreClassChat::getSession();
        $q = $session->createFindQuery('erLhcoreClassModelCannedMsg');
        $q->where($q->expr->lOr($q->expr->eq('department_id', $q->bindValue($chat->dep_id)), $q->expr->lAnd($q->expr->eq('department_id', $q->bindValue(0)), $q->expr->eq('user_id', $q->bindValue(0))), $q->expr->eq('user_id', $q->bindValue($chat->user_id))), $q->expr->eq('auto_send', $q->bindValue(1)));
        $q->limit(1, 0);
        $q->orderBy('user_id DESC, position ASC, id ASC');
        // Questions with matched URL has higher priority
        $items = $session->find($q);
        if (!empty($items)) {
            $cannedMsg = array_shift($items);
            $replaceArray = array('{nick}' => $chat->nick, '{email}' => $chat->email, '{phone}' => $chat->phone, '{operator}' => (string) $chat->user->name_support);
            $additionalData = $chat->additional_data_array;
            if (is_array($additionalData)) {
                foreach ($additionalData as $row) {
                    if (isset($row->identifier) && $row->identifier != '') {
                        $replaceArray['{' . $row->identifier . '}'] = $row->value;
                    }
                }
            }
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.workflow.canned_message_replace', array('chat' => $chat, 'replace_array' => &$replaceArray));
            $cannedMsg->setReplaceData($replaceArray);
            $msg = new erLhcoreClassModelmsg();
            $msg->msg = $cannedMsg->msg_to_user;
            $msg->chat_id = $chat->id;
            $msg->user_id = $chat->user_id;
            $msg->name_support = $chat->user->name_support;
            $chat->last_user_msg_time = $msg->time = time();
            erLhcoreClassChat::getSession()->save($msg);
            if ($chat->last_msg_id < $msg->id) {
                $chat->last_msg_id = $msg->id;
            }
            $chat->updateThis();
        }
    }

Usage Example

        $chat->unread_messages_informed = 0;
        erLhcoreClassChat::getSession()->update($chat);
        echo $tpl->fetch();
        flush();
        session_write_close();
        if (function_exists('fastcgi_finish_request')) {
            fastcgi_finish_request();
        }
        if ($chatDataChanged == true) {
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.data_changed', array('chat' => &$chat, 'user' => $currentUser));
        }
        if ($operatorAccepted == true) {
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.accept', array('chat' => &$chat, 'user' => $currentUser));
            erLhcoreClassChat::updateActiveChats($chat->user_id);
            if ($chat->department !== false) {
                erLhcoreClassChat::updateDepartmentStats($chat->department);
            }
            erLhcoreClassChatWorkflow::presendCannedMsg($chat);
            $options = $chat->department->inform_options_array;
            erLhcoreClassChatWorkflow::chatAcceptedWorkflow(array('department' => $chat->department, 'options' => $options), $chat);
        }
        exit;
    }
    echo $tpl->fetch();
    exit;
} else {
    $tpl->setFile('lhchat/errors/adminchatnopermission.tpl.php');
    $tpl->set('show_close_button', true);
    echo $tpl->fetch();
    exit;
}