1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
restentity.php
См. документацию.
1<?php
2
9
11{
13
14 const ERROR_ENTITY_ALREADY_EXISTS = 'ERROR_ENTITY_ALREADY_EXISTS';
15 const ERROR_ENTITY_NOT_FOUND = 'ERROR_ENTITY_NOT_FOUND';
16 const ERROR_SECTION_NOT_FOUND = 'ERROR_SECTION_NOT_FOUND';
17 const ERROR_ITEM_NOT_FOUND = 'ERROR_ITEM_NOT_FOUND';
18 const ERROR_PROPERTY_NOT_FOUND = 'ERROR_PROPERTY_NOT_FOUND';
19 const ERROR_PROPERTY_ALREADY_EXISTS = 'ERROR_PROPERTY_ALREADY_EXISTS';
20 const ERROR_UNSUPPORTED_PROPERTY_TYPE = 'ERROR_UNSUPPORTED_PROPERTY_TYPE';
21 const ERROR_UNSUPPORTED_PROPERTY_TYPE_CHANGE = 'ERROR_UNSUPPORTED_PROPERTY_TYPE_CHANGE';
22
23 private static $arAllowedOperations = array('', '!', '<', '<=', '>', '>=', '><', '!><', '?', '=', '!=', '%', '!%', '');
24
25 public static function OnRestServiceBuildDescription()
26 {
27 if(CModule::IncludeModule('iblock'))
28 {
29 return array(
30 'entity' => array(
31 'entity.add' => array(__CLASS__, 'entityAdd'),
32 'entity.get' => array(__CLASS__, 'entityGet'),
33 'entity.update' => array(__CLASS__, 'entityUpdate'),
34 'entity.delete' => array(__CLASS__, 'entityDelete'),
35 'entity.rights' => array(__CLASS__, 'entityRights'),
36
37 'entity.section.add' => array(__CLASS__, 'entitySectionAdd'),
38 'entity.section.get' => array(__CLASS__, 'entitySectionGet'),
39 'entity.section.update' => array(__CLASS__, 'entitySectionUpdate'),
40 'entity.section.delete' => array(__CLASS__, 'entitySectionDelete'),
41
42 'entity.item.add' => array(__CLASS__, 'entityItemAdd'),
43 'entity.item.get' => array(__CLASS__, 'entityItemGet'),
44 'entity.item.update' => array(__CLASS__, 'entityItemUpdate'),
45 'entity.item.delete' => array(__CLASS__, 'entityItemDelete'),
46
47 'entity.item.property.add' => array(__CLASS__, 'entityItemPropertyAdd'),
48 'entity.item.property.get' => array(__CLASS__, 'entityItemPropertyGet'),
49 'entity.item.property.update' => array(__CLASS__, 'entityItemPropertyUpdate'),
50 'entity.item.property.delete' => array(__CLASS__, 'entityItemPropertyDelete'),
51 ),
52 );
53 }
54 }
55
56 public static function entityAdd($params, $n, $server)
57 {
58 global $USER;
59
60 if(self::checkParams($params))
61 {
62 if(!self::checkEntity($params['ENTITY'], $server))
63 {
64 if(!isset($params['ACCESS']) || !is_array($params['ACCESS']))
65 {
66 $params['ACCESS'] = array();
67 }
68
69 $params['ACCESS']['U'.$USER->GetID()] = 'X';
70
71 $arIBlockFields = array(
72 'IBLOCK_TYPE_ID' => self::getIBlockType(),
73 "NAME" => trim($params['NAME']),
74 "CODE" => self::getEntityIBlockCode($params['ENTITY'], $server),
75 "ACTIVE" => "Y",
76 'WORKFLOW' => 'N',
77 'INDEX_SECTION' => 'N',
78 'INDEX_ELEMENT' => 'N',
79 'VERSION' => 1,
80 'RIGHTS_MODE' => 'E',
81 'RIGHTS' => self::checkRights($params['ACCESS']),
82 'SITE_ID' => CSite::GetDefSite()
83 );
84
85 $ib = new \CIBlock();
86
87 $conn = Application::getConnection();
88 $conn->startTransaction();
89 $error = '';
90 try
91 {
92 $ID = $ib->Add($arIBlockFields);
93 if (!$ID)
94 {
95 $error = $ib->getLastError();
96 }
97 }
98 catch (SqlQueryException)
99 {
100 $error = 'Internal error adding entity. Try adding again.';
101 }
102 if ($error === '')
103 {
104 $conn->commitTransaction();
105
106 return true;
107 }
108 else
109 {
110 $conn->rollbackTransaction();
111 throw new RestException($error, RestException::ERROR_CORE);
112 }
113 }
114 else
115 {
116 throw new RestException('Entity already exists', self::ERROR_ENTITY_ALREADY_EXISTS);
117 }
118 }
119 }
120
121 public static function entityGet($params, $n, $server)
122 {
123 $params = array_change_key_case($params, CASE_UPPER);
124 if(isset($params['ENTITY']))
125 {
126 if(self::checkParams($params))
127 {
128 $arRes = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
129 if($arRes)
130 {
131 return array(
132 'ID' => $arRes['ID'],
133 'IBLOCK_TYPE_ID' => $arRes['IBLOCK_TYPE_ID'],
134 'ENTITY' => $params['ENTITY'],
135 'NAME' => $arRes['NAME'],
136 );
137 }
138 else
139 {
140 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
141 }
142 }
143 }
144 else
145 {
146 $res = array();
147 $dbRes = self::getIBlocks($server);
148 while($arRes = $dbRes->Fetch())
149 {
150 $entity = self::parseEntity($arRes['CODE'], $server);
151 if($entity)
152 {
153 $res[] = array(
154 'ID' => $arRes['ID'],
155 'IBLOCK_TYPE_ID' => $arRes['IBLOCK_TYPE_ID'],
156 'ENTITY' => $entity,
157 'NAME' => $arRes['NAME'],
158 );
159 }
160 }
161
162 return $res;
163 }
164 }
165
166 public static function entityRights($params, $n, $server)
167 {
168 global $USER;
169
170 if(self::checkParams($params))
171 {
172 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
173 if($arIBlock)
174 {
175 $obIBlockRights = new \CIBlockRights($arIBlock['ID']);
176
177 if(isset($params['ACCESS']) && is_array($params['ACCESS']) && count($params['ACCESS']) > 0)
178 {
179 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'iblock_edit'))
180 {
181 $params['ACCESS']['U'.$USER->GetID()] = 'X';
182 $arRights = self::checkRights($params['ACCESS']);
183
184 $obIBlockRights->SetRights($arRights);
185 $obIBlockRights->Recalculate();
186 }
187 else
188 {
189 throw new AccessException();
190 }
191 }
192
193 $arRights = $obIBlockRights->GetRights();
194 $res = array();
195
196 foreach($arRights as $arRight)
197 {
198 $res[$arRight['GROUP_CODE']] = \CIBlockRights::TaskToLetter($arRight['TASK_ID']);
199 }
200
201 return $res;
202 }
203 }
204 }
205
206 public static function entityUpdate($params, $n, $server)
207 {
208 global $USER;
209
210 if(self::checkParams($params))
211 {
212 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
213 if($arIBlock)
214 {
215 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'iblock_edit'))
216 {
217 $recalcRights = false;
218
219 $arIBlockFields = array();
220 if(isset($params['NAME']))
221 {
222 $arIBlockFields["NAME"] = trim($params['NAME']);
223 }
224
225 if(isset($params['ENTITY_NEW']) && $params['ENTITY_NEW'] != $params['ENTITY'])
226 {
227 if (self::checkEntity($params['ENTITY_NEW'], $server))
228 {
229 throw new RestException('Entity already exists', self::ERROR_ENTITY_ALREADY_EXISTS);
230 }
231
232 $arIBlockFields["CODE"] = self::getEntityIBlockCode($params['ENTITY_NEW'], $server);
233 }
234
235 if(isset($params['ACCESS']) && is_array($params['ACCESS']) && count($params['ACCESS']) > 0)
236 {
237 $recalcRights = true;
238 $params['ACCESS']['U'.$USER->GetID()] = 'X';
239 $arIBlockFields['RIGHTS'] = self::checkRights($params['ACCESS']);
240 }
241
242 if(count($arIBlockFields) > 0)
243 {
244 $ib = new \CIBlock();
245
246 $conn = Application::getConnection();
247 $conn->startTransaction();
248 $error = '';
249 try
250 {
251 if (!$ib->Update($arIBlock['ID'], $arIBlockFields))
252 {
253 $error = $ib->getLastError();
254 }
255 if ($error === '' && $recalcRights)
256 {
257 $obIBlockRights = new CIBlockRights($arIBlock['ID']);
258 $obIBlockRights->Recalculate();
259 unset($obIBlockRights);
260 }
261 }
262 catch (SqlQueryException)
263 {
264 $error = 'Internal error updating entity. Try updating again.';
265 }
266 if ($error === '')
267 {
268 $conn->commitTransaction();
269 }
270 else
271 {
272 $conn->rollbackTransaction();
273 throw new RestException($error, RestException::ERROR_CORE);
274 }
275 }
276 return true;
277 }
278 else
279 {
280 throw new AccessException();
281 }
282 }
283 else
284 {
285 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
286 }
287 }
288 }
289
290 public static function entityDelete($params, $n, $server)
291 {
293 global $APPLICATION;
294
295 if(self::checkParams($params))
296 {
297 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
298 if($arIBlock)
299 {
300 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'iblock_edit'))
301 {
302 $conn = Application::getConnection();
303 $conn->startTransaction();
304 $error = '';
305 try
306 {
307 if (!CIBlock::Delete($arIBlock['ID']))
308 {
309 $ex = $APPLICATION->GetException();
310 $error =
311 $ex
312 ? $ex->GetString()
313 : 'Unable to delete iblock'
314 ;
315 unset(
316 $ex,
317 );
318 }
319 }
320 catch (SqlQueryException)
321 {
322 $error = 'Internal error deleting entity. Try deleting again.';
323 }
324 if ($error === '')
325 {
326 $conn->commitTransaction();
327 }
328 else
329 {
330 $conn->rollbackTransaction();
331 throw new RestException($error, RestException::ERROR_CORE);
332 }
333
334 return true;
335 }
336 else
337 {
338 throw new AccessException();
339 }
340 }
341 else
342 {
343 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
344 }
345 }
346 }
347
348 public static function entitySectionGet($params, $n, $server)
349 {
350 if(self::checkSectionParams($params))
351 {
352 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
353 if($arIBlock)
354 {
355 $arSort = array('ID' => 'ASC');
356 $arFilter = array();
357
358 if(isset($params['SORT']) && is_array($params['SORT']))
359 {
360 $arSort = array_change_key_case($params['SORT'], CASE_UPPER);
361 }
362
363 if(isset($params['FILTER']) && is_array($params['FILTER']))
364 {
365 $arFilter = array_change_key_case($params['FILTER'], CASE_UPPER);
366 }
367
369 $arFilter['IBLOCK_ID'] = $arIBlock['ID'];
370 $arFilter['CHECK_PERMISSIONS'] = 'Y';
371
372 $dbRes = \CIBlockSection::GetList(
373 $arSort,
374 $arFilter,
375 false,
376 array('ID', 'IBLOCK_ID', 'CODE', 'TIMESTAMP_X', 'DATE_CREATE', 'CREATED_BY', 'MODIFIED_BY', 'ACTIVE', 'SORT', 'NAME', 'PICTURE', 'DETAIL_PICTURE', 'DESCRIPTION', 'LEFT_MARGIN', 'RIGHT_MARGIN', 'DEPTH_LEVEL', 'IBLOCK_SECTION_ID'),
377 self::getNavData($n)
378 );
379
380 $result = array();
381 while ($res = $dbRes->Fetch(false, false))
382 {
383 $res['ENTITY'] = $params['ENTITY'];
384 $res['SECTION'] = $res['IBLOCK_SECTION_ID'];
385
386 $res['TIMESTAMP_X'] = CRestUtil::ConvertDateTime($res['TIMESTAMP_X']);
387 $res['DATE_CREATE'] = CRestUtil::ConvertDateTime($res['DATE_CREATE']);
388
389 if($res['PICTURE'] > 0)
390 $res['PICTURE'] = self::getFile($res['PICTURE']);
391
392 if($res['DETAIL_PICTURE'] > 0)
393 $res['DETAIL_PICTURE'] = self::getFile($res['DETAIL_PICTURE']);
394
395 unset($res['IBLOCK_ID']);
396 unset($res['IBLOCK_SECTION_ID']);
397 unset($res['DETAIL_TEXT_TYPE']);
398 unset($res['DESCRIPTION_TYPE']);
399 $result[] = $res;
400 }
401
403 }
404 else
405 {
406 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
407 }
408 }
409 }
410
411 public static function entitySectionAdd($params, $n, $server)
412 {
413 if(self::checkSectionParams($params))
414 {
415 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
416 if($arIBlock)
417 {
418 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'section_edit'))
419 {
420 $arSectionFields = self::prepareSection($params, $arIBlock, $server);
421
422 $ib = new \CIBlockSection();
423
424 $conn = Application::getConnection();
425 $conn->startTransaction();
426 $ID = false;
427 $error = '';
428 try
429 {
430 $ID = $ib->Add($arSectionFields);
431 if (!$ID)
432 {
433 $error = $ib->getLastError();
434 }
435 }
436 catch (SqlQueryException)
437 {
438 $error = 'Internal error adding entity section. Try adding again.';
439 }
440 if ($ID)
441 {
442 $conn->commitTransaction();
443
444 return $ID;
445 }
446 else
447 {
448 $conn->rollbackTransaction();
449 throw new RestException($error, RestException::ERROR_CORE);
450 }
451 }
452 else
453 {
454 throw new AccessException();
455 }
456 }
457 else
458 {
459 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
460 }
461 }
462 }
463
464 public static function entitySectionUpdate($params, $n, $server)
465 {
466 if(self::checkSectionParams($params))
467 {
468 $params['ID'] = intval($params['ID']);
469 if($params['ID'] <= 0)
470 {
471 throw new ArgumentNullException("ID");
472 }
473 else
474 {
475 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
476 if($arIBlock)
477 {
478 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'section_edit'))
479 {
480 $dbRes = \CIBlockSection::GetList(array(), array(
481 'ID' => $params['ID'],
482 'IBLOCK_ID' => $arIBlock['ID']
483 ), false, array('ID'));
484 $arRes = $dbRes->Fetch();
485
486 if($arRes)
487 {
488 $arSectionFields = self::prepareSection($params, $arIBlock, $server);
489
490 if(count($arSectionFields) > 0)
491 {
492 $ib = new \CIBlockSection();
493
494 $conn = Application::getConnection();
495 $conn->startTransaction();
496 $error = '';
497 try
498 {
499 if (!$ib->Update($arRes['ID'], $arSectionFields))
500 {
501 $error = $ib->getLastError();
502 }
503 }
504 catch (SqlQueryException)
505 {
506 $error = 'Internal error updating entity section. Try updating again.';
507 }
508 if ($error === '')
509 {
510 $conn->commitTransaction();
511 }
512 else
513 {
514 $conn->rollbackTransaction();
515 throw new RestException($error, RestException::ERROR_CORE);
516 }
517 }
518
519 return true;
520 }
521 else
522 {
523 throw new RestException('Section not found', self::ERROR_SECTION_NOT_FOUND);
524 }
525 }
526 else
527 {
528 throw new AccessException();
529 }
530 }
531 else
532 {
533 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
534 }
535 }
536 }
537 }
538
539 public static function entitySectionDelete($params, $n, $server)
540 {
542 global $APPLICATION;
543
544 if(self::checkSectionParams($params))
545 {
546 $params['ID'] = intval($params['ID']);
547 if($params['ID'] <= 0)
548 {
549 throw new ArgumentNullException("ID");
550 }
551 else
552 {
553 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
554 if($arIBlock)
555 {
556 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'section_delete'))
557 {
558 $dbRes = \CIBlockSection::GetList(array(), array(
559 'ID' => $params['ID'],
560 'IBLOCK_ID' => $arIBlock['ID']
561 ), false, array('ID'));
562 $arRes = $dbRes->Fetch();
563 if($arRes)
564 {
565 $conn = Application::getConnection();
566 $conn->startTransaction();
567 $error = '';
568 try
569 {
570 if (!\CIBlockSection::Delete($params['ID']))
571 {
572 $ex = $APPLICATION->GetException();
573 $error =
574 $ex
575 ? $ex->GetString()
576 : 'Unable to delete section'
577 ;
578 unset(
579 $ex,
580 );
581 }
582 }
583 catch (SqlQueryException)
584 {
585 $error = 'Internal error deleting entity section. Try deleting again.';
586 }
587 if ($error === '')
588 {
589 $conn->commitTransaction();
590 }
591 else
592 {
593 $conn->rollbackTransaction();
594 throw new RestException($error, RestException::ERROR_CORE);
595 }
596
597 return true;
598 }
599 else
600 {
601 throw new RestException('Section not found', self::ERROR_SECTION_NOT_FOUND);
602 }
603 }
604 else
605 {
606 throw new AccessException();
607 }
608 }
609 else
610 {
611 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
612 }
613 }
614 }
615 }
616
617 public static function entityItemGet($params, $n, $server)
618 {
619 if(!self::checkItemParams($params))
620 {
621 return;
622 }
623 $iBlockCode = self::getEntityIBlockCode($params['ENTITY'], $server);
624
626 if(is_null($iBlockId))
627 {
628 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
629 }
630 $arFields = array();
631
632 $dbRes = self::getItemProperties($params['ENTITY'], $server);
633 while ($arField = $dbRes->Fetch())
634 {
635 $arFields[$arField['CODE']] = $arField['ID'];
636 }
637
638 $arSort = array('ID' => 'ASC');
639 $arFilter = array();
640
641 if(isset($params['SORT']) && is_array($params['SORT']))
642 {
643 $arSort = array_change_key_case($params['SORT'], CASE_UPPER);
644 }
645
646 if(isset($params['FILTER']) && is_array($params['FILTER']))
647 {
648 $arFilter = array_change_key_case($params['FILTER'], CASE_UPPER);
649 }
650
652 $arFilter['IBLOCK_ID'] = $iBlockId;
653 $arFilter['CHECK_PERMISSIONS'] = 'Y';
654
655 $dbRes = \CIBlockElement::GetList(
656 $arSort,
657 $arFilter,
658 false,
659 self::getNavData($n),
660 array('ID', 'IBLOCK_ID', 'TIMESTAMP_X', 'MODIFIED_BY', 'DATE_CREATE', 'CREATED_BY', 'ACTIVE', 'DATE_ACTIVE_FROM', 'DATE_ACTIVE_TO', 'SORT', 'NAME', 'PREVIEW_PICTURE', 'PREVIEW_TEXT', 'DETAIL_PICTURE', 'DETAIL_TEXT', 'CODE', 'IBLOCK_SECTION_ID')
661 );
662
663 $result = array();
664 while ($el = $dbRes->GetNextElement(false))
665 {
666 $res = $el->GetFields();
667 $arProps = $el->GetProperties();
668
669 foreach($res as $key => $value)
670 {
671 if(array_key_exists('~'.$key, $res))
672 {
673 $res[$key] = $res['~'.$key];
674 unset($res['~'.$key]);
675 }
676 }
677
678 $res['ENTITY'] = $params['ENTITY'];
679 $res['SECTION'] = $res['IBLOCK_SECTION_ID'];
680
681 if(!empty($arProps))
682 {
683 $res['PROPERTY_VALUES'] = array();
684 foreach($arProps as $prop)
685 {
686 if($prop['PROPERTY_TYPE'] == 'F')
687 {
688 if($prop['VALUE'] > 0)
689 {
690 $prop['~VALUE'] = self::getFile($prop['~VALUE']);
691 }
692 }
693
694 $res['PROPERTY_VALUES'][$prop['CODE']] = $prop['~VALUE'];
695 }
696 }
697
698 $res['DATE_ACTIVE_FROM'] = CRestUtil::ConvertDateTime($res['DATE_ACTIVE_FROM']);
699 $res['DATE_ACTIVE_TO'] = CRestUtil::ConvertDateTime($res['DATE_ACTIVE_TO']);
700 $res['TIMESTAMP_X'] = CRestUtil::ConvertDateTime($res['TIMESTAMP_X']);
701 $res['DATE_CREATE'] = CRestUtil::ConvertDateTime($res['DATE_CREATE']);
702
703 if($res['PREVIEW_PICTURE'] > 0)
704 $res['PREVIEW_PICTURE'] = self::getFile($res['PREVIEW_PICTURE']);
705
706 if($res['DETAIL_PICTURE'] > 0)
707 $res['DETAIL_PICTURE'] = self::getFile($res['DETAIL_PICTURE']);
708
709 unset($res['IBLOCK_ID']);
710 unset($res['IBLOCK_SECTION_ID']);
711 unset($res['DETAIL_TEXT_TYPE']);
712 unset($res['PREVIEW_TEXT_TYPE']);
713 unset($res['ACTIVE_FROM']);
714 unset($res['ACTIVE_TO']);
715
716 $result[] = $res;
717 }
718
720 }
721
722 public static function entityItemAdd($params, $n, $server)
723 {
724 if(self::checkItemParams($params))
725 {
726 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
727 if($arIBlock)
728 {
729 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'element_edit'))
730 {
731 $arItemFields = self::prepareItem($params, $arIBlock, $server);
732
733 $ib = new \CIBlockElement();
734
735 $conn = Application::getConnection();
736 $conn->startTransaction();
737 $ID = false;
738 $error = '';
739 try
740 {
741 $ID = $ib->Add($arItemFields);
742 if (!$ID)
743 {
744 $error = $ib->getLastError();
745 }
746 }
747 catch (SqlQueryException)
748 {
749 $error = 'Internal error adding entity item. Try adding again.';
750 }
751 if ($error === '')
752 {
753 $conn->commitTransaction();
754
755 return $ID;
756 }
757 else
758 {
759 $conn->rollbackTransaction();
760 throw new RestException($error, RestException::ERROR_CORE);
761 }
762 }
763 else
764 {
765 throw new AccessException();
766 }
767 }
768 else
769 {
770 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
771 }
772 }
773 }
774
775 public static function entityItemUpdate($params, $n, $server)
776 {
777 if(self::checkItemParams($params))
778 {
779 $params['ID'] = intval($params['ID']);
780 if($params['ID'] <= 0)
781 {
782 throw new ArgumentNullException("ID");
783 }
784 else
785 {
786 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
787 if($arIBlock)
788 {
789 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'element_edit'))
790 {
791 $dbRes = \CIBlockElement::GetList(array(), array(
792 'ID' => $params['ID'],
793 'IBLOCK_ID' => $arIBlock['ID']
794 ), false, false, array('ID'));
795 $arRes = $dbRes->Fetch();
796
797 if($arRes)
798 {
799 $arItemFields = self::prepareItem($params, $arIBlock, $server);
800
801 if(count($arItemFields) > 0)
802 {
803 $ib = new \CIBlockElement();
804 $PROPS = false;
805
806 if(isset($arItemFields['PROPERTY_VALUES']))
807 {
808 $PROPS = $arItemFields['PROPERTY_VALUES'];
809 unset($arItemFields['PROPERTY_VALUES']);
810 }
811
812 if(isset($arItemFields["PREVIEW_PICTURE"]) && $arItemFields["PREVIEW_PICTURE"] == false)
813 {
814 $arItemFields["PREVIEW_PICTURE"] = array("del" => "Y");
815 }
816
817 if(isset($arItemFields["DETAIL_PICTURE"]) && $arItemFields["DETAIL_PICTURE"] == false)
818 {
819 $arItemFields["DETAIL_PICTURE"] = array("del" => "Y");
820 }
821
822 $conn = Application::getConnection();
823 $conn->startTransaction();
824 $error = '';
825 try
826 {
827 $res = $ib->Update($arRes['ID'], $arItemFields);
828 if ($res)
829 {
830 if ($PROPS)
831 {
832 \CIBlockElement::SetPropertyValuesEx($arRes['ID'], $arIBlock['ID'], $PROPS);
833 }
834 }
835 else
836 {
837 $error = $ib->getLastError();
838 }
839 }
840 catch (SqlQueryException)
841 {
842 $error = 'Internal error updating entity item. Try updating again.';
843 }
844 if ($error === '')
845 {
846 $conn->commitTransaction();
847 }
848 else
849 {
850 $conn->rollbackTransaction();
851 throw new RestException($error, RestException::ERROR_CORE);
852 }
853 }
854
855 return true;
856 }
857 else
858 {
859 throw new RestException('Item not found', self::ERROR_ITEM_NOT_FOUND);
860 }
861 }
862 else
863 {
864 throw new AccessException();
865 }
866 }
867 else
868 {
869 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
870 }
871 }
872 }
873 }
874
875 public static function entityItemDelete($params, $n, $server)
876 {
878 global $APPLICATION;
879
880 if(self::checkItemParams($params))
881 {
882 $params['ID'] = intval($params['ID']);
883 if($params['ID'] <= 0)
884 {
885 throw new ArgumentNullException("ID");
886 }
887 else
888 {
889 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
890 if($arIBlock)
891 {
892 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'element_delete'))
893 {
894 $dbRes = \CIBlockElement::GetList(
895 [],
896 [
897 'ID' => $params['ID'],
898 'IBLOCK_ID' => $arIBlock['ID']
899 ],
900 false,
901 false,
902 [
903 'ID',
904 ]
905 );
906 $arRes = $dbRes->Fetch();
907 if($arRes)
908 {
909 $conn = Application::getConnection();
910 $conn->startTransaction();
911 $error = '';
912 try
913 {
914 if (!\CIBlockElement::Delete($params['ID']))
915 {
916 $ex = $APPLICATION->GetException();
917 $error =
918 $ex
919 ? $ex->GetString()
920 : 'Unable to delete item'
921 ;
922 unset(
923 $ex,
924 );
925 }
926 }
927 catch (SqlQueryException)
928 {
929 $error = 'Internal error deleting entity item. Try deleting again.';
930 }
931 if ($error === '')
932 {
933 $conn->commitTransaction();
934 }
935 else
936 {
937 $conn->rollbackTransaction();
938 throw new RestException($error, RestException::ERROR_CORE);
939 }
940
941 return true;
942 }
943 else
944 {
945 throw new RestException('Item not found', self::ERROR_ITEM_NOT_FOUND);
946 }
947 }
948 else
949 {
950 throw new AccessException();
951 }
952 }
953 else
954 {
955 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
956 }
957 }
958 }
959 }
960
961 public static function entityItemPropertyGet($params, $n, $server)
962 {
963 if(self::checkItemPropertyParams($params))
964 {
965 if(self::checkEntity($params['ENTITY'], $server))
966 {
967 if(isset($params['PROPERTY']) && $params['PROPERTY'] != '')
968 {
969 $arField = self::getItemProperty($params['PROPERTY'], $params['ENTITY'], $server);
970 if(is_array($arField))
971 {
972 return array(
973 'PROPERTY' => $arField['CODE'],
974 'NAME' => $arField['NAME'],
975 'TYPE' => $arField['PROPERTY_TYPE'],
976 'SORT' => $arField['SORT'],
977 );
978 }
979 else
980 {
981 throw new RestException('Property not found', self::ERROR_PROPERTY_NOT_FOUND);
982 }
983 }
984 else
985 {
986 $result = array();
987 $dbRes = self::getItemProperties($params['ENTITY'], $server);
988 while ($arField = $dbRes->Fetch())
989 {
990 $result[] = array(
991 'PROPERTY' => $arField['CODE'],
992 'NAME' => $arField['NAME'],
993 'TYPE' => $arField['PROPERTY_TYPE'],
994 'SORT' => $arField['SORT'],
995 );
996 }
997 return $result;
998 }
999 }
1000 else
1001 {
1002 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
1003 }
1004 }
1005 }
1006
1007 public static function entityItemPropertyAdd($params, $n, $server)
1008 {
1009 if(self::checkItemPropertyParams($params))
1010 {
1011 if(!self::checkItemProperty($params['PROPERTY'], $params['ENTITY'], $server))
1012 {
1013 if(!isset($params['PROPERTY']))
1014 {
1015 throw new ArgumentNullException('PROPERTY');
1016 }
1017
1018 $arIBlock = self::getIBlock(self::getEntityIBlockCode($params['ENTITY'], $server));
1019 if($arIBlock)
1020 {
1021 if(\CIBlockRights::UserHasRightTo($arIBlock['ID'], $arIBlock['ID'], 'iblock_edit'))
1022 {
1023 $arFields = array(
1024 "IBLOCK_ID" => $arIBlock['ID'],
1025 "CODE" => $params['PROPERTY'],
1026 "NAME" => $params['NAME'],
1027 "ACTIVE" => "Y",
1028 "PROPERTY_TYPE" => $params['TYPE'],
1029 "SORT" => $params['SORT'],
1030 );
1031
1032 if($params['TYPE'] == 'L')
1033 {
1034 throw new \Bitrix\Main\NotSupportedException(self::ERROR_UNSUPPORTED_PROPERTY_TYPE);
1035 }
1036
1037 $ibp = new \CIBlockProperty;
1038
1039 $conn = Application::getConnection();
1040 $conn->startTransaction();
1041 $propId = false;
1042 $error = '';
1043 try
1044 {
1045 $propId = $ibp->Add($arFields);
1046 if (!$propId)
1047 {
1048 $error = $ibp->getLastError();
1049 }
1050 }
1051 catch (SqlQueryException)
1052 {
1053 $error = 'Internal error adding entity property. Try adding again.';
1054 }
1055 if ($error === '')
1056 {
1057 $conn->commitTransaction();
1058 }
1059 else
1060 {
1061 $conn->rollbackTransaction();
1062 throw new RestException($error, RestException::ERROR_CORE);
1063 }
1064
1065 return true;
1066 }
1067 else
1068 {
1069 throw new AccessException();
1070 }
1071 }
1072 else
1073 {
1074 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
1075 }
1076 }
1077 else
1078 {
1079 throw new RestException ('Property already exists', self::ERROR_PROPERTY_ALREADY_EXISTS);
1080 }
1081 }
1082 }
1083
1084 public static function entityItemPropertyUpdate($params, $n, $server)
1085 {
1086 if(self::checkItemPropertyParams($params))
1087 {
1088 if(self::checkEntity($params['ENTITY'], $server))
1089 {
1090 $arField = self::getItemProperty($params['PROPERTY'], $params['ENTITY'], $server);
1091 if($arField)
1092 {
1093 if(\CIBlockRights::UserHasRightTo($arField['IBLOCK_ID'], $arField['IBLOCK_ID'], 'iblock_edit'))
1094 {
1095 $arPropFields = array();
1096
1097 if(isset($params['PROPERTY_NEW']) && $params['PROPERTY_NEW'] != $params['PROPERTY'])
1098 {
1099 if (self::checkItemProperty($params['PROPERTY_NEW'], $params['ENTITY'], $server))
1100 {
1101 throw new RestException ('Property '.$params['PROPERTY_NEW'].' already exists', self::ERROR_PROPERTY_ALREADY_EXISTS);
1102 }
1103
1104 $arPropFields["CODE"] = $params['PROPERTY_NEW'];
1105 }
1106
1107 if(isset($params['NAME']))
1108 {
1109 $arPropFields['NAME'] = trim($params['NAME']);
1110 }
1111
1112 if(isset($params['SORT']))
1113 {
1114 $arPropFields['SORT'] = trim($params['SORT']);
1115 }
1116
1117 if(isset($params['TYPE']) && $arField['PROPERTY_TYPE'] != $params['TYPE'])
1118 {
1119 if($params['TYPE'] == 'F')
1120 {
1121 throw new \Bitrix\Main\ArgumentException('Cannot change property type to File', "TYPE");
1122 }
1123 // elseif($params['TYPE'] == 'L')
1124 // {
1125 // throw new \Bitrix\Main\NotSupportedException(self::ERROR_UNSUPPORTED_PROPERTY_TYPE);
1126 // }
1127 else
1128 {
1129 $arPropFields['PROPERTY_TYPE'] = $params['TYPE'];
1130 }
1131 }
1132
1133 $ibp = new \CIBlockProperty;
1134
1135 $conn = Application::getConnection();
1136 $conn->startTransaction();
1137 $error = '';
1138 try
1139 {
1140 if (!$ibp->Update($arField['ID'], $arPropFields))
1141 {
1142 $error = $ibp->getLastError();
1143 }
1144 }
1145 catch (SqlQueryException)
1146 {
1147 $error = 'Internal error updating entity property. Try updating again.';
1148 }
1149 if ($error === '')
1150 {
1151 $conn->commitTransaction();
1152 }
1153 else
1154 {
1155 $conn->rollbackTransaction();
1156 throw new RestException($error, RestException::ERROR_CORE);
1157 }
1158
1159 return true;
1160 }
1161 else
1162 {
1163 throw new AccessException();
1164 }
1165 }
1166 else
1167 {
1168 throw new RestException('Property not found', self::ERROR_PROPERTY_NOT_FOUND);
1169 }
1170 }
1171 else
1172 {
1173 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
1174 }
1175 }
1176 }
1177
1178 public static function entityItemPropertyDelete($params, $n, $server)
1179 {
1181 global $APPLICATION;
1182
1183 if(self::checkItemPropertyParams($params))
1184 {
1185 if(self::checkEntity($params['ENTITY'], $server))
1186 {
1187 $arField = self::getItemProperty($params['PROPERTY'], $params['ENTITY'], $server);
1188 if($arField)
1189 {
1190 if(\CIBlockRights::UserHasRightTo($arField['IBLOCK_ID'], $arField['IBLOCK_ID'], 'iblock_edit'))
1191 {
1192 $conn = Application::getConnection();
1193 $conn->startTransaction();
1194 $error = '';
1195 try
1196 {
1197 if (!CIBlockProperty::Delete($arField['ID']))
1198 {
1199 $ex = $APPLICATION->GetException();
1200 $error =
1201 $ex
1202 ? $ex->GetString()
1203 : 'Unable to delete item'
1204 ;
1205 unset(
1206 $ex,
1207 );
1208 }
1209 }
1210 catch (SqlQueryException)
1211 {
1212 $error = 'Internal error deleting entity property. Try deleting again.';
1213 }
1214 if ($error === '')
1215 {
1216 $conn->commitTransaction();
1217 }
1218 else
1219 {
1220 $conn->rollbackTransaction();
1221 throw new RestException($error, RestException::ERROR_CORE);
1222 }
1223
1224 return true;
1225 }
1226 else
1227 {
1228 throw new AccessException();
1229 }
1230 }
1231 else
1232 {
1233 throw new RestException('Property not found', self::ERROR_PROPERTY_NOT_FOUND);
1234 }
1235 }
1236 else
1237 {
1238 throw new RestException('Entity not found', self::ERROR_ENTITY_NOT_FOUND);
1239 }
1240 }
1241 }
1242
1243 public static function Clean($appId)
1244 {
1245 if(CModule::IncludeModule('iblock'))
1246 {
1247 $dbRes = \CIBlock::GetList(array(), array(
1248 '=TYPE' => self::getIBlockType(),
1249 'CODE' => self::ENTITY_IBLOCK_CODE_PREFIX."_".$appId.'%'
1250 ));
1251 while ($arRes = $dbRes->Fetch())
1252 {
1253 \CIBlock::Delete($arRes['ID']);
1254 }
1255 }
1256 }
1257
1258 protected static function checkIblockType()
1259 {
1260 $iblockType = COption::GetOptionString("rest", "entity_iblock_type", "rest_entity");
1261
1262 $arIBlockTypeData = array(
1263 'ID' => $iblockType,
1264 'SECTIONS' => 'Y',
1265 'IN_RSS' => 'N',
1266 );
1267
1268 $obBlocktype = new \CIBlockType();
1269 if($obBlocktype->Add($arIBlockTypeData))
1270 {
1271 COption::SetOptionString("rest", "entity_iblock_type", $iblockType);
1272
1273 $dbRes = \CIBlock::GetList(array(), array('TYPE' => $iblockType));
1274
1275 $taskId = \CIBlockRights::LetterToTask('X');
1276
1277 while ($arIBlock = $dbRes->Fetch())
1278 {
1279 $obIBlockRights = new \CIBlockRights($arIBlock['ID']);
1280 $arRights = $obIBlockRights->GetRights();
1281
1282 foreach($arRights as $key => $arRight)
1283 {
1284 if($arRight['GROUP_CODE'] == 'U1')
1285 {
1286 unset($arRights[$key]);
1287 }
1288 }
1289
1290 $arRights['n0'] = array(
1291 'GROUP_CODE' => 'U1',
1292 'TASK_ID' => $taskId,
1293 'DO_CLEAN' => 'N',
1294 );
1295
1296 $obIBlockRights->SetRights($arRights);
1297 }
1298 }
1299 }
1300
1301 protected static function getIBlock($code, $bSkipCheck = false)
1302 {
1303 $dbRes = \CIBlock::GetList(array(), array(
1304 '=TYPE' => self::getIBlockType(),
1305 '=CODE' => $code,
1306 ));
1307
1308 $arRes = $dbRes->Fetch();
1309 if(!$arRes && !$bSkipCheck)
1310 {
1312 return self::getIBlock($code, true);
1313 }
1314
1315 return $arRes;
1316 }
1317
1318 protected static function getIBlocks($server)
1319 {
1320 return \CIBlock::GetList(array(), array(
1321 '=TYPE' => self::getIBlockType(),
1322 'CODE' => self::getEntityIBlockCode('%', $server)
1323 ));
1324 }
1325
1326 protected static function getItemProperty($property, $entity, $server)
1327 {
1328 $dbRes = \CIBlockProperty::GetByID($property, false, self::getEntityIBlockCode($entity, $server));
1329 return $dbRes->Fetch();
1330 }
1331
1332 protected static function getItemProperties($entity, $server)
1333 {
1334 return \CIBlockProperty::GetList(
1335 array('SORT' => 'ASC'),
1336 array('IBLOCK_CODE' => self::getEntityIBlockCode($entity, $server))
1337 );
1338 }
1339
1340 protected static function checkParams(&$params)
1341 {
1342 $params = array_change_key_case($params, CASE_UPPER);
1343
1344 if(isset($params['ENTITY']))
1345 {
1346 $params['ENTITY'] = preg_replace('/[^a-zA-Z0-9_]/i', '', trim(strval($params['ENTITY'])));
1347
1348 if($params['ENTITY'] == '')
1349 {
1350 throw new ArgumentNullException("ENTITY");
1351 }
1352
1353 if(isset($params['ENTITY_NEW']))
1354 {
1355 $params['ENTITY_NEW'] = preg_replace('/[^a-zA-Z0-9_]/i', '', trim(strval($params['ENTITY_NEW'])));
1356 }
1357 }
1358 else
1359 {
1360 throw new ArgumentNullException("ENTITY");
1361 }
1362
1363 return true;
1364 }
1365
1366 protected static function checkItemParams(&$params)
1367 {
1368 if(self::checkParams($params))
1369 {
1370 return true;
1371 }
1372 else
1373 {
1374 return false;
1375 }
1376 }
1377
1378 protected static function checkSectionParams(&$params)
1379 {
1380 if(self::checkParams($params))
1381 {
1382 return true;
1383 }
1384 else
1385 {
1386 return false;
1387 }
1388 }
1389
1390 protected static function checkItemPropertyParams(&$params)
1391 {
1392 if(self::checkParams($params))
1393 {
1394 if(isset($params['PROPERTY']))
1395 {
1396 $params['PROPERTY'] = preg_replace('/[^a-zA-Z0-9_]/i', '', trim(strval($params['PROPERTY'])));
1397 }
1398
1399 if(isset($params['PROPERTY_NEW']))
1400 {
1401 $params['PROPERTY_NEW'] = preg_replace('/[^a-zA-Z0-9_]/i', '', trim(strval($params['PROPERTY_NEW'])));
1402 }
1403
1404 if(isset($params['TYPE']))
1405 {
1406 $params['TYPE'] = mb_strtoupper($params['TYPE']);
1407 if(!in_array($params['TYPE'], array('S', 'N', 'F'/*, 'L'*/)))
1408 {
1409 throw new ArgumentException('Wrong entity item property type', "TYPE");
1410 }
1411 }
1412
1413 if(isset($params['SORT']))
1414 {
1415 $params['SORT'] = intval($params['SORT']);
1416 }
1417
1418 return true;
1419 }
1420 else
1421 {
1422 return false;
1423 }
1424 }
1425
1426 protected static function checkEntity($entity, $server)
1427 {
1428 if(self::getIBlock(self::getEntityIBlockCode($entity, $server)))
1429 return true;
1430 else
1431 return false;
1432 }
1433
1434 protected static function checkItemProperty($property, $entity, $server)
1435 {
1436 if(self::getItemProperty($property, $entity, $server))
1437 return true;
1438 else
1439 return false;
1440 }
1441
1442 protected static function parseEntity($iblock, \CRestServer $server)
1443 {
1444 if(!$server->getClientId())
1445 {
1446 throw new AccessException("Application context required");
1447 }
1448
1449 $str = self::ENTITY_IBLOCK_CODE_PREFIX."_".$server->getClientId()."_";
1450
1451 if(mb_substr($iblock, 0, mb_strlen($str)) === $str)
1452 {
1453 return mb_substr($iblock, mb_strlen($str));
1454 }
1455 else
1456 {
1457 return false;
1458 }
1459 }
1460
1461 protected static function getEntityIBlockCode($entity, \CRestServer $server)
1462 {
1463 if(!$server->getClientId())
1464 {
1465 throw new AccessException("Application context required");
1466 }
1467
1468 return self::ENTITY_IBLOCK_CODE_PREFIX."_".$server->getClientId()."_".$entity;
1469 }
1470
1471 protected static function getIBlockType()
1472 {
1473 return COption::GetOptionString("rest", "entity_iblock_type", "rest_entity");
1474 }
1475
1476 protected static function prepareItem($params, $arIBlock, $server)
1477 {
1478 $arItemFields = array();
1479
1480 foreach($params as $key => $param)
1481 {
1482 switch($key)
1483 {
1484 case 'ENTITY':
1485 case 'IBLOCK_ID':
1486 case 'ID':
1487
1488 case 'RIGHTS':
1489 case 'PREVIEW_TEXT_TYPE':
1490 case 'DETAIL_TEXT_TYPE':
1491 case 'CREATED_BY':
1492 case 'MODIFIED_BY':
1493 case 'DATE_CREATE':
1494 case 'SHOW_COUNTER':
1495 case 'SHOW_COUNTER_START':
1496 case 'TAGS':
1497
1498 break;
1499
1500 case 'PROPERTY_VALUES':
1501 $PROPS = array();
1502 $dbRes = self::getItemProperties($params['ENTITY'], $server);
1503 while ($arField = $dbRes->Fetch())
1504 {
1505 if(isset($param[$arField['CODE']]))
1506 {
1507 if($arField['PROPERTY_TYPE'] == 'F')
1508 {
1509 $PROPS[$arField['CODE']] = CRestUtil::saveFile($param[$arField['CODE']]);
1510 }
1511 else
1512 {
1513 $PROPS[$arField['CODE']] = $param[$arField['CODE']];
1514 }
1515 }
1516 }
1517 $arItemFields['PROPERTY_VALUES'] = $PROPS;
1518 break;
1519
1520 case 'DATE_ACTIVE_FROM':
1521 case 'DATE_ACTIVE_TO':
1522 $arItemFields[$key] = CRestUtil::unConvertDateTime($param, true);
1523 break;
1524
1525 case 'PREVIEW_PICTURE':
1526 case 'DETAIL_PICTURE':
1527 $arItemFields[$key] = CRestUtil::saveFile($param);
1528 break;
1529
1530 case 'SECTION':
1531 $arItemFields['IBLOCK_SECTION_ID'] = $param;
1532 break;
1533
1534 default:
1535 if(!preg_match('/[^a-zA-Z0-9_]/', $key))
1536 $arItemFields[$key] = $param;
1537 break;
1538 }
1539 }
1540
1541 $arItemFields['IBLOCK_ID'] = $arIBlock['ID'];
1542
1543 return $arItemFields;
1544 }
1545
1546 protected static function prepareSection($params, $arIBlock, $server)
1547 {
1548 $arSectionFields = array();
1549
1550 foreach($params as $key => $param)
1551 {
1552 switch($key)
1553 {
1554 case 'ENTITY':
1555 case 'IBLOCK_ID':
1556 case 'ID':
1557
1558 case 'RIGHTS':
1559 case 'DESCRIPTION_TYPE':
1560 case 'CREATED_BY':
1561 case 'MODIFIED_BY':
1562 case 'DATE_CREATE':
1563 case 'XML_ID':
1564 case 'EXTERNAL_ID':
1565 case 'TIMESTAMP_X_UNIX':
1566
1567 break;
1568
1569 case 'PICTURE':
1570 case 'DETAIL_PICTURE':
1571 $arSectionFields[$key] = CRestUtil::saveFile($param);
1572 break;
1573
1574 case 'SECTION':
1575 $arSectionFields['IBLOCK_SECTION_ID'] = $param;
1576 break;
1577
1578 default:
1579 if(!preg_match('/[^a-zA-Z0-9_]/', $key))
1580 $arSectionFields[$key] = $param;
1581 break;
1582 }
1583 }
1584
1585 $arSectionFields['IBLOCK_ID'] = $arIBlock['ID'];
1586
1587 return $arSectionFields;
1588 }
1589
1590 protected static function checkFilter($arFilter, $bChangeLogic = true)
1591 {
1592 if(is_array($arFilter))
1593 {
1594 $arFilter = array_change_key_case($arFilter, CASE_UPPER);
1595
1596 foreach ($arFilter as $key => $value)
1597 {
1598 if(is_numeric($key) && is_array($value))
1599 {
1600 $arFilter[$key] = self::checkFilter($value, false);
1601 }
1602 elseif(preg_match('/^([^a-zA-Z]*)(.*)/', $key, $matches))
1603 {
1604 $operation = $matches[1];
1605 $field = $matches[2];
1606
1607 if(!in_array($operation, self::$arAllowedOperations))
1608 {
1609 unset($arFilter[$key]);
1610 }
1611 else
1612 {
1613 switch($field)
1614 {
1615 case 'DATE_ACTIVE_FROM':
1616 case 'DATE_ACTIVE_TO':
1617 case 'TIMESTAMP_X':
1618 case 'DATE_CREATE':
1619 $arFilter[$key] = CRestUtil::unConvertDateTime($value, true);
1620 break;
1621
1622 case 'SECTION':
1623 $arFilter[$operation.'IBLOCK_SECTION_ID'] = $value;
1624 unset($arFilter[$key]);
1625 break;
1626
1627 case 'IBLOCK_ID':
1628 case 'CHECK_PERMISSIONS':
1629 unset($arFilter[$key]);
1630 break;
1631
1632 case 'LOGIC':
1633 if($bChangeLogic)
1634 unset($arFilter[$key]);
1635 break;
1636
1637 default:
1638
1639 break;
1640 }
1641 }
1642 }
1643 else
1644 {
1645 unset($arFilter[$key]);
1646 }
1647 }
1648 }
1649
1650 return $arFilter;
1651 }
1652
1653 protected static function checkSectionFilter($arFilter, $bChangeLogic = true)
1654 {
1655 if(is_array($arFilter))
1656 {
1657 $arFilter = array_change_key_case($arFilter, CASE_UPPER);
1658
1659 foreach ($arFilter as $key => $value)
1660 {
1661 if(preg_match('/^([^a-zA-Z]*)(.*)/', $key, $matches))
1662 {
1663 $operation = $matches[1];
1664 $field = $matches[2];
1665
1666 if(!in_array($operation, self::$arAllowedOperations))
1667 {
1668 unset($arFilter[$key]);
1669 }
1670 else
1671 {
1672 switch($field)
1673 {
1674 case 'TIMESTAMP_X':
1675 case 'DATE_CREATE':
1676 $arFilter[$key] = CRestUtil::unConvertDateTime($value, true);
1677 break;
1678
1679 case 'SECTION':
1680 $arFilter[$operation.'IBLOCK_SECTION_ID'] = $value;
1681 unset($arFilter[$key]);
1682 break;
1683
1684 case 'IBLOCK_ID':
1685 case 'CHECK_PERMISSIONS':
1686 unset($arFilter[$key]);
1687 break;
1688
1689 default:
1690 break;
1691 }
1692 }
1693 }
1694 else
1695 {
1696 unset($arFilter[$key]);
1697 }
1698 }
1699 }
1700
1701 return $arFilter;
1702 }
1703
1704 protected static function checkRights($arRights)
1705 {
1706 $res = array();
1707 $i = 0;
1708
1709 foreach($arRights as $rightCode => $access)
1710 {
1711 if($access == 'W' || $access == 'R' || $access == 'X')
1712 {
1713 $res['n'.($i++)] = array(
1714 'GROUP_CODE' => $rightCode,
1715 'TASK_ID' => \CIBlockRights::LetterToTask($access),
1716 'DO_CLEAN' => 'N',
1717 );
1718 }
1719 }
1720
1721 return $res;
1722 }
1723
1724 protected static function getFile($fileId)
1725 {
1726 $arFile = CFile::GetFileArray($fileId);
1727 if(is_array($arFile))
1728 {
1729 return \CHTTP::URN2URI($arFile['SRC']);
1730 }
1731 else
1732 {
1733 return '';
1734 }
1735 }
1736}
global $APPLICATION
Определения include.php:80
static resolveIdByCode(string $code, ?string $siteId=null)
Определения iblocktable.php:641
Определения restentity.php:11
static getItemProperty($property, $entity, $server)
Определения restentity.php:1326
static checkItemPropertyParams(&$params)
Определения restentity.php:1390
static entityItemUpdate($params, $n, $server)
Определения restentity.php:775
const ERROR_PROPERTY_ALREADY_EXISTS
Определения restentity.php:19
const ERROR_ENTITY_ALREADY_EXISTS
Определения restentity.php:14
static entityItemGet($params, $n, $server)
Определения restentity.php:617
const ERROR_UNSUPPORTED_PROPERTY_TYPE
Определения restentity.php:20
const ERROR_SECTION_NOT_FOUND
Определения restentity.php:16
static getFile($fileId)
Определения restentity.php:1724
const ENTITY_IBLOCK_CODE_PREFIX
Определения restentity.php:12
static entityAdd($params, $n, $server)
Определения restentity.php:56
static entitySectionAdd($params, $n, $server)
Определения restentity.php:411
static entitySectionUpdate($params, $n, $server)
Определения restentity.php:464
static Clean($appId)
Определения restentity.php:1243
static entitySectionGet($params, $n, $server)
Определения restentity.php:348
static entityUpdate($params, $n, $server)
Определения restentity.php:206
const ERROR_ENTITY_NOT_FOUND
Определения restentity.php:15
static getIBlock($code, $bSkipCheck=false)
Определения restentity.php:1301
static entityItemPropertyDelete($params, $n, $server)
Определения restentity.php:1178
static checkSectionParams(&$params)
Определения restentity.php:1378
static checkItemParams(&$params)
Определения restentity.php:1366
static getIBlockType()
Определения restentity.php:1471
static entityItemPropertyAdd($params, $n, $server)
Определения restentity.php:1007
static OnRestServiceBuildDescription()
Определения restentity.php:25
static checkRights($arRights)
Определения restentity.php:1704
static parseEntity($iblock, \CRestServer $server)
Определения restentity.php:1442
static entityItemPropertyUpdate($params, $n, $server)
Определения restentity.php:1084
const ERROR_ITEM_NOT_FOUND
Определения restentity.php:17
static checkParams(&$params)
Определения restentity.php:1340
static getItemProperties($entity, $server)
Определения restentity.php:1332
static prepareSection($params, $arIBlock, $server)
Определения restentity.php:1546
static entityDelete($params, $n, $server)
Определения restentity.php:290
static entityItemPropertyGet($params, $n, $server)
Определения restentity.php:961
static entityRights($params, $n, $server)
Определения restentity.php:166
static getEntityIBlockCode($entity, \CRestServer $server)
Определения restentity.php:1461
static entityGet($params, $n, $server)
Определения restentity.php:121
static entityItemAdd($params, $n, $server)
Определения restentity.php:722
static checkFilter($arFilter, $bChangeLogic=true)
Определения restentity.php:1590
static entitySectionDelete($params, $n, $server)
Определения restentity.php:539
static checkIblockType()
Определения restentity.php:1258
static prepareItem($params, $arIBlock, $server)
Определения restentity.php:1476
const ERROR_UNSUPPORTED_PROPERTY_TYPE_CHANGE
Определения restentity.php:21
static getIBlocks($server)
Определения restentity.php:1318
static checkEntity($entity, $server)
Определения restentity.php:1426
static entityItemDelete($params, $n, $server)
Определения restentity.php:875
static checkItemProperty($property, $entity, $server)
Определения restentity.php:1434
const ERROR_PROPERTY_NOT_FOUND
Определения restentity.php:18
static checkSectionFilter($arFilter, $bChangeLogic=true)
Определения restentity.php:1653
Определения iblock_rights.php:7
Определения rest.php:24
getClientId()
Определения rest.php:362
Определения rest.php:896
static setNavData($result, $dbRes)
Определения rest.php:927
$str
Определения commerceml2.php:63
$arFields
Определения dblapprove.php:5
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$res
Определения filter_act.php:7
$result
Определения get_property_values.php:14
if($ajaxMode) $ID
Определения get_user.php:27
$entity
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
$iBlockId
Определения iblock_subelement_generator.php:45
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
if(!is_array($deviceNotifyCodes)) $access
Определения options.php:174
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if(empty($signedUserToken)) $key
Определения quickway.php:257
$i
Определения factura.php:643
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"
Определения waybill.php:936
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$matches
Определения index.php:22
$arRes
Определения options.php:104
$error
Определения subscription_card_product.php:20
$n
Определения update_log.php:107
$arFilter
Определения user_search.php:106
$dbRes
Определения yandex_detail.php:168
$arIBlock['PROPERTY']
Определения yandex_detail.php:172