59 if ($userId == $USER->GetID())
61 $groups = $USER->GetUserGroupArray();
67 if (isset($cacheGroups[$userId]))
69 $groups = $cacheGroups[$userId];
74 $result = UserGroupTable::getList(array(
75 'select' => array(
'GROUP_ID'),
76 'filter' => array(
'USER_ID' => $userId)
80 while ($row = $result->fetch())
81 $groups []= $row[
'GROUP_ID'];
83 $cacheGroups[$userId] = $groups;
102 throw new SystemException(
'provide at least one operation', 0, __FILE__, __LINE__);
105 if (!is_array($groupId))
107 $groupId = array($groupId);
110 if (in_array(
'1', $groupId,
true) || \CMain::GetUserRight(
'sale', $groupId) >=
'W')
115 $operations = static::convertNamesToOperations($operations);
117 $result = static::getList(array(
119 'NAME' =>
'Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME',
122 '=ID' => $fromStatus,
123 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.GROUP_ID' => $groupId,
124 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME' => $operations,
128 while ($row = $result->fetch())
130 if (($key = array_search($row[
'NAME'], $operations)) !==
false)
132 unset($operations[$key]);
162 static $cacheAllowStatuses = array();
164 if (! is_array($groupId))
165 $groupId = array($groupId);
167 $cacheKey = md5(join(
'|', $groupId) .
"_".(is_array($fromStatus) ? join(
'|', $fromStatus) : $fromStatus));
169 if (in_array(
'1', $groupId,
true) || \CMain::GetUserRight(
'sale', $groupId) >=
'W')
171 if (!array_key_exists($cacheKey, $cacheAllowStatuses))
173 $result = static::getList(array(
176 'NAME' =>
'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'
179 '=TYPE' => static::TYPE,
180 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID),
186 while ($row = $result->fetch())
188 $cacheAllowStatuses[$cacheKey][$row[
'ID']] = $row[
'NAME'];
194 if (!array_key_exists($cacheKey, $cacheAllowStatuses))
196 $cacheAllowStatuses[$cacheKey] = array();
198 $dbRes = static::getList(array(
199 'select' => array(
'ID'),
201 '=ID' => $fromStatus,
202 '=TYPE' => static::TYPE,
203 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.GROUP_ID' => $groupId,
204 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME' =>
'sale_status_from',
211 $result = static::getList(array(
212 'select' => array(
'ID',
'NAME' =>
'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'),
214 '=TYPE' => static::TYPE,
215 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID,
216 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.GROUP_ID' => $groupId,
217 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME' =>
'sale_status_to',
219 'order' => array(
'SORT'),
222 while ($row = $result->fetch())
224 $cacheAllowStatuses[$cacheKey][$row[
'ID']] = $row[
'NAME'];
230 return $cacheAllowStatuses[$cacheKey] ?? [];
257 static $statusList = [];
259 if (!isset($statusList[static::TYPE]))
261 $statusList[static::TYPE] = [];
263 $result = static::getList([
265 'filter' => [
'=TYPE' => static::TYPE],
266 'order' => [
'SORT' =>
'ASC']
269 while ($row = $result->fetch())
271 $statusList[static::TYPE][$row[
'ID']] = $row[
'ID'];
275 return $statusList[static::TYPE];
288 'select' => [
"ID",
"NAME" =>
'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'],
290 '=TYPE' => static::TYPE,
292 'order' => [
'SORT' =>
'ASC']
297 $parameters[
'filter'][
'=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID'] = $lang;
299 elseif (defined(
"LANGUAGE_ID"))
301 $parameters[
'filter'][
'=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID'] = LANGUAGE_ID;
304 static $allStatusesNames = [];
306 if (!isset($allStatusesNames[static::TYPE]))
308 $allStatusesNames[static::TYPE] = [];
310 $result = static::getList($parameters);
311 while ($row = $result->fetch())
313 $allStatusesNames[static::TYPE][$row[
'ID']] = $row[
'NAME'];
317 return $allStatusesNames[static::TYPE];
342 static $cacheStatuses = array();
344 if (!is_array($groupId))
345 $groupId = array($groupId);
347 $cacheHash = md5(static::TYPE.
"|".join(
'_', $groupId).
"|".join(
'_', $operations));
349 if (!empty($cacheStatuses[$cacheHash]))
351 return $cacheStatuses[$cacheHash];
354 if (in_array(
'1', $groupId,
true) || \CMain::GetUserRight(
'sale', $groupId) >=
'W')
356 $statuses = static::getAllStatuses();
360 $statuses = static::getStatusesByGroupId($groupId, $operations);
363 $cacheStatuses[$cacheHash] = $statuses;
434 if (! ($statusId = $data[
'ID']) || ! is_string($statusId))
439 if ($languages = $data[
'LANG'])
441 unset($data[
'LANG']);
443 if (! is_array($languages))
444 throw new SystemException(
'invalid status LANG', 0, __FILE__, __LINE__);
447 $data[
'TYPE'] = static::TYPE;
451 if (! StatusTable::getById($statusId)->fetch())
453 StatusTable::add($data);
460 $installedLanguages = array();
462 $result = StatusLangTable::getList(array(
463 'select' => array(
'LID'),
464 'filter' => array(
'=STATUS_ID' => $statusId),
467 while ($row = $result->fetch())
469 $installedLanguages[$row[
'LID']] =
true;
472 foreach ($languages as $language)
474 if (! is_array($language))
475 throw new SystemException(
'invalid status language', 0, __FILE__, __LINE__);
477 if (! $installedLanguages[$language[
'LID']])
479 $language[
'STATUS_ID'] = $statusId;
481 StatusLangTable::add($language);