示例#1
0
 public static function SynchronizeUserPhones()
 {
     $offset = intval(COption::GetOptionInt("voximplant", "sync_offset", 0));
     $result = Bitrix\Main\UserTable::getList(array('select' => array('ID', 'WORK_PHONE', 'PERSONAL_PHONE', 'PERSONAL_MOBILE', 'UF_PHONE_INNER'), 'filter' => array('=Bitrix\\Voximplant\\Phone:USER.USER_ID' => 0), 'limit' => 100, 'offset' => $offset, 'order' => 'ID'));
     $count = 0;
     while ($user = $result->fetch()) {
         $user["WORK_PHONE"] = CVoxImplantPhone::Normalize($user["WORK_PHONE"]);
         if ($user["WORK_PHONE"]) {
             VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["WORK_PHONE"], 'PHONE_MNEMONIC' => "WORK_PHONE"));
         }
         $user["PERSONAL_PHONE"] = CVoxImplantPhone::Normalize($user["PERSONAL_PHONE"]);
         if ($user["PERSONAL_PHONE"]) {
             VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["PERSONAL_PHONE"], 'PHONE_MNEMONIC' => "PERSONAL_PHONE"));
         }
         $user["PERSONAL_MOBILE"] = CVoxImplantPhone::Normalize($user["PERSONAL_MOBILE"]);
         if ($user["PERSONAL_MOBILE"]) {
             VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["PERSONAL_MOBILE"], 'PHONE_MNEMONIC' => "PERSONAL_MOBILE"));
         }
         $user["UF_PHONE_INNER"] = intval(preg_replace("/[^0-9]/i", "", $user["UF_PHONE_INNER"]));
         if ($user["UF_PHONE_INNER"] > 0 && $user["UF_PHONE_INNER"] < 10000) {
             VI\PhoneTable::add(array('USER_ID' => intval($user['ID']), 'PHONE_NUMBER' => $user["UF_PHONE_INNER"], 'PHONE_MNEMONIC' => "UF_PHONE_INNER"));
         }
         $count++;
     }
     if ($count > 0) {
         $offset = $offset + 100;
         COption::SetOptionInt("voximplant", "sync_offset", $offset);
         return "CVoxImplantPhone::SynchronizeUserPhones();";
     } else {
         return false;
     }
 }
示例#2
0
 /**
  * @override
  * @return bool
  */
 protected function extractDataFromCache()
 {
     if ($this->arParams['CACHE_TYPE'] == 'N') {
         return false;
     }
     $userGroups = implode(",", Bitrix\Main\UserTable::getUserGroupIds($this->getUserId()));
     return !$this->StartResultCache(false, $userGroups);
 }
