6use Bitrix\Sale\Internals\StatusTable;
7use Bitrix\Sale\Internals\StatusLangTable;
8use Bitrix\Main\UserGroupTable;
9use Bitrix\Main\SystemException;
10use Bitrix\Main\Localization\Loc;
12Loc::loadMessages(__FILE__);
31 if (static::TYPE !==
'')
33 if (!isset($parameters[
'filter']))
35 $parameters[
'filter'] = [
'=TYPE' => static::TYPE];
39 $parameters[
'filter'] = [
40 '=TYPE' => static::TYPE,
46 return StatusTable::getList($parameters);
67 if (isset($cacheGroups[
$userId]))
75 'select' =>
array(
'GROUP_ID'),
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);
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]);
150 return static::getAllowedGroupStatuses(static::getUserGroups(
$userId), $fromStatus);
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))
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();
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',
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] ?? [];
237 private static function convertNamesToOperations($names)
239 $operations =
array();
241 foreach ($names as
$name)
243 $operations[] =
'sale_status_'.mb_strtolower(
$name);
265 'filter' => [
'=TYPE' => static::TYPE],
266 'order' => [
'SORT' =>
'ASC']
269 while ($row =
$result->fetch())
271 $statusList[static::TYPE][$row[
'ID']] = $row[
'ID'];
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];
331 return static::getStatusesGroupCanDoOperations(static::getUserGroups(
$userId), $operations);
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;
374 private static function getStatusesByGroupId(
array $groupId,
array $operations =
array())
376 $operations = static::convertNamesToOperations($operations);
381 'OPERATION' =>
'Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME',
384 '=TYPE' => static::TYPE,
385 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.GROUP_ID' => $groupId,
387 'order' =>
array(
'SORT'),
390 if (!empty($operations))
392 $parameters[
'filter'][
'=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME'] = $operations;
396 $dbRes = static::getList($parameters);
397 while ($row =
$dbRes->fetch())
399 if ((
string)$row[
'OPERATION'] ===
'')
404 $statuses[$row[
'ID']] = $row[
'ID'];
434 if (! ($statusId =
$data[
'ID']) || ! is_string($statusId))
439 if ($languages =
$data[
'LANG'])
441 unset(
$data[
'LANG']);
443 if (!is_array($languages))
445 throw new SystemException(
'invalid status LANG', 0, __FILE__, __LINE__);
449 $data[
'TYPE'] = static::TYPE;
453 if (! StatusTable::getById($statusId)->fetch())
455 StatusTable::add(
$data);
462 $installedLanguages = [];
464 $result = StatusLangTable::getList([
469 '=STATUS_ID' => $statusId,
473 while ($row =
$result->fetch())
475 $installedLanguages[$row[
'LID']] =
true;
478 foreach ($languages as $language)
480 if (!is_array($language))
482 throw new SystemException(
'invalid status language', 0, __FILE__, __LINE__);
485 if (!isset($installedLanguages[$language[
'LID']]))
487 $language[
'STATUS_ID'] = $statusId;
489 StatusLangTable::add($language);
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
static getUserGroups($userId)
static getStatusesGroupCanDoOperations($groupId, array $operations)
static getInitialStatus()
static getAllStatusesNames($lang=null)
static getAllowedUserStatuses($userId, $fromStatus)
static getList(array $parameters=array())
static install(array $data)
static getAllowedGroupStatuses($groupId, $fromStatus)
static getStatusesUserCanDoOperations($userId, array $operations)
static canGroupDoOperations($groupId, $fromStatus, array $operations)
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
if(!defined('SITE_ID')) $lang
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
if(empty($signedUserToken)) $key
if( $guestStatuses !=='') if(!is_array($guestStatuses)) $statusList