Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
companycard.php
1<?php
10
11use Bitrix\Crm\CompanyAddress;
12use Bitrix\Crm\EntityAddressType;
13use Bitrix\Crm\EntityRequisite;
14use Bitrix\Crm\Format;
15use Bitrix\Crm\Requisite;
18
19Loc::loadMessages(__FILE__);
20
26{
27 const DATA_PROVIDER_CODE = 'crm/requisites';
28
34 public static function getArray()
35 {
36 Loader::includeModule('crm');
37 $reqData = self::getRequisites();
38 if (!is_array($reqData))
39 {
40 $reqData = array();
41 }
42
43 $data = array();
44 $data['COMPANY_NAME'] = $reqData['RQ_COMPANY_NAME'];
45 if (!$data['COMPANY_NAME'])
46 {
47 $data['COMPANY_NAME'] = $reqData['RQ_NAME'];
48 }
49 $data['COMPANY_NAME'] = str_replace(array("'", '"'), '', $data['COMPANY_NAME']);
50
51 $data['PHONE'] = $reqData['RQ_PHONE'];
52 $data['ADDRESS'] = $reqData['COMPANY_ADDRESS'];
53
54 return array(
55 'CODE' => self::DATA_PROVIDER_CODE,
56 'EDIT_URL' => '/crm/configs/mycompany/',
57 'DATA' => $data
58 );
59 }
60
66 public static function getRequisites()
67 {
68 // get my company id
69 $myCompanyId = Requisite\EntityLink::getDefaultMyCompanyId();
70 if (!$myCompanyId)
71 {
72 return null;
73 }
74
75 // get requisites
76 $req = new EntityRequisite;
77 $res = $req->getList(array(
78 'filter' => array(
79 '=ENTITY_TYPE_ID' => \CCrmOwnerType::Company,
80 '=ENTITY_ID' => $myCompanyId
81 )
82 ));
83 $data = $res->fetch();
84 if (!$data)
85 {
86 return null;
87 }
88
89 // prepare requisites
90 $result = array();
91 foreach ($data as $key => $value)
92 {
93 if (mb_substr($key, 0, 3) == 'RQ_')
94 {
95 $result[$key] = $value;
96 }
97 }
98
99 // format person name
100 $result[EntityRequisite::PERSON_FULL_NAME] = \CUser::formatName(
101 Format\PersonNameFormatter::getFormat(),
102 array(
103 'NAME' => $result[EntityRequisite::PERSON_FIRST_NAME],
104 'LAST_NAME' => $result[EntityRequisite::PERSON_LAST_NAME],
105 'SECOND_NAME' => $result[EntityRequisite::PERSON_SECOND_NAME],
106 )
107 );
108
109 // get address requisites
110 $addresses = EntityRequisite::getAddresses($data['ID']);
111 $addressTypes = array(
112 EntityAddressType::Registered
113 );
114
115 $address = null;
116 foreach ($addressTypes as $addressType)
117 {
118 if (isset($addresses[$addressType]))
119 {
120 $address = $addresses[$addressType];
121 }
122 }
123
124 if (!$address && count($addresses) > 0)
125 {
126 $address = current($addresses);
127 }
128
129 if ($address && is_array($address))
130 {
131 $address = Format\AddressFormatter::getSingleInstance()->formatTextComma($address);
132 }
133 else
134 {
135 // get address from entity fields
136 $address = \CCrmCompany::getByID($myCompanyId, false);
137 if (!is_array($address))
138 {
139 $address = array();
140 }
141 if ($address['REG_ADDRESS'])
142 {
143 $addressTypeId = EntityAddressType::Registered;
144 }
145 else
146 {
147 $addressTypeId = EntityAddressType::Primary;
148 }
149
150 $address = Format\AddressFormatter::getSingleInstance()->formatTextComma(
151 CompanyAddress::mapEntityFields($address, ['TYPE_ID' => $addressTypeId])
152 );
153 }
154
155 $result['COMPANY_ADDRESS'] = $address;
156
157 return $result;
158 }
159}
static loadMessages($file)
Definition loc.php:64