Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userprofileimport.php
1<?php
3
4
9
11{
12 public function __construct()
13 {
14 $this->fields = new Sale\Internals\Fields();
15 }
16
20 public function getOwnerTypeId()
21 {
23 }
24
30 public function add(array $params)
31 {
32 $result = new Sale\Result();
33
34 $profileId = null;
35 $fields = $params['TRAITS'];
36 $property = $params["ORDER_PROP"];
37
38 $errorList = [];
39 $fields['ID'] = $this->registerUser($fields, $errorList);
40
41 if (!empty($errorList))
42 {
43 foreach($errorList as $error)
44 {
45 $result->addError(new Error(str_replace('<br>','', $error['TEXT'])));
46 }
47 }
48 elseif(intval($fields['ID'])>0)
49 {
50 $propertyOrders = static::getPropertyOrdersByPersonalTypeId($fields["PERSON_TYPE_ID"]);
51
52 if(is_array($propertyOrders))
53 {
54 foreach($propertyOrders as $filedsProperty)
55 {
56 $propertyId = $filedsProperty["ID"];
57 if(array_key_exists($propertyId, $property))
58 {
59 $propertyByConfigValue = $property[$propertyId];
60 if($profileId == null)
61 {
62 if(!empty($propertyByConfigValue))
63 {
64 $profileId = \CSaleOrderUserProps::Add(array(
65 "NAME" => $fields["AGENT_NAME"],
66 "USER_ID" => $fields['ID'],
67 "PERSON_TYPE_ID" => $fields['PERSON_TYPE_ID'],
68 "XML_ID" => $fields["XML_ID"],
69 "VERSION_1C" => $fields["VERSION_1C"]
70 ));
71 }
72 }
73
74 \CSaleOrderUserPropsValue::Add(array(
75 "USER_PROPS_ID" => $profileId,
76 "ORDER_PROPS_ID" => $propertyId,
77 "NAME" => $filedsProperty["NAME"],
78 "VALUE" => $propertyByConfigValue
79 ));
80 }
81 }
82 }
83 }
84
85 if($result->isSuccess())
86 {
87 $user = new static();
88 $user->setFields($fields);
89 $this->setEntity($user);
90 }
91
92 return $result;
93 }
94
100 public function update(array $params)
101 {
102 $entity = $this->getEntity();
103
104 if($entity->getId()>0)
105 static::updateEmptyXmlId($entity->getId(), $params['TRAITS']['XML_ID']);
106
107 return new Sale\Result();
108 }
109
115 public function delete(array $params = null)
116 {
117 return new Sale\Result();
118 }
119
124 protected function checkFields(array $fields)
125 {
126 return new Sale\Result();
127 }
128
133 public function load(array $fields)
134 {
135 $result = $this->checkFields($fields);
136
137 if($result->isSuccess())
138 {
139 if(!empty($fields['ID']))
140 {
141 $user = UserTable::getById($fields['ID']);
142 if($fields = $user->fetch())
143 {
144 $userProfile = new static();
145 $userProfile->setFields($fields);
146
147 $this->setEntity($userProfile);
148 }
149 }
150 }
151
152 return $result;
153 }
154
158 public function getId()
159 {
160 $entity = $this->getEntity();
161 if(!empty($entity))
162 {
163 return $entity->getField('ID');
164 }
165 return null;
166 }
167
171 public function isImportable()
172 {
173 return $this->settings->isImportableFor($this->getOwnerTypeId());
174 }
175
179 public function refreshData(array $fields)
180 {
181 }
182
186 public static function getFieldExternalId()
187 {
188 return 'XML_ID';
189 }
190}