1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
statusbase.php
См. документацию.
1<?php
2
3namespace Bitrix\Sale;
4
5use Bitrix\Main;
6use Bitrix\Sale\Internals\StatusTable;
7use Bitrix\Sale\Internals\StatusLangTable;
8use Bitrix\Main\UserGroupTable;
9use Bitrix\Main\SystemException;
10use Bitrix\Main\Localization\Loc;
11
12Loc::loadMessages(__FILE__);
13
18abstract class StatusBase
19{
20 const TYPE = '';
21
29 public static function getList(array $parameters = array())
30 {
31 if (static::TYPE !== '')
32 {
33 if (!isset($parameters['filter']))
34 {
35 $parameters['filter'] = ['=TYPE' => static::TYPE];
36 }
37 else
38 {
39 $parameters['filter'] = [
40 '=TYPE' => static::TYPE,
41 $parameters['filter']
42 ];
43 }
44 }
45
46 return StatusTable::getList($parameters);
47 }
48
55 protected static function getUserGroups($userId)
56 {
57 global $USER;
58
59 if ($userId == $USER->GetID())
60 {
61 $groups = $USER->GetUserGroupArray();
62 }
63 else
64 {
65 static $cacheGroups;
66
67 if (isset($cacheGroups[$userId]))
68 {
69 $groups = $cacheGroups[$userId];
70 }
71 else
72 {
73 // TODO: DATE_ACTIVE_FROM >=< DATE_ACTIVE_TO
74 $result = UserGroupTable::getList(array(
75 'select' => array('GROUP_ID'),
76 'filter' => array('USER_ID' => $userId)
77 ));
78
79 $groups = array();
80 while ($row = $result->fetch())
81 $groups []= $row['GROUP_ID'];
82
83 $cacheGroups[$userId] = $groups;
84 }
85 }
86
87 return $groups;
88 }
89
98 public static function canGroupDoOperations($groupId, $fromStatus, array $operations)
99 {
100 if (!$operations)
101 {
102 throw new SystemException('provide at least one operation', 0, __FILE__, __LINE__);
103 }
104
105 if (!is_array($groupId))
106 {
107 $groupId = array($groupId);
108 }
109
110 if (in_array('1', $groupId, true) || \CMain::GetUserRight('sale', $groupId) >= 'W') // Admin
111 {
112 return true;
113 }
114
115 $operations = static::convertNamesToOperations($operations);
116
117 $result = static::getList(array(
118 'select' => array(
119 'NAME' => 'Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME',
120 ),
121 'filter' => array(
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,
125 ),
126 ));
127
128 while ($row = $result->fetch())
129 {
130 if (($key = array_search($row['NAME'], $operations)) !== false)
131 {
132 unset($operations[$key]);
133 }
134 }
135
136 return !$operations;
137 }
138
148 public static function getAllowedUserStatuses($userId, $fromStatus)
149 {
150 return static::getAllowedGroupStatuses(static::getUserGroups($userId), $fromStatus);
151 }
152
160 protected static function getAllowedGroupStatuses($groupId, $fromStatus)
161 {
162 static $cacheAllowStatuses = array();
163
164 if (! is_array($groupId))
165 $groupId = array($groupId);
166
167 $cacheKey = md5(join('|', $groupId) . "_".(is_array($fromStatus) ? join('|', $fromStatus) : $fromStatus));
168
169 if (in_array('1', $groupId, true) || \CMain::GetUserRight('sale', $groupId) >= 'W') // Admin
170 {
171 if (!array_key_exists($cacheKey, $cacheAllowStatuses))
172 {
173 $result = static::getList(array(
174 'select' => array(
175 'ID',
176 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'
177 ),
178 'filter' => array(
179 '=TYPE' => static::TYPE,
180 '=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID' => LANGUAGE_ID),
181 'order' => array(
182 'SORT'
183 ),
184 ));
185
186 while ($row = $result->fetch())
187 {
188 $cacheAllowStatuses[$cacheKey][$row['ID']] = $row['NAME'];
189 }
190 }
191 }
192 else
193 {
194 if (!array_key_exists($cacheKey, $cacheAllowStatuses))
195 {
196 $cacheAllowStatuses[$cacheKey] = array();
197
198 $dbRes = static::getList(array( // check if group can change from status
199 'select' => array('ID'),
200 'filter' => array(
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',
205 ),
206 'limit' => 1,
207 ));
208
209 if ($dbRes->fetch())
210 {
211 $result = static::getList(array(
212 'select' => array('ID', 'NAME' => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'),
213 'filter' => array(
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',
218 ),
219 'order' => array('SORT'),
220 ));
221
222 while ($row = $result->fetch())
223 {
224 $cacheAllowStatuses[$cacheKey][$row['ID']] = $row['NAME'];
225 }
226 }
227 }
228 }
229
230 return $cacheAllowStatuses[$cacheKey] ?? [];
231 }
232
237 private static function convertNamesToOperations($names)
238 {
239 $operations = array();
240
241 foreach ($names as $name)
242 {
243 $operations[] = 'sale_status_'.mb_strtolower($name);
244 }
245
246 return $operations;
247 }
248
255 public static function getAllStatuses()
256 {
257 static $statusList = [];
258
259 if (!isset($statusList[static::TYPE]))
260 {
261 $statusList[static::TYPE] = [];
262
263 $result = static::getList([
264 'select' => ['ID'],
265 'filter' => ['=TYPE' => static::TYPE],
266 'order' => ['SORT' => 'ASC']
267 ]);
268
269 while ($row = $result->fetch())
270 {
271 $statusList[static::TYPE][$row['ID']] = $row['ID'];
272 }
273 }
274
275 return $statusList[static::TYPE];
276 }
277
285 public static function getAllStatusesNames($lang = null)
286 {
287 $parameters = [
288 'select' => ["ID", "NAME" => 'Bitrix\Sale\Internals\StatusLangTable:STATUS.NAME'],
289 'filter' => [
290 '=TYPE' => static::TYPE,
291 ],
292 'order' => ['SORT' => 'ASC']
293 ];
294
295 if ($lang !== null)
296 {
297 $parameters['filter']['=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID'] = $lang;
298 }
299 elseif (defined("LANGUAGE_ID"))
300 {
301 $parameters['filter']['=Bitrix\Sale\Internals\StatusLangTable:STATUS.LID'] = LANGUAGE_ID;
302 }
303
304 static $allStatusesNames = [];
305
306 if (!isset($allStatusesNames[static::TYPE]))
307 {
308 $allStatusesNames[static::TYPE] = [];
309
310 $result = static::getList($parameters);
311 while ($row = $result->fetch())
312 {
313 $allStatusesNames[static::TYPE][$row['ID']] = $row['NAME'];
314 }
315 }
316
317 return $allStatusesNames[static::TYPE];
318 }
319
329 public static function getStatusesUserCanDoOperations($userId, array $operations)
330 {
331 return static::getStatusesGroupCanDoOperations(static::getUserGroups($userId), $operations);
332 }
333
340 public static function getStatusesGroupCanDoOperations($groupId, array $operations)
341 {
342 static $cacheStatuses = array();
343
344 if (!is_array($groupId))
345 $groupId = array($groupId);
346
347 $cacheHash = md5(static::TYPE."|".join('_', $groupId)."|".join('_', $operations));
348
349 if (!empty($cacheStatuses[$cacheHash]))
350 {
351 return $cacheStatuses[$cacheHash];
352 }
353
354 if (in_array('1', $groupId, true) || \CMain::GetUserRight('sale', $groupId) >= 'W') // Admin
355 {
356 $statuses = static::getAllStatuses();
357 }
358 else
359 {
360 $statuses = static::getStatusesByGroupId($groupId, $operations);
361 }
362
363 $cacheStatuses[$cacheHash] = $statuses;
364
365 return $statuses;
366 }
367
374 private static function getStatusesByGroupId(array $groupId, array $operations = array())
375 {
376 $operations = static::convertNamesToOperations($operations);
377
378 $parameters = array(
379 'select' => array(
380 'ID',
381 'OPERATION' => 'Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME',
382 ),
383 'filter' => array(
384 '=TYPE' => static::TYPE,
385 '=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.GROUP_ID' => $groupId,
386 ),
387 'order' => array('SORT'),
388 );
389
390 if (!empty($operations))
391 {
392 $parameters['filter']['=Bitrix\Sale\Internals\StatusGroupTaskTable:STATUS.TASK.Bitrix\Main\TaskOperation:TASK.OPERATION.NAME'] = $operations;
393 };
394
395 $statuses = array();
396 $dbRes = static::getList($parameters);
397 while ($row = $dbRes->fetch())
398 {
399 if ((string)$row['OPERATION'] === '')
400 {
401 continue;
402 }
403
404 $statuses[$row['ID']] = $row['ID'];
405 }
406
407 return $statuses;
408 }
409
413 public static function getInitialStatus()
414 {
416 }
417
421 public static function getFinalStatus()
422 {
424 }
425
432 public static function install(array $data)
433 {
434 if (! ($statusId = $data['ID']) || ! is_string($statusId))
435 {
436 throw new SystemException('invalid status ID', 0, __FILE__, __LINE__);
437 }
438
439 if ($languages = $data['LANG'])
440 {
441 unset($data['LANG']);
442
443 if (!is_array($languages))
444 {
445 throw new SystemException('invalid status LANG', 0, __FILE__, __LINE__);
446 }
447 }
448
449 $data['TYPE'] = static::TYPE;
450
451 // install status if it is not installed
452
453 if (! StatusTable::getById($statusId)->fetch())
454 {
455 StatusTable::add($data);
456 }
457
458 // install status languages if they are not installed
459
460 if ($languages)
461 {
462 $installedLanguages = [];
463
464 $result = StatusLangTable::getList([
465 'select' => [
466 'LID',
467 ],
468 'filter' => [
469 '=STATUS_ID' => $statusId,
470 ],
471 ]);
472
473 while ($row = $result->fetch())
474 {
475 $installedLanguages[$row['LID']] = true;
476 }
477
478 foreach ($languages as $language)
479 {
480 if (!is_array($language))
481 {
482 throw new SystemException('invalid status language', 0, __FILE__, __LINE__);
483 }
484
485 if (!isset($installedLanguages[$language['LID']]))
486 {
487 $language['STATUS_ID'] = $statusId;
488
489 StatusLangTable::add($language);
490 }
491 }
492 }
493 }
494}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getUserGroups($userId)
Определения statusbase.php:55
static getStatusesGroupCanDoOperations($groupId, array $operations)
Определения statusbase.php:340
static getInitialStatus()
Определения statusbase.php:413
static getAllStatusesNames($lang=null)
Определения statusbase.php:285
static getAllowedUserStatuses($userId, $fromStatus)
Определения statusbase.php:148
static getList(array $parameters=array())
Определения statusbase.php:29
static install(array $data)
Определения statusbase.php:432
const TYPE
Определения statusbase.php:20
static getAllStatuses()
Определения statusbase.php:255
static getFinalStatus()
Определения statusbase.php:421
static getAllowedGroupStatuses($groupId, $fromStatus)
Определения statusbase.php:160
static getStatusesUserCanDoOperations($userId, array $operations)
Определения statusbase.php:329
static canGroupDoOperations($groupId, $fromStatus, array $operations)
Определения statusbase.php:98
$data['IS_AVAILABLE']
Определения .description.php:13
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$result
Определения get_property_values.php:14
global $USER
Определения csv_new_run.php:40
if(!defined('SITE_ID')) $lang
Определения include.php:91
$groups
Определения options.php:30
$name
Определения menu_edit.php:35
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
if( $guestStatuses !=='') if(!is_array($guestStatuses)) $statusList
Определения options.php:2065
$dbRes
Определения yandex_detail.php:168