1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
converter.php
См. документацию.
1<?php
2namespace Bitrix\Sale\Exchange\OneC;
3
4
5use Bitrix\Main\ArgumentOutOfRangeException;
6use Bitrix\Main\Type\DateTime;
7use Bitrix\Sale\Exchange\EntityType;
8use Bitrix\Sale\Exchange\IConverter;
9use Bitrix\Sale\Exchange\ImportOneCBase;
10use Bitrix\Sale\Exchange\ISettings;
11
17abstract class Converter implements IConverter
18{
20 const KOEF_DEFAULT = 1;
22
24 protected $settings = null;
25
26 protected $entityTypeId;
27 protected $documentTypeId;
28
30 private static $instances = null;
31
37 public static function getInstance($typeId)
38 {
39 if(!is_int($typeId))
40 {
41 $typeId = (int)$typeId;
42 }
43
44 if(!DocumentType::IsDefined($typeId))
45 {
47 }
48
49 if(self::$instances === null || !isset(self::$instances[$typeId]))
50 {
51 if(self::$instances === null)
52 {
53 self::$instances = array();
54 }
55
56 if(!isset(self::$instances[$typeId]))
57 {
58 self::$instances[$typeId] = ConverterFactory::create($typeId);
59 }
60 }
61 return self::$instances[$typeId];
62 }
63
67 abstract protected function getFieldsInfo();
68
72 public function getSettings()
73 {
74 return $this->settings;
75 }
76
77 public function getEntityTypeId()
78 {
79 return $this->entityTypeId;
80 }
81
82 public function getDocmentTypeId()
83 {
84 return $this->documentTypeId;
85 }
86
93
98 protected function externalizeField(&$value, $fieldInfo=null)
99 {
100 if($value<>'')
101 {
102 switch($fieldInfo['TYPE'])
103 {
104 case 'text':
105 $value = self::toText($value);
106 break;
107 case 'time':
108 if($value instanceof DateTime)
109 $value = \CDatabase::FormatDate($value->toString(), \CSite::GetDateFormat("FULL", LANG), "HH:MI:SS");
110 break;
111 case 'date':
112 if($value instanceof DateTime)
113 $value = \CDatabase::FormatDate($value->toString(), \CSite::GetDateFormat("FULL", LANG), "YYYY-MM-DD");
114 break;
115 case 'datetime':
116 if($value instanceof DateTime)
117 $value = \CDatabase::FormatDate($value->toString(), \CSite::GetDateFormat("FULL", LANG), "YYYY-MM-DD HH:MI:SS");
118 break;
119 case 'bool':
120 $value = $value == 'Y'? 'true':'false';
121 break;
122 case 'int':
123 $value = intval($value);
124 break;
125 }
126 }
127 }
128
133 protected static function toText($value)
134 {
135 $value = preg_replace('/<style[^>]*>.*?<\/style>/is', '', $value);
136 $value = preg_replace('/<blockquote[^>]*>.*?<\/blockquote>/is', '', $value);
137 $value = preg_replace('/<script[^>]*>.*?<\/script>/is', '', $value);
138
139 return html_entity_decode(
140 strip_tags(
141 preg_replace('/(<br[^>]*>)+/isu', "\n", $value)
142 )
143 );
144 }
145
150 public static function normalizeExternalCode($code)
151 {
152 $xml_id = $code;
153 list($productXmlId, $offerXmlId) = explode("#", $xml_id, 2);
154 if ($productXmlId === $offerXmlId)
155 $xml_id = $productXmlId;
156
157 return $xml_id;
158 }
159
165 protected function externalizeRekv(array $rekv, array $info)
166 {
167 $result = array();
168 $rowId=0;
169 foreach($rekv as $kRekv=>$vRekv)
170 {
171 foreach($info['FIELDS'] as $name=>$fieldInfo)
172 {
173 $value='';
174 switch($name)
175 {
176 case 'NAME':
177 $value = $kRekv;
178 break;
179 case 'VALUE':
180 $value = $vRekv;
181 if($value instanceof DateTime)
182 $fieldInfo['TYPE'] = 'datetime';
183 break;
184 }
185 $this->externalizeField($value, $fieldInfo);
186 $result[$rowId][$name] = $value;
187 }
188 $rowId++;
189 }
190 return $result;
191 }
192
198 protected function externalizeRekvValue($kRekv, $vRekv, array $info)
199 {
200 $result = array();
201 foreach($info['FIELDS'] as $name=>$fieldInfo)
202 {
203 $value='';
204 switch($name)
205 {
206 case 'NAME':
207 $value = DocumentBase::getLangByCodeField($kRekv);
208 break;
209 case 'VALUE':
210 $value = $vRekv;
211 break;
212 }
213 $this->externalizeField($value, $fieldInfo);
214 $result[$name] = $value;
215 }
216 return $result;
217 }
218
223 protected function modifyTrim(array $fields)
224 {
225
226 $result = array();
227 foreach ($fields as $key=>$value)
228 {
229 if(is_array($value))
230 {
231 if(count($value)>0)
232 {
233 if($key === 'REK_VALUES' || $key === 'ADDRESS_FIELD' || $key === 'CONTACT' || $key === 'REPRESENTATIVE')
234 {
235 $groupFieldValues = array();
236 foreach ($value as $k=>$v)
237 {
238 if($v['VALUE']=='')
239 {
240 unset($fields[$key][$k]);
241 }
242 $groupFieldValues = $fields[$key];
243 }
244 if(count($groupFieldValues)>0)
245 $result[$key] = $groupFieldValues;
246 else
247 unset($fields[$key]);
248 }
249 else
250 {
251 $value = $this->modifyTrim($value);
252 if(count($value)>0)
253 $result[$key]=$value;
254 }
255 }
256 }
257 else
258 {
259 if($value<>'')
260 $result[$key]=$value;
261 }
262 }
263
264 return $result;
265 }
266
271 static protected function getSiteNameByLid($lid)
272 {
273 static $sites;
274
275 if($sites === null)
276 {
277 $res = \CSite::getList("sort", "desc");
278 while ($site = $res->fetch())
279 {
280 $sites[$site['LID']]=$site['NAME'];
281 }
282
283 if(!is_array($sites))
284 {
285 $sites = array();
286 }
287 }
288 return isset($sites[$lid]) ? $sites[$lid]:'';
289 }
290
292 {
294
295 if(is_array($fields))
296 {
297 foreach($fields as $k=>$items)
298 {
299 foreach($items as $productXML_ID => $item)
300 {
302 {
303 unset($result[$k][$productXML_ID]);
304
307 }
308 }
309 }
310 }
311 return $result;
312 }
313}
static isDefined($typeID)
Определения entitytype.php:46
const UNDEFINED
Определения entitytype.php:7
externalizeField(&$value, $fieldInfo=null)
Определения converter.php:98
const CURRENCY_RATE_DEFAULT
Определения converter.php:21
static toText($value)
Определения converter.php:133
modifyItemIdByItemName($fields)
Определения converter.php:291
externalizeRekv(array $rekv, array $info)
Определения converter.php:165
externalizeRekvValue($kRekv, $vRekv, array $info)
Определения converter.php:198
static getSiteNameByLid($lid)
Определения converter.php:271
const MEASURE_CODE_DEFAULT
Определения converter.php:19
static getInstance($typeId)
Определения converter.php:37
init(ISettings $settings, $entityTypeId=EntityType::UNDEFINED, $documentTypeId=DocumentType::UNDEFINED)
Определения converter.php:87
modifyTrim(array $fields)
Определения converter.php:223
static normalizeExternalCode($code)
Определения converter.php:150
static getLangByCodeField($code)
Определения documentbase.php:876
static isDefined($typeID)
Определения documenttype.php:37
$sites
Определения clear_component_cache.php:15
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if($NS['step']==6) if( $NS[ 'step']==7) if(COption::GetOptionInt('main', 'disk_space', 0) > 0) $info
Определения backup.php:924
$name
Определения menu_edit.php:35
$settings
Определения product_settings.php:43
if(empty($signedUserToken)) $key
Определения quickway.php:257
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
$items
Определения template.php:224
$k
Определения template_pdf.php:567
$site
Определения yandex_run.php:614
$fields
Определения yandex_run.php:501