4use Bitrix\Crm\CompanyTable;
5use Bitrix\Crm\Requisite\EntityLink;
6use Bitrix\Crm\Settings\CompanySettings;
10use Bitrix\SalesCenter\Integration\CrmManager;
38 protected static function addNewCompany(
string $title,
string $phone): void
40 if (!Loader::includeModule(
'crm'))
45 $company = new \CCrmCompany(
false);
48 'OPENED' => CompanySettings::getCurrent()->getOpenedFlag() ?
'Y' :
'N',
49 'IS_MY_COMPANY' =>
'Y',
54 'VALUE_TYPE' =>
'WORK'
59 $company->add($fields);
68 public static function setContacts(
int $siteId, array $data): void
70 $shopStoredData = unserialize(
Manager::getOption(self::OPTION_DATA_CODE,
''), [
'allowed_classes' =>
false]);
71 $shopStoredData = is_array($shopStoredData) ? $shopStoredData : [];
72 if (isset($shopStoredData[$siteId]))
74 unset($shopStoredData[$siteId]);
76 $shopStoredData[$siteId] = [];
82 $data[self::COMPANY_KEY],
83 $data[self::PHONE_KEY]
87 foreach (self::DEFAULT_CONTACTS as $key => $value)
89 if (!($data[$key] ??
''))
93 if ($data[$key] !== ($contacts[$key] ??
''))
95 $shopStoredData[$siteId][$key] = $data[$key];
109 static $contacts =
null;
111 if ($contacts ===
null)
121 !Loader::includeModule(
'crm')
122 || !Loader::includeModule(
'salescenter')
133 $defaultCompanyId = EntityLink::getDefaultMyCompanyId();
135 if (!$contacts && $defaultCompanyId === 0)
145 $phones = CrmManager::getPublishedCompanyPhone();
150 $emails = CrmManager::getPublishedCompanyEmail();
165 $cache = new \CPHPCache;
166 $cacheManager =
$GLOBALS[
'CACHE_MANAGER'];
168 $cacheDir =
'/landing/crm_contacts';
169 if ($cache->initCache(8640000, $cacheTag . $siteId, $cacheDir))
171 return $cache->getVars();
174 $cache->startDataCache();
175 $cacheManager->startTagCache($cacheDir);
176 $cacheManager->registerTag($cacheTag);
184 $shopData = unserialize(
Manager::getOption(self::OPTION_DATA_CODE,
''), [
'allowed_classes' =>
false]);
185 if (isset($shopData[$siteId]))
187 $contacts = array_merge(
193 foreach ($contacts as &$value)
195 if (is_array($value))
197 $value = array_shift($value);
202 $cacheManager->endTagCache();
203 $cache->endDataCache($contacts);
214 if (defined(
'BX_COMP_MANAGED_CACHE'))
227 $companyId = $fields[
'ID'] ??
null;
228 if ($companyId === EntityLink::getDefaultMyCompanyId())
246 $replace[
'#crmCompanyTitle'] = \htmlspecialcharsbx($crmContacts[
'COMPANY']);
248 if (!empty($crmContacts[
'PHONE']))
250 $phone = $crmContacts[
'PHONE'];
251 $phone = \htmlspecialcharsbx($phone);
252 $replace[
'#crmPhoneTitle1'] = $phone;
253 if ($attributesReplace)
255 $replace[
'#crmPhone1'] = $phone;
259 if (!empty($crmContacts[
'EMAIL']))
261 $email = $crmContacts[
'EMAIL'];
262 $email = \htmlspecialcharsbx($email);
263 $replace[
'#crmEmailTitle1'] = $email;
264 if ($attributesReplace)
266 $replace[
'#crmEmail1'] = $email;
281 $companyId = (int)(explode(
"_", $xmlId)[1] ?? 0);
283 if (isset($requisites[$companyId][
'companyTitle']) && $companyId > 0)
285 $companyTitle = $requisites[$companyId][
'companyTitle'];
287 if (!isset($companyTitle))
289 $companyTitle =
'Company24';
291 $replace[
'#requisiteCompanyTitle'] = $companyTitle;
302 if (!Loader::includeModule(
'crm'))
309 $companies = CompanyTable::query()
310 ->setSelect([
'ID',
'TITLE'])
311 ->where(
'IS_MY_COMPANY',
'Y')
312 ->setOrder([
'DATE_MODIFY' =>
'desc'])
315 foreach ($companies as $company)
318 $bankRequisites = [];
319 $requisitesRaw = \CCrmEntitySelectorHelper::PrepareRequisiteData(
320 \CCrmOwnerType::Company,
323 'VIEW_FORMATTED' =>
true,
324 'SKIP_CHECK_MY_COMPANY_PERMISSION' =>
true,
327 foreach ($requisitesRaw as $requisite)
329 $requisiteData = Encoding::convertEncoding(json_decode($requisite[
'requisiteData'], 1),
'UTF-8', SITE_CHARSET);
330 if (!empty($requisiteData[
'viewData'][
'fields']))
332 $requisites[$requisite[
'requisiteId']] = [
333 'id' => $requisite[
'requisiteId'],
334 'title' => $requisiteData[
'viewData'][
'title'] ??
null,
335 'data' => $requisiteData[
'viewData'][
'fields'],
338 if (!empty($requisiteData[
'bankDetailViewDataList']))
340 $bankRequisites[$requisite[
'requisiteId']] = [
341 'id' => $requisite[
'requisiteId'],
342 'title' => $requisiteData[
'viewData'][
'title'] ??
null,
343 'bankData' => $requisiteData[
'bankDetailViewDataList'][0][
'viewData'][
'fields'] ??
null,
348 if (empty($requisites))
353 $fullData[$company[
'ID']] = [
354 'companyId' => $company[
'ID'],
355 'companyTitle' => $company[
'TITLE'],
356 'requisites' => $requisites,
357 'bankRequisites' => $bankRequisites,
372 $requisitesPlainList = [];
373 foreach ($requisites as $company)
375 foreach ($company[$requisitesType] as $requisite)
377 $requisitesPlainList[
"{$company['companyId']}_{$requisite['id']}"]
378 =
"{$company['companyTitle']}: {$requisite['title']} : {$requisite['id']}";
382 return $requisitesPlainList;
392 if (!Loader::includeModule(
'crm'))
399 $res = \CCrmFieldMulti::getList(
402 'ENTITY_ID' => \CCrmOwnerType::CompanyName,
403 'ELEMENT_ID' => $companyId,
406 while ($row = $res->Fetch())
408 $row = array_change_key_case($row);
409 $row[
'type_id'] = mb_strtolower($row[
'type_id']);
411 if (!isset($data[$row[
'type_id']]))
413 $data[$row[
'type_id']] = [];
415 $data[$row[
'type_id']][] = $row[
'value'];
static getReplaceRequisiteCompanyNameForContent(string $xmlId)
static getReplacesForContent(int $siteId, bool $attributesReplace=true)
static setContacts(int $siteId, array $data)
static getMyRequisitesPlainList(array $requisites=[], string $requisitesType='requisites')
static clearContactsCache()
static onAfterCompanyChange(array $fields)
static getCompanyCommunications(int $companyId)
static getContacts(int $siteId)
static addNewCompany(string $title, string $phone)
static getOption($code, $default=null)
static setOption($code, $value)
$GLOBALS['____1444769544']