示例#3
0
 public static function GetDataForPopup($callId, $phone, $userId = 0)
 {
     if (strlen($phone) <= 0 || !CModule::IncludeModule('crm')) {
         return false;
     }
     if ($userId > 0) {
         $findParams = array('USER_ID' => $userId);
     } else {
         $findParams = array('ENABLE_EXTENDED_MODE' => false);
     }
     $crm = CCrmSipHelper::findByPhoneNumber((string) $phone, $findParams);
     if ($crm) {
         $dealStatuses = CCrmViewHelper::GetDealStageInfos();
         $entity = '';
         $entityData = array();
         $entities = array();
         $arResult = array('FOUND' => 'Y', 'CONTACT' => array(), 'COMPANY' => array(), 'ACTIVITIES' => array(), 'DEALS' => array(), 'RESPONSIBILITY' => array());
         if (isset($crm['CONTACT'])) {
             $entity = 'CONTACT';
             $entityData = $crm[$entity][0];
             $arResult['CONTACT'] = array('NAME' => $entityData['FORMATTED_NAME'], 'POST' => $entityData['POST'], 'PHOTO' => '');
             if (intval($entityData['PHOTO']) > 0) {
                 $arPhoto = CFile::ResizeImageGet($entityData['PHOTO'], array('width' => 37, 'height' => 37), BX_RESIZE_IMAGE_EXACT, false, false, true);
                 $arResult['CONTACT']['PHOTO'] = $arPhoto['src'];
             }
             $arResult['COMPANY'] = $entityData['COMPANY_TITLE'];
             $arResult['CONTACT_DATA'] = array('ID' => $entityData['ID']);
         } else {
             if (isset($crm['LEAD'])) {
                 $entity = 'LEAD';
                 $entityData = $crm[$entity][0];
                 $arResult['CONTACT'] = array('ID' => 0, 'NAME' => !empty($entityData['FORMATTED_NAME']) ? $entityData['FORMATTED_NAME'] : $entityData['TITLE'], 'POST' => $entityData['POST'], 'PHOTO' => '');
                 $arResult['COMPANY'] = $entityData['COMPANY_TITLE'];
                 $arResult['LEAD_DATA'] = array('ID' => $entityData['ID'], 'ASSIGNED_BY_ID' => $entityData['ASSIGNED_BY_ID']);
             } else {
                 if (isset($crm['COMPANY'])) {
                     $entity = 'COMPANY';
                     $entityData = $crm[$entity][0];
                     $arResult['COMPANY'] = $entityData['TITLE'];
                     $arResult['COMPANY_DATA'] = array('ID' => $entityData['ID']);
                 }
             }
         }
         if ($entityData['ASSIGNED_BY_ID'] > 0) {
             $ar = Bitrix\Main\UserTable::getById($entityData['ASSIGNED_BY_ID']);
             if ($user = $ar->fetch()) {
                 $arPhoto = CFile::ResizeImageGet($user['PERSONAL_PHOTO'], array('width' => 37, 'height' => 37), BX_RESIZE_IMAGE_EXACT, false, false, true);
                 $arResult['RESPONSIBILITY'] = array('ID' => $user['ID'], 'NAME' => CUser::FormatName(CSite::GetNameFormat(false), $user, true, false), 'PHOTO' => $arPhoto ? $arPhoto['src'] : '', 'POST' => $user['WORK_POSITION']);
             }
         }
         if (isset($entityData['SHOW_URL'])) {
             $arResult['SHOW_URL'] = $entityData['SHOW_URL'];
         }
         if (isset($entityData['ACTIVITY_LIST_URL'])) {
             $arResult['ACTIVITY_URL'] = $entityData['ACTIVITY_LIST_URL'];
         }
         if (isset($entityData['INVOICE_LIST_URL'])) {
             $arResult['INVOICE_URL'] = $entityData['INVOICE_LIST_URL'];
         }
         if (isset($entityData['DEAL_LIST_URL'])) {
             $arResult['DEAL_URL'] = $entityData['DEAL_LIST_URL'];
         }
         $activityId = CCrmActivity::GetIDByOrigin('VI_' . $callId);
         if ($activityId) {
             $arResult['CURRENT_CALL_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Activity, $activityId);
             if ($arResult['CURRENT_CALL_URL'] !== '') {
                 $arResult['CURRENT_CALL_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CURRENT_CALL_URL'], array("disable_storage_edit" => 'Y'));
             }
         }
         if (isset($crm['CONTACT']) && isset($crm['COMPANY'])) {
             $entities = array('CONTACT', 'COMPANY', 'LEAD');
         } else {
             if (isset($crm['CONTACT']) && isset($crm['LEAD']) && !isset($crm['COMPANY'])) {
                 $entities = array('CONTACT', 'LEAD');
             } else {
                 if (isset($crm['LEAD']) && isset($crm['COMPANY']) && !isset($crm['CONTACT'])) {
                     $entities = array('LEAD', 'COMPANY');
                 } else {
                     $entities = array($entity);
                 }
             }
         }
         foreach ($entities as $entity) {
             if (isset($crm[$entity][0]['ACTIVITIES'])) {
                 foreach ($crm[$entity][0]['ACTIVITIES'] as $activity) {
                     if ($activity['ID'] == $activityId) {
                         continue;
                     }
                     $overdue = 'N';
                     if (strlen($activity['DEADLINE']) > 0 && MakeTimeStamp($activity['DEADLINE']) < time()) {
                         $overdue = 'Y';
                     }
                     $arResult['ACTIVITIES'][$activity['ID']] = array('TITLE' => $activity['SUBJECT'], 'DATE' => strlen($activity['DEADLINE']) > 0 ? $activity['DEADLINE'] : $activity['END_TIME'], 'OVERDUE' => $overdue, 'URL' => $activity['SHOW_URL']);
                 }
                 if (!empty($arResult['ACTIVITIES'])) {
                     $arResult['ACTIVITIES'] = array_values($arResult['ACTIVITIES']);
                 }
             }
             if (isset($crm[$entity][0]['DEALS'])) {
                 foreach ($crm[$entity][0]['DEALS'] as $deal) {
                     $opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID']);
                     if (strpos('&', $opportunity)) {
                         $opportunity = CCrmCurrency::MoneyToString($deal['OPPORTUNITY'], $deal['CURRENCY_ID'], '#') . ' ' . $deal['CURRENCY_ID'];
                     }
                     $opportunity = str_replace('.00', '', $opportunity);
                     $arResult['DEALS'][$deal['ID']] = array('ID' => $deal['ID'], 'TITLE' => $deal['TITLE'], 'STAGE' => $dealStatuses[$deal['STAGE_ID']]['NAME'], 'STAGE_COLOR' => $dealStatuses[$deal['STAGE_ID']]['COLOR'] ? $dealStatuses[$deal['STAGE_ID']]['COLOR'] : "#5fa0ce", 'OPPORTUNITY' => $opportunity, 'URL' => $deal['SHOW_URL']);
                 }
                 if (!empty($arResult['DEALS'])) {
                     $arResult['DEALS'] = array_values($arResult['DEALS']);
                 }
             }
         }
     } else {
         $arResult = array('FOUND' => 'N');
         $userPermissions = CCrmPerms::GetUserPermissions($userId);
         if (CCrmLead::CheckCreatePermission($userPermissions)) {
             $arResult['LEAD_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Lead, 0);
             if ($arResult['LEAD_URL'] !== '') {
                 $arResult['LEAD_URL'] = CCrmUrlUtil::AddUrlParams($arResult['LEAD_URL'], array("phone" => (string) $phone, 'origin_id' => 'VI_' . $callId));
             }
         }
         if (CCrmContact::CheckCreatePermission($userPermissions)) {
             $arResult['CONTACT_URL'] = CCrmOwnerType::GetEditUrl(CCrmOwnerType::Contact, 0);
             if ($arResult['CONTACT_URL'] !== '') {
                 $arResult['CONTACT_URL'] = CCrmUrlUtil::AddUrlParams($arResult['CONTACT_URL'], array("phone" => (string) $phone, 'origin_id' => 'VI_' . $callId));
             }
         }
     }
     return $arResult;
 }