Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
client.php
1<?php
3
5use \Bitrix\Sale\Exchange\Integration\Service\Batchable;
6
7abstract class Client
8{
12 abstract protected function getClient();
13
14 public function refresh(array $params)
15 {
16 $list = $this->resolve($params);
17
18 if(count($list)>0)
19 {
20 $void = $this
21 ->diff($list)
22 ->toArray();
23
24 if(count($void)>0)
25 {
26 $this->adds($void);
27 }
28 }
29 return $this;
30 }
31
32 public function resolve(array $params)
33 {
34 $client = $this->getClient();
35 return $client::resolveFieldsValuesFromOrderList($params);
36 }
37
38 public function diff(array $params)
39 {
40 $client = $this->getClient();
41 $client->init($params);
42
43 $relationList = $client->relationListDstEntity();
44 $res = count($relationList)>0 ? $client::proxyList(['ID'=>$relationList]):[];
45
46 if(isset($res['error']) == false)
47 {
48 $list = [];
49 foreach($res as $fields)
50 {
51 $list[] = $fields['ID'];
52 }
53 $client->relationDeleteByDstEntity($list);
54 }
55 else
56 {
58 }
59 return $client->relationVoid();
60 }
61
62 public function adds(array $params)
63 {
64 $client = $this->getClient();
65
66 $params = static::prepareFields($params);
67 $client->init($params);
68 $client->adds();
69
70 return $client
71 ->getCollection();
72 }
73
74 static protected function prepareFields(array $params)
75 {
76 $result = [];
77
78 foreach ($params as $index=>$param)
79 {
80 if(isset($param['EMAIL']))
81 {
82 $param['EMAIL'] = [
83 0 => ['VALUE'=>$param['EMAIL'], 'VALUE_TYPE'=>'WORK']
84 ];
85 }
86
87 if(isset($param['PHONE']))
88 {
89 $param['PHONE'] = [
90 0 => ['VALUE'=>$param['PHONE']]
91 ];
92 }
93
94 $result[$index] = $param;
95 }
96
97 return $result;
98 }
99}