erLhcoreClassChatWorkflow::transferWorkflow PHP Méthode

transferWorkflow() public static méthode

Transfer workflow between departments
public static transferWorkflow ( erLhcoreClassModelChat &$chat )
$chat erLhcoreClassModelChat
    public static function transferWorkflow(erLhcoreClassModelChat &$chat)
    {
        $chat->transfer_if_na = 0;
        $chat->transfer_timeout_ts = time();
        if ($chat->department !== false && ($departmentTransfer = $chat->department->department_transfer) !== false) {
            $chat->dep_id = $departmentTransfer->id;
            $msg = new erLhcoreClassModelmsg();
            $msg->msg = erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncuser', 'Chat was automatically transferred to') . ' "' . $departmentTransfer . '" ' . erTranslationClassLhTranslation::getInstance()->getTranslation('chat/syncuser', 'from') . ' "' . $chat->department . '"';
            $msg->chat_id = $chat->id;
            $msg->user_id = -1;
            $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;
            }
            if ($departmentTransfer->inform_unread == 1) {
                $chat->reinform_timeout = $departmentTransfer->inform_unread_delay;
                $chat->unread_messages_informed = 0;
            }
            // Our new department also has a transfer rule
            if ($departmentTransfer->department_transfer !== false) {
                $chat->transfer_if_na = 1;
                $chat->transfer_timeout_ac = $departmentTransfer->transfer_timeout;
            }
            if ($chat->department->nc_cb_execute == 1) {
                $chat->nc_cb_executed = 0;
            }
            if ($chat->department->na_cb_execute == 1) {
                $chat->na_cb_executed = 0;
            }
            erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.data_changed_assigned_department', array('chat' => &$chat));
        }
        $chat->updateThis();
    }

Usage Example

 * Run every 10 minits or so. On this cron depends automatic chat transfer and unaswered chats callback.
 *
 * */
echo "Starting chat/workflow\n";
if (erLhcoreClassModelChatConfig::fetch('run_departments_workflow')->current_value == 1) {
    echo "Starting departments workflow\n";
    $ts = time();
    foreach (erLhcoreClassChat::getList(array('limit' => 500, 'customfilter' => array('transfer_timeout_ts < (' . $ts . '-transfer_timeout_ac)'), 'filter' => array('status' => erLhcoreClassModelChat::STATUS_PENDING_CHAT, 'transfer_if_na' => 1))) as $chat) {
        $canExecuteWorkflow = true;
        if (erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value >= 0) {
            if ($chat->department !== false && $chat->department->department_transfer_id > 0) {
                $canExecuteWorkflow = erLhcoreClassChat::getPendingChatsCountPublic($chat->department->department_transfer_id) <= erLhcoreClassModelChatConfig::fetch('pro_active_limitation')->current_value;
            }
        }
        if ($canExecuteWorkflow == true) {
            erLhcoreClassChatWorkflow::transferWorkflow($chat);
            echo "executing department transfer workflow for - ", $chat->id, "\n";
        } else {
            echo "Skipping transfer because dedicated department queue is full\n";
        }
    }
    echo "Ended departments workflow\n";
}
// Unanswered chats callback
echo erLhcoreClassChatWorkflow::mainUnansweredChatWorkflow();
echo "Closed chats - ", erLhcoreClassChatWorkflow::automaticChatClosing(), "\n";
echo "Purged chats - ", erLhcoreClassChatWorkflow::automaticChatPurge(), "\n";
foreach (erLhcoreClassChat::getList(array('limit' => 500, 'filter' => array('status' => erLhcoreClassModelChat::STATUS_PENDING_CHAT))) as $chat) {
    erLhcoreClassChatWorkflow::autoAssign($chat, $chat->department);
    erLhcoreClassChatEventDispatcher::getInstance()->dispatch('chat.pending_process_workflow', array('chat' => &$chat));
}