1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
cataloggroup.php
См. документацию.
1<?php
2
6
8
10{
11 protected static array $arBaseGroupCache = [];
12
13 public static function CheckFields($ACTION, &$arFields, $ID = 0)
14 {
15 global $APPLICATION;
16 global $USER;
17 global $DB;
18
19 $boolResult = true;
20 $arMsg = array();
21
22 $ACTION = mb_strtoupper($ACTION);
23 if ('UPDATE' != $ACTION && 'ADD' != $ACTION)
24 return false;
25
26 if (array_key_exists("NAME", $arFields) || $ACTION=="ADD")
27 {
28 $arFields["NAME"] = trim($arFields["NAME"]);
29 if ('' == $arFields["NAME"])
30 {
31 $arMsg[] = array('id' => 'NAME', 'text' => GetMessage('BT_MOD_CAT_GROUP_ERR_EMPTY_NAME'));
32 $boolResult = false;
33 }
34 }
35
36 if ((array_key_exists("BASE", $arFields) || $ACTION=="ADD") && $arFields["BASE"] != "Y")
37 {
38 $arFields["BASE"] = "N";
39 }
40
41 if (array_key_exists("SORT", $arFields) || $ACTION=="ADD")
42 {
43 $arFields["SORT"] = intval($arFields["SORT"]);
44 if (0 >= $arFields["SORT"])
45 $arFields["SORT"] = 100;
46 }
47
48 $intUserID = 0;
49 $boolUserExist = CCatalog::IsUserExists();
50 if ($boolUserExist)
51 $intUserID = intval($USER->GetID());
52 $strDateFunction = $DB->GetNowFunction();
53 if (array_key_exists('TIMESTAMP_X', $arFields))
54 unset($arFields['TIMESTAMP_X']);
55 if (array_key_exists('DATE_CREATE', $arFields))
56 unset($arFields['DATE_CREATE']);
57 $arFields['~TIMESTAMP_X'] = $strDateFunction;
58 if (array_key_exists('MODIFIED_BY', $arFields))
59 {
60 if ($arFields['MODIFIED_BY'] !== false)
61 {
62 $arFields['MODIFIED_BY'] = (int)$arFields['MODIFIED_BY'];
63 if ($arFields['MODIFIED_BY'] <= 0)
64 {
65 unset($arFields['MODIFIED_BY']);
66 }
67 }
68 }
69 if (!isset($arFields['MODIFIED_BY']) && $boolUserExist)
70 {
71 $arFields["MODIFIED_BY"] = $intUserID;
72 }
73 if ('ADD' == $ACTION)
74 {
75 $arFields['~DATE_CREATE'] = $strDateFunction;
76 if (array_key_exists('CREATED_BY', $arFields))
77 {
78 if ($arFields['CREATED_BY'] !== false)
79 {
80 $arFields['CREATED_BY'] = (int)$arFields['CREATED_BY'];
81 if ($arFields['CREATED_BY'] <= 0)
82 {
83 unset($arFields['CREATED_BY']);
84 }
85 }
86 }
87 if (!isset($arFields['CREATED_BY']) && $boolUserExist)
88 {
89 $arFields["CREATED_BY"] = $intUserID;
90 }
91 }
92 if ('UPDATE' == $ACTION)
93 {
94 if (array_key_exists('CREATED_BY', $arFields))
95 unset($arFields['CREATED_BY']);
96 }
97
98 if (is_set($arFields, 'USER_GROUP') || $ACTION=="ADD")
99 {
100 if (!is_array($arFields['USER_GROUP']) || empty($arFields['USER_GROUP']))
101 {
102 $arMsg[] = array('id' => 'USER_GROUP', 'text' => GetMessage('BT_MOD_CAT_GROUP_ERR_EMPTY_USER_GROUP'));
103 $boolResult = false;
104 }
105 else
106 {
107 $arValid = array();
108 foreach ($arFields['USER_GROUP'] as &$intValue)
109 {
110 $intValue = intval($intValue);
111 if (0 < $intValue)
112 $arValid[] = $intValue;
113 }
114 if (isset($intValue))
115 unset($intValue);
116 if (!empty($arValid))
117 {
118 $arFields['USER_GROUP'] = array_values(array_unique($arValid));
119 }
120 else
121 {
122 $arMsg[] = array('id' => 'USER_GROUP', 'text' => GetMessage('BT_MOD_CAT_GROUP_ERR_EMPTY_USER_GROUP'));
123 $boolResult = false;
124 }
125 }
126 }
127
128 if (is_set($arFields, 'USER_GROUP_BUY') || $ACTION=="ADD")
129 {
130 if (!is_array($arFields['USER_GROUP_BUY']) || empty($arFields['USER_GROUP_BUY']))
131 {
132 $arMsg[] = array('id' => 'USER_GROUP_BUY', 'text' => GetMessage('BT_MOD_CAT_GROUP_ERR_EMPTY_USER_GROUP_BUY'));
133 $boolResult = false;
134 }
135 else
136 {
137 $arValid = array();
138 foreach ($arFields['USER_GROUP_BUY'] as &$intValue)
139 {
140 $intValue = intval($intValue);
141 if (0 < $intValue)
142 $arValid[] = $intValue;
143 }
144 if (isset($intValue))
145 unset($intValue);
146 if (!empty($arValid))
147 {
148 $arFields['USER_GROUP_BUY'] = array_values(array_unique($arValid));
149 }
150 else
151 {
152 $arMsg[] = array('id' => 'USER_GROUP_BUY', 'text' => GetMessage('BT_MOD_CAT_GROUP_ERR_EMPTY_USER_GROUP_BUY'));
153 $boolResult = false;
154 }
155 }
156 }
157
158 if (!$boolResult)
159 {
160 $obError = new CAdminException($arMsg);
161 $APPLICATION->ResetException();
162 $APPLICATION->ThrowException($obError);
163 }
164 return $boolResult;
165 }
166
167 public static function GetGroupsPerms($arUserGroups = array(), $arCatalogGroupsFilter = array())
168 {
169 global $USER;
170
171 if (!is_array($arUserGroups))
172 $arUserGroups = array($arUserGroups);
173
174 if (empty($arUserGroups))
175 $arUserGroups = (CCatalog::IsUserExists() ? $USER->GetUserGroupArray() : array(2));
177
178 if (!is_array($arCatalogGroupsFilter))
179 $arCatalogGroupsFilter = array($arCatalogGroupsFilter);
181 if (!empty($arCatalogGroupsFilter))
182 $arCatalogGroupsFilter = array_fill_keys($arCatalogGroupsFilter, true);
183
184 $result = array(
185 'view' => array(),
186 'buy' => array()
187 );
188
189 if (empty($arUserGroups))
190 return $result;
191
192 if (defined('CATALOG_SKIP_CACHE') && CATALOG_SKIP_CACHE)
193 {
194 $priceTypeIterator = CCatalogGroup::GetGroupsList(array('@GROUP_ID' => $arUserGroups));
195 while ($priceType = $priceTypeIterator->Fetch())
196 {
197 $priceTypeId = (int)$priceType['CATALOG_GROUP_ID'];;
198 $key = ($priceType['BUY'] == 'Y' ? 'buy' : 'view');
199 if ($key == 'view' && !empty($arCatalogGroupsFilter) && !isset($arCatalogGroupsFilter[$priceTypeId]))
200 continue;
201 $result[$key][$priceTypeId] = $priceTypeId;
202 unset($key, $priceTypeId);
203 }
204 unset($priceType, $priceTypeIterator);
205 if (!empty($result['view']))
206 $result['view'] = array_values($result['view']);
207 if (!empty($result['buy']))
208 $result['buy'] = array_values($result['buy']);
209
210 return $result;
211 }
212
213 $data = array();
214 $cacheTime = (int)(defined('CATALOG_CACHE_TIME') ? CATALOG_CACHE_TIME : CATALOG_CACHE_DEFAULT_TIME);
215 $managedCache = Application::getInstance()->getManagedCache();
216 if ($managedCache->read($cacheTime, 'catalog_group_perms'))
217 {
218 $data = $managedCache->get('catalog_group_perms');
219 }
220 else
221 {
222 $priceTypeIterator = CCatalogGroup::GetGroupsList();
223 while ($priceType = $priceTypeIterator->Fetch())
224 {
225 $priceTypeId = (int)$priceType['CATALOG_GROUP_ID'];
226 $groupId = (int)($priceType['GROUP_ID']);
227 $key = ($priceType['BUY'] == 'Y' ? 'buy' : 'view');
228
229 if (!isset($data[$groupId]))
230 $data[$groupId] = array(
231 'view' => array(),
232 'buy' => array()
233 );
234 $data[$groupId][$key][$priceTypeId] = $priceTypeId;
235 unset($key, $groupId, $priceTypeId);
236 }
237 unset($priceType, $priceTypeIterator);
238 if (!empty($data))
239 {
240 foreach ($data as &$groupData)
241 {
242 if (!empty($groupData['view']))
243 $groupData['view'] = array_values($groupData['view']);
244 if (!empty($groupData['buy']))
245 $groupData['buy'] = array_values($groupData['buy']);
246 }
247 unset($groupData);
248 }
249 $managedCache->set('catalog_group_perms', $data);
250 }
251
252 foreach ($arUserGroups as &$groupId)
253 {
254 if (!isset($data[$groupId]))
255 continue;
256 if (!empty($data[$groupId]['view']))
257 {
258 $priceTypeList = $data[$groupId]['view'];
259 foreach ($priceTypeList as &$priceTypeId)
260 {
261 if (!empty($arCatalogGroupsFilter) && !isset($arCatalogGroupsFilter[$priceTypeId]))
262 continue;
263 $result['view'][$priceTypeId] = $priceTypeId;
264 }
265 unset($priceTypeId, $priceTypeList);
266 }
267 if (!empty($data[$groupId]['buy']))
268 {
269 $priceTypeList = $data[$groupId]['buy'];
270 foreach ($priceTypeList as &$priceTypeId)
271 $result['buy'][$priceTypeId] = $priceTypeId;
272 unset($priceTypeId, $priceTypeList);
273 }
274 }
275 unset($groupId);
276
277 if (!empty($result['view']))
278 $result['view'] = array_values($result['view']);
279 if (!empty($result['buy']))
280 $result['buy'] = array_values($result['buy']);
281
282 return $result;
283 }
284
291 public static function GetListArray(): array
292 {
294 }
295
302 public static function GetBaseGroup()
303 {
305 if (!empty($group))
306 {
307 $group['NAME_LANG'] = (string)$group['NAME_LANG'];
308 $group['XML_ID'] = (string)$group['XML_ID'];
309
310 return $group;
311 }
312
313 return false;
314 }
315
322 public static function GetBaseGroupId(): ?int
323 {
325 }
326
327 public static function GetByID($ID, $lang = LANGUAGE_ID): false|array
328 {
329 global $USER;
330
331 $ID = (int)$ID;
332 if ($ID <= 0)
333 {
334 return false;
335 }
336
337 $lang = (string)$lang;
338
340 'select' => [
341 'ID',
342 'NAME',
343 'BASE',
344 'SORT',
345 'XML_ID',
346 'CREATED_BY',
347 'MODIFIED_BY',
348 'TIMESTAMP_X',
349 'DATE_CREATE',
350 ],
351 'filter' => [
352 '=ID' => $ID,
353 ],
354 ]);
355
356 if ($row === null)
357 {
358 return false;
359 }
360 if ($row['TIMESTAMP_X'] instanceof Main\Type\DateTime)
361 {
362 $row['TIMESTAMP_X'] = $row['TIMESTAMP_X']->toString();
363 }
364 if ($row['DATE_CREATE'] instanceof Main\Type\DateTime)
365 {
366 $row['DATE_CREATE'] = $row['DATE_CREATE']->toString();
367 }
368
369 $langName = Catalog\GroupLangTable::getRow([
370 'select' => [
371 'NAME',
372 ],
373 'filter' => [
374 '=CATALOG_GROUP_ID' => $ID,
375 '=LANG' => $lang,
376 ],
377 ]);
378
379 $row['NAME_LANG'] = $langName === null ? null : $langName['NAME'];
380
381 $userGroupIds =
383 ? $USER->GetUserGroupArray()
384 : [2]
385 ;
386
388 'select' => [
389 'ID',
390 ],
391 'filter' => [
392 '=CATALOG_GROUP_ID' => $ID,
393 '@GROUP_ID' => $userGroupIds,
395 ]
396 ]);
397 $row['CAN_ACCESS'] = $access === null ? 'N' : 'Y';
398
400 'select' => [
401 'ID',
402 ],
403 'filter' => [
404 '=CATALOG_GROUP_ID' => $ID,
405 '@GROUP_ID' => $userGroupIds,
407 ]
408 ]);
409 $row['CAN_BUY'] = $access === null ? 'N' : 'Y';
410
411 return $row;
412 }
413}
const CATALOG_CACHE_DEFAULT_TIME
Определения include.php:110
global $APPLICATION
Определения include.php:80
static getBasePriceType()
Определения group.php:209
static getTypeList()
Определения group.php:273
static getBasePriceTypeId()
Определения group.php:261
static getInstance()
Определения application.php:98
static getRow(array $parameters)
Определения datamanager.php:398
static normalizeArrayValuesByInt(&$map, $sorted=true)
Определения collection.php:150
static GetBaseGroupId()
Определения cataloggroup.php:322
static array $arBaseGroupCache
Определения cataloggroup.php:11
static CheckFields($ACTION, &$arFields, $ID=0)
Определения cataloggroup.php:13
static GetListArray()
Определения cataloggroup.php:291
static GetGroupsPerms($arUserGroups=array(), $arCatalogGroupsFilter=array())
Определения cataloggroup.php:167
static GetBaseGroup()
Определения cataloggroup.php:302
static GetByID($ID, $lang=LANGUAGE_ID)
Определения cataloggroup.php:327
static IsUserExists()
Определения catalog.php:1812
static GetGroupsList($arFilter=array())
Определения cataloggroup.php:461
$arFields
Определения dblapprove.php:5
$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
if($ajaxMode) $ID
Определения get_user.php:27
global $DB
Определения cron_frame.php:29
global $USER
Определения csv_new_run.php:40
$ACTION
Определения csv_new_setup.php:27
if(!defined('SITE_ID')) $lang
Определения include.php:91
if(!is_array($deviceNotifyCodes)) $access
Определения options.php:174
IncludeModuleLangFile($filepath, $lang=false, $bReturnArray=false)
Определения tools.php:3778
is_set($a, $k=false)
Определения tools.php:2133
GetMessage($name, $aReplace=null)
Определения tools.php:3397
Определения collection.php:2
return false
Определения prolog_main_admin.php:185
if(empty($signedUserToken)) $key
Определения quickway.php:257
if(!empty($XML_DATA['PRICE'])) $priceTypeList
Определения yandex_run.php:872