public static function CheckNumberForBlackList($number) { $blackListTime = Bitrix\Main\Config\Option::get("voximplant", "blacklist_time", 5); $blackListCount = Bitrix\Main\Config\Option::get("voximplant", "blacklist_count", 5); $minTime = new Bitrix\Main\Type\DateTime(); $minTime->add('-' . $blackListTime . ' minutes'); $dbData = VI\StatisticTable::getList(array('filter' => array("PHONE_NUMBER" => $number, '>CALL_START_DATE' => $minTime), 'select' => array('ID'))); $callsCount = 0; while ($dbData->fetch()) { $callsCount++; if ($callsCount >= $blackListCount) { $number = substr($number, 0, 20); VI\BlacklistTable::add(array("PHONE_NUMBER" => $number)); $messageUserId = Bitrix\Main\Config\Option::get("voximplant", "blacklist_user_id", ""); CVoxImplantHistory::SendMessageToChat($messageUserId, $number, CVoxImplantMain::CALL_INCOMING, GetMessage("BLACKLIST_NUMBER")); return true; } } return false; }
public static function GetTelephonyStatistic() { $arMonthlyStat = COption::GetOptionString("voximplant", "telephony_statistic", ""); if ($arMonthlyStat) { $arMonthlyStat = unserialize($arMonthlyStat); } else { $arMonthlyStat = array(); } $lastUncountedMonth = COption::GetOptionString("voximplant", "telephony_statistic_last_month", ""); //last month which wasn't counted if ($lastUncountedMonth) { $lastUncountedMonth = unserialize($lastUncountedMonth); } else { $lastUncountedMonth = array(); } $curLastMonth = array(); $curLastMonth["MM"] = date("m"); $curLastMonth["YYYY"] = date("Y"); if (date("m") != $lastUncountedMonth["MM"] || date("Y") != $lastUncountedMonth["YYYY"]) { $firstDayCurMonth = ConvertTimeStamp(MakeTimeStamp("01." . date("m") . "." . date("Y"), "DD.MM.YYYY")); if (!empty($lastUncountedMonth)) { $firstUncountedDay = ConvertTimeStamp(MakeTimeStamp("01." . $lastUncountedMonth["MM"] . "." . $lastUncountedMonth["YYYY"], "DD.MM.YYYY")); $arFilter = array(array('LOGIC' => 'AND', '>CALL_START_DATE' => $firstUncountedDay, '<CALL_START_DATE' => $firstDayCurMonth)); } else { $arFilter = array(array('LOGIC' => 'AND', '>CALL_START_DATE' => ConvertTimeStamp(MakeTimeStamp("04.02.2014", "DD.MM.YYYY")), '<CALL_START_DATE' => $firstDayCurMonth)); } $arFilter['CALL_CATEGORY'] = 'external'; $parameters = array('order' => array('CALL_START_DATE' => 'DESC'), 'filter' => $arFilter, 'select' => array('COST', 'COST_CURRENCY', 'CALL_DURATION', 'CALL_START_DATE')); $dbStat = VI\StatisticTable::getList($parameters); $curPortalCurrency = ""; while ($arData = $dbStat->fetch()) { $arData["COST_CURRENCY"] = $arData["COST_CURRENCY"] == "RUR" ? "RUB" : $arData["COST_CURRENCY"]; if (!$curPortalCurrency) { $curPortalCurrency = $arData["COST_CURRENCY"]; } $arDateParse = ParseDateTime($arData["CALL_START_DATE"]); $arMonthlyStat[$arDateParse["YYYY"]][$arDateParse["MM"]]["CALL_DURATION"] += $arData["CALL_DURATION"]; $arMonthlyStat[$arDateParse["YYYY"]][$arDateParse["MM"]]["COST"] += $arData["COST"]; // $arMonthlyStat[$arDateParse["YYYY"]][$arDateParse["MM"]]["COST"] = number_format($arMonthlyStat[$arDateParse["YYYY"]][$arDateParse["MM"]]["COST"], 4); $arMonthlyStat[$arDateParse["YYYY"]][$arDateParse["MM"]]["COST_CURRENCY"] = $curPortalCurrency; } if (!empty($arMonthlyStat)) { krsort($arMonthlyStat); foreach ($arMonthlyStat as $year => $arYear) { krsort($arYear); $arMonthlyStat[$year] = $arYear; } COption::SetOptionString("voximplant", "telephony_statistic", serialize($arMonthlyStat)); COption::SetOptionString("voximplant", "telephony_statistic_last_month", serialize($curLastMonth)); } } return $arMonthlyStat; }
public static function RegisterEntity($params) { if (!CModule::IncludeModule('crm')) { return false; } $callId = $params['ORIGIN_ID']; $callerId = ''; if (substr($callId, 0, 3) == 'VI_') { $callId = substr($callId, 3); } $res = VI\CallTable::getList(array('filter' => array('=CALL_ID' => $callId))); if ($call = $res->fetch()) { $callerId = $call['CALLER_ID']; CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $call['CALL_ID'], 'PHONE_NUMBER' => $call['CALLER_ID'], 'INCOMING' => $call['INCOMING'], 'USER_ID' => $call['USER_ID'], 'DATE_CREATE' => $call['DATE_CREATE'])); if ($call['USER_ID'] > 0) { $crmData = CVoxImplantCrmHelper::GetDataForPopup($callId, $call['CALLER_ID'], $call['USER_ID']); $pullResult = CVoxImplantIncoming::SendPullEvent(array('COMMAND' => 'update_crm', 'USER_ID' => $call['USER_ID'], 'CALL_ID' => $callId, 'CALLER_ID' => $callerId, 'CRM' => $crmData)); } CVoxImplantHistory::WriteToLog(array($callId, $call), 'CRM ATTACH INIT CALL'); } else { $res = VI\StatisticTable::getList(array('filter' => array('=CALL_ID' => $callId))); if ($history = $res->fetch()) { $history['USER_ID'] = $history['PORTAL_USER_ID']; $history['DATE_CREATE'] = $history['CALL_START_DATE']; CVoxImplantCrmHelper::AddCall(array('CALL_ID' => $history['CALL_ID'], 'PHONE_NUMBER' => $history['PHONE_NUMBER'], 'INCOMING' => $history['INCOMING'] == CVoxImplantMain::CALL_OUTGOING ? CVoxImplantMain::CALL_OUTGOING : CVoxImplantMain::CALL_INCOMING, 'USER_ID' => $history['USER_ID'], 'DATE_CREATE' => $history['DATE_CREATE'])); CVoxImplantCrmHelper::UpdateCall($history); CVoxImplantCrmHelper::AttachRecordToCall(array('CALL_ID' => $history['CALL_ID'], 'CALL_WEBDAV_ID' => $history['CALL_WEBDAV_ID'], 'CALL_RECORD_ID' => $history['CALL_RECORD_ID'])); CVoxImplantHistory::WriteToLog(array($callId), 'CRM ATTACH FULL CALL'); } } return true; }
public static function statisticGet($arParams, $nav, $server) { $arParams = array_change_key_case($arParams, CASE_UPPER); $sort = $arParams['SORT']; $order = $arParams['ORDER']; if (isset($arParams['FILTER']) && is_array($arParams['FILTER'])) { $arFilter = array_change_key_case($arParams['FILTER'], CASE_UPPER); } else { $arFilter = array(); } if (!CVoxImplantMain::CheckAccess()) { $arFilter['USER_ID'] = $GLOBALS['USER']->GetID(); } $arReturn = array(); $dbResCnt = \Bitrix\Voximplant\StatisticTable::getList(array('filter' => $arFilter, 'select' => array("CNT" => new Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')))); $arResCnt = $dbResCnt->fetch(); if ($arResCnt && $arResCnt["CNT"] > 0) { $arNavParams = self::getNavData($nav, true); $arSort = array(); if ($sort && $order) { $arSort[$sort] = $order; } $dbRes = \Bitrix\Voximplant\StatisticTable::getList(array('order' => $arSort, 'filter' => $arFilter, 'limit' => $arNavParams['limit'], 'offset' => $arNavParams['offset'])); $result = array(); while ($arData = $dbRes->fetch()) { unset($arData['ACCOUNT_ID']); unset($arData['APPLICATION_ID']); unset($arData['APPLICATION_NAME']); unset($arData['CALL_LOG']); unset($arData['CALL_RECORD_ID']); unset($arData['CALL_WEBDAV_ID']); unset($arData['CALL_STATUS']); unset($arData['CALL_DIRECTION']); $arData['CALL_TYPE'] = $arData['INCOMING']; unset($arData['INCOMING']); $arData['CALL_START_DATE'] = CRestUtil::ConvertDateTime($arData['CALL_START_DATE']); $result[] = $arData; } return self::setNavData($result, array("count" => $arResCnt['CNT'], "offset" => $arNavParams['offset'])); } return $arReturn; }
$filterByUser = intval($_GET['USER_ID']); $filter["PORTAL_USER_ID"] = $filterByUser; } $filterByCode = ''; if (isset($_GET['CODE']) && preg_match('#^[[:alnum:]\\-]+$#D', $_GET['CODE'])) { $filterByCode = $_GET['CODE']; $filter["CALL_FAILED_CODE"] = $filterByCode; } $parametrs = array('order' => array('CALL_START_DATE' => 'DESC'), 'filter' => $filter, 'select' => array('*')); if (!$_GET['SHOWALL_1']) { $parametrs['limit'] = $limit; $parametrs['offset'] = ($page - 1) * $limit; } $data = VI\StatisticTable::getList($parametrs); $result = new CDBResult($data); $countQuery = new Bitrix\Main\Entity\Query(VI\StatisticTable::getEntity()); $countQuery->addSelect(new \Bitrix\Main\Entity\ExpressionField('CNT', 'COUNT(1)')); $countQuery->setFilter($filter); $totalCount = $countQuery->setLimit(null)->setOffset(null)->exec()->fetch(); $totalCount = intval($totalCount['CNT']); if (!$_GET['SHOWALL_1']) { $totalPage = ceil($totalCount / $limit); $result->NavStart($limit); } else { $totalPage = 1; $result->NavStart(); } $result->NavRecordCount = $totalCount; $result->NavPageCount = $totalPage; $result->NavPageNomer = $page; $arResult["NAV_OBJECT"] = $result;
public static function GetForPopup($id) { $id = intval($id); if ($id <= 0) { return false; } $history = VI\StatisticTable::getById($id); $params = $history->fetch(); if (!$params) { return false; } $params = self::PrepereData($params); $arResult = array('PORTAL_USER_ID' => $params['PORTAL_USER_ID'], 'PHONE_NUMBER' => $params['PHONE_NUMBER'], 'INCOMING_TEXT' => $params['INCOMING_TEXT'], 'CALL_ICON' => $params['CALL_ICON'], 'CALL_FAILED_CODE' => $params['CALL_FAILED_CODE'], 'CALL_FAILED_REASON' => $params['CALL_FAILED_REASON'], 'CALL_DURATION_TEXT' => $params['CALL_DURATION_TEXT'], 'COST_TEXT' => $params['COST_TEXT'], 'CALL_RECORD_HREF' => $params['CALL_RECORD_HREF']); return $arResult; }
<?php $APPLICATION->IncludeComponent("bitrix:voximplant.sip_payments", "", array()); ?> </div> <!-- statistic--> <?php if (CModule::IncludeModule("currency")) { $curPortalCurrency = ""; $lastDay = ConvertTimeStamp(mktime(0, 0, 0, date("m"), date("d") + 1, date("Y"))); $firstDay = ConvertTimeStamp(MakeTimeStamp("01." . date("m") . "." . date("Y"), "DD.MM.YYYY")); $parameters = array('order' => array('CALL_START_DATE' => 'DESC'), 'filter' => array(array('LOGIC' => 'AND', '>CALL_START_DATE' => $firstDay, '<CALL_START_DATE' => $lastDay)), 'select' => array('COST', 'COST_CURRENCY', 'CALL_DURATION')); $costLastMonth = 0; $durationLastMonth = 0; $data = VI\StatisticTable::getList($parameters); while ($arData = $data->fetch()) { $arData["COST_CURRENCY"] = $arData["COST_CURRENCY"] == "RUR" ? "RUB" : $arData["COST_CURRENCY"]; if (!$curPortalCurrency) { $curPortalCurrency = $arData["COST_CURRENCY"]; } $costLastMonth += $arData["COST"]; $durationLastMonth += $arData["CALL_DURATION"]; } if ($durationLastMonth > 60) { $formatTimeMin = floor($durationLastMonth / 60); $formatTimeSec = $durationLastMonth - $formatTimeMin * 60; $durationLastMonth = $formatTimeMin . " " . GetMessage("TELEPHONY_MIN"); if ($formatTimeSec > 0) { $durationLastMonth = $durationLastMonth . " " . $formatTimeSec . " " . GetMessage("TELEPHONY_SEC"); }