Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
userprops.php
1<?php
8namespace Bitrix\Sale;
9
15
16Loc::loadMessages(__FILE__);
17
19{
20 private $profiles = array();
21 private static $instance;
22
23 function __construct()
24 {
25
26 }
27
31 public static function getInstance()
32 {
33
34 if(!isset(self::$instance))
35 {
36 self::$instance = new self();
37 }
38
39 return self::$instance;
40 }
41
46 public static function getList(array $parameters)
47 {
48 return UserPropsTable::getList($parameters);
49 }
50
54 public static function loadFromDB($parameters)
55 {
56 static::getInstance()->profiles = static::getList($parameters)->fetchAll();
57 }
58
64 public static function getFirstId($personTypeId, $userId)
65 {
66 if (empty(static::getInstance()->profiles))
67 {
68 static::loadFromDB(array(
69 'order' => array("DATE_UPDATE" => "DESC"),
70 'filter' => array(
71 "PERSON_TYPE_ID" => $personTypeId,
72 "USER_ID" => $userId
73 ),
74 ));
75 }
76
77 if (!empty(static::getInstance()->profiles) && is_array(static::getInstance()->profiles))
78 {
79 $profile = reset(static::getInstance()->profiles);
80 return $profile['ID'];
81 }
82
83 return false;
84 }
85
92 public static function checkCorrect($profileId, $personTypeId, $userId)
93 {
94 if (static::getList(array(
95 'filter' => array(
96 "ID" => $profileId,
97 "PERSON_TYPE_ID" => $personTypeId,
98 "USER_ID" => $userId
99 )))->fetch())
100 {
101 return true;
102 }
103 else
104 {
105 return false;
106 }
107 }
108
118 public static function loadProfiles($userId, $personTypeId = null, $profileId = null)
119 {
120 $result = new Result();
121 $userId = (int)$userId;
122
123 $resultData =
124 $filter =
125 $locationIdMap =
126 $locationCodeList = array();
127
128 if ($userId <= 0)
129 {
130 return $result->addError(new Error("EMPTY USER ID"));
131 }
132 else
133 {
134 $filter['USER_ID'] = $userId;
135 }
136
137 if ((int)$personTypeId > 0)
138 $filter['PERSON_TYPE_ID'] = (int)$personTypeId;
139
140 if ((int)$profileId > 0)
141 $filter['USER_PROPS_ID'] = (int)$profileId;
142
143 $userPropsValueData = Internals\UserPropsValueTable::getList(
144 array(
145 'filter' => $filter,
146 'select' => array(
147 'ORDER_PROPS_ID', 'USER_PROPS_ID', 'VALUE',
148 'PROFILE_NAME' => 'USER_PROPERTY.NAME',
149 'VALUE_ORIG' => 'VALUE',
150 'USER_ID' => 'USER_PROPERTY.USER_ID',
151 'PERSON_TYPE_ID' => 'USER_PROPERTY.PERSON_TYPE_ID',
152 'DATE_UPDATE' => 'USER_PROPERTY.DATE_UPDATE',
153 'MULTIPLE' => 'PROPERTY.MULTIPLE',
154 'TYPE' => 'PROPERTY.TYPE',
155 ),
156 'order' => array(
157 'USER_PROPERTY.DATE_UPDATE' => 'DESC',
158 'USER_PROPERTY.NAME' => 'ASC'
159 )
160 )
161 );
162
163 while ($propValue = $userPropsValueData->fetch())
164 {
165 if (($propValue['MULTIPLE'] === 'Y' || $propValue['TYPE'] === 'FILE')
166 && CheckSerializedData($propValue['VALUE'])
167 && ($serialisedValue = @unserialize($propValue['VALUE'], ['allowed_classes' => false])) !== false)
168 {
169 $propValue['VALUE'] = $serialisedValue;
170 }
171
172 if (!array_key_exists($propValue['PERSON_TYPE_ID'], $resultData))
173 $resultData[$propValue['PERSON_TYPE_ID']] = array();
174
175 $resultData[$propValue['PERSON_TYPE_ID']][$propValue['USER_PROPS_ID']]['NAME'] = $propValue['PROFILE_NAME'];
176
177 if ($propValue['TYPE'] === 'ENUM' && $propValue['MULTIPLE'] === 'Y')
178 {
179 $propValue['VALUE'] = explode(',', $propValue['VALUE']);
180 }
181 elseif ($propValue['TYPE'] === 'FILE' && !empty($propValue['VALUE']))
182 {
183 $fileIds = $propValue['VALUE'];
184 $propValue['VALUE'] = array();
185 if (is_array($fileIds))
186 {
187 foreach ($fileIds as $value)
188 {
189 if ($fileArray = \CFile::GetFileArray($value))
190 {
191 $propValue['VALUE'][] = $fileArray;
192 }
193 }
194 }
195 elseif ($fileArray = \CFile::GetFileArray($fileIds))
196 {
197 $propValue['VALUE'] = $fileArray;
198 }
199 }
200
201 $resultData[$propValue['PERSON_TYPE_ID']][$propValue['USER_PROPS_ID']]['VALUES'][$propValue['ORDER_PROPS_ID']] = $propValue['VALUE'];
202 $resultData[$propValue['PERSON_TYPE_ID']][$propValue['USER_PROPS_ID']]['VALUES_ORIG'][$propValue['ORDER_PROPS_ID']] = $propValue['VALUE_ORIG'];
203 }
204
205 $result->setData($resultData);
206
207 return $result;
208 }
209
217 public static function getProfileValues($profileId)
218 {
219 $result = array();
220 if ((int)$profileId <= 0)
221 {
222 return $result;
223 }
224
225 $userPropsValueData = Internals\UserPropsTable::getList(
226 array(
227 'filter' => array('=ID' => (int)$profileId),
228 'select' => array('ID','USER_ID', 'PERSON_TYPE_ID'),
229 'limit' => 1
230 )
231 );
232 $profile = $userPropsValueData->fetch();
233 if (!$profile )
234 {
235 return $result;
236 }
237 $resultLoading = static::loadProfiles($profile['USER_ID'], $profile['PERSON_TYPE_ID'], $profile['ID']);
238
239 if ($resultLoading->isSuccess())
240 {
241 $data = $resultLoading->getData();
242 $resultValue = $data[$profile['PERSON_TYPE_ID']][$profile['ID']]['VALUES'];
243 $result = !empty($resultValue) ? $resultValue : array();
244 }
245
246 return $result;
247 }
248}
static loadMessages($file)
Definition loc.php:64
static getProfileValues($profileId)
static checkCorrect($profileId, $personTypeId, $userId)
Definition userprops.php:92
static loadProfiles($userId, $personTypeId=null, $profileId=null)
static getList(array $parameters)
Definition userprops.php:46
static getFirstId($personTypeId, $userId)
Definition userprops.php:64
static loadFromDB($parameters)
Definition userprops.php:54