Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
FacebookBrandPropertyCreator.php
1<?php
2
4
8use CLanguage;
9use CUserTypeEntity;
10
12{
13 private const BRAND_REFERENCE_NAME = 'FacebookBrandReference';
14 private const BRAND_REFERENCE_TABLE_NAME = 'b_catalog_facebook_brand_reference';
15 private const BRAND_PROPERTY_CODE = 'BRAND_FOR_FACEBOOK';
16
17 public static function createFacebookBrandProperty(): void
18 {
19 self::createProperty();
20 self::createHighLoadBlock();
21 }
22
23 private static function createProperty(): void
24 {
25 if (
26 !Loader::includeModule('crm')
27 || !Loader::includeModule('iblock')
28 )
29 {
30 return;
31 }
32
33 $crmCatalogIblockId = \Bitrix\Crm\Product\Catalog::getDefaultId();
34 $facebookBrandProperty = \CIBlockPropertyTools::getExistProperty(
35 $crmCatalogIblockId,
36 self::BRAND_PROPERTY_CODE
37 );
38 if ($facebookBrandProperty)
39 {
40 return;
41 }
42 \CIBlockPropertyTools::createProperty(
43 $crmCatalogIblockId,
44 self::BRAND_PROPERTY_CODE,
45 );
46 }
47
48 private static function createHighLoadBlock(): void
49 {
50 if (!Loader::includeModule('highloadblock'))
51 {
52 return;
53 }
54
55 $highLoadBlockResult = Highloadblock\HighloadBlockTable::getList([
56 'filter' => [
57 'NAME' => self::BRAND_REFERENCE_NAME,
58 'TABLE_NAME' => self::BRAND_REFERENCE_TABLE_NAME,
59 ],
60 'cache' => [
61 'ttl' => 86400,
62 ],
63 ]);
64
65 if ($highLoadBlockResult->fetch())
66 {
67 return;
68 }
69
70 $data = [
71 'NAME' => self::BRAND_REFERENCE_NAME,
72 'TABLE_NAME' => self::BRAND_REFERENCE_TABLE_NAME,
73 ];
74
75 $result = Highloadblock\HighloadBlockTable::add($data);
76 if (!$result->isSuccess())
77 {
78 return;
79 }
80
81 $highLoadBlockId = $result->getId();
82 $highLoadData = Highloadblock\HighloadBlockTable::getById($highLoadBlockId)->fetch();
83 Highloadblock\HighloadBlockTable::compileEntity($highLoadData);
84 $userFields = [
85 [
86 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
87 'FIELD_NAME' => 'UF_NAME',
88 'USER_TYPE_ID' => 'string',
89 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_NAME',
90 'SORT' => '100',
91 'MULTIPLE' => 'N',
92 'MANDATORY' => 'N',
93 'SHOW_FILTER' => 'N',
94 'SHOW_IN_LIST' => 'Y',
95 'EDIT_IN_LIST' => 'Y',
96 'IS_SEARCHABLE' => 'Y',
97 ],
98 [
99 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
100 'FIELD_NAME' => 'UF_FILE',
101 'USER_TYPE_ID' => 'file',
102 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_FILE',
103 'SORT' => '200',
104 'MULTIPLE' => 'N',
105 'MANDATORY' => 'N',
106 'SHOW_FILTER' => 'N',
107 'SHOW_IN_LIST' => 'Y',
108 'EDIT_IN_LIST' => 'Y',
109 'IS_SEARCHABLE' => 'Y',
110 ],
111 [
112 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
113 'FIELD_NAME' => 'UF_LINK',
114 'USER_TYPE_ID' => 'string',
115 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_LINK',
116 'SORT' => '300',
117 'MULTIPLE' => 'N',
118 'MANDATORY' => 'N',
119 'SHOW_FILTER' => 'N',
120 'SHOW_IN_LIST' => 'Y',
121 'EDIT_IN_LIST' => 'Y',
122 'IS_SEARCHABLE' => 'Y',
123 ],
124 [
125 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
126 'FIELD_NAME' => 'UF_DESCRIPTION',
127 'USER_TYPE_ID' => 'string',
128 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_DESCR',
129 'SORT' => '400',
130 'MULTIPLE' => 'N',
131 'MANDATORY' => 'N',
132 'SHOW_FILTER' => 'N',
133 'SHOW_IN_LIST' => 'Y',
134 'EDIT_IN_LIST' => 'Y',
135 'IS_SEARCHABLE' => 'Y',
136 ],
137 [
138 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
139 'FIELD_NAME' => 'UF_FULL_DESCRIPTION',
140 'USER_TYPE_ID' => 'string',
141 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_FULL_DESCR',
142 'SORT' => '500',
143 'MULTIPLE' => 'N',
144 'MANDATORY' => 'N',
145 'SHOW_FILTER' => 'N',
146 'SHOW_IN_LIST' => 'Y',
147 'EDIT_IN_LIST' => 'Y',
148 'IS_SEARCHABLE' => 'Y',
149 ],
150 [
151 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
152 'FIELD_NAME' => 'UF_SORT',
153 'USER_TYPE_ID' => 'double',
154 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_SORT',
155 'SORT' => '600',
156 'MULTIPLE' => 'N',
157 'MANDATORY' => 'N',
158 'SHOW_FILTER' => 'N',
159 'SHOW_IN_LIST' => 'Y',
160 'EDIT_IN_LIST' => 'Y',
161 'IS_SEARCHABLE' => 'N',
162 ],
163 [
164 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
165 'FIELD_NAME' => 'UF_EXTERNAL_CODE',
166 'USER_TYPE_ID' => 'string',
167 'XML_ID' => 'UF_BRAND_FOR_FACEBOOK_EXTERNAL_CODE',
168 'SORT' => '700',
169 'MULTIPLE' => 'N',
170 'MANDATORY' => 'N',
171 'SHOW_FILTER' => 'N',
172 'SHOW_IN_LIST' => 'Y',
173 'EDIT_IN_LIST' => 'Y',
174 'IS_SEARCHABLE' => 'N',
175 ],
176 [
177 'ENTITY_ID' => 'HLBLOCK_' . $highLoadBlockId,
178 'FIELD_NAME' => 'UF_XML_ID',
179 'USER_TYPE_ID' => 'string',
180 'XML_ID' => 'UF_XML_ID',
181 'SORT' => '800',
182 'MULTIPLE' => 'N',
183 'MANDATORY' => 'Y',
184 'SHOW_FILTER' => 'N',
185 'SHOW_IN_LIST' => 'Y',
186 'EDIT_IN_LIST' => 'Y',
187 'IS_SEARCHABLE' => 'N',
188 ],
189 ];
190
191 $languageIds = [];
192 $languageResult = CLanguage::GetList();
193 while($language = $languageResult->Fetch())
194 {
195 $languageIds[] = $language['LID'];
196 }
197
198 $userTypeEntity = new CUserTypeEntity;
199 foreach ($userFields as $userField)
200 {
201 $userTypeResult = CUserTypeEntity::GetList(
202 [],
203 [
204 'ENTITY_ID' => $userField['ENTITY_ID'],
205 'FIELD_NAME' => $userField['FIELD_NAME'],
206 ]
207 );
208 if ($userTypeResult->Fetch())
209 {
210 continue;
211 }
212
213 $labelNames = [];
214 foreach($languageIds as $languageId)
215 {
216 $messages = Loc::loadLanguageFile(__FILE__, $languageId);
217 $labelNames[$languageId] = $messages[$userField['FIELD_NAME']];
218 }
219
220 $userField['EDIT_FORM_LABEL'] = $labelNames;
221 $userField['LIST_COLUMN_LABEL'] = $labelNames;
222 $userField['LIST_FILTER_LABEL'] = $labelNames;
223
224 $userTypeEntity->Add($userField);
225 }
226 }
227}
static loadLanguageFile($file, $language=null, $normalize=true)
Definition loc.php:224