1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
restservice.php
См. документацию.
1<?php
3
22
24
26{
27 const SCOPE = "lists";
28
29 public static function onRestServiceBuildDescription()
30 {
31 return array(
32 static::SCOPE => array(
33 "lists.get.iblock.type.id" => array(__CLASS__, "getIblockTypeId"),
34
35 "lists.add" => array(__CLASS__, "addLists"),
36 "lists.get" => array(__CLASS__, "getLists"),
37 "lists.update" => array(__CLASS__, "updateLists"),
38 "lists.delete" => array(__CLASS__, "deleteLists"),
39
40 "lists.section.add" => array(__CLASS__, "addSection"),
41 "lists.section.get" => array(__CLASS__, "getSection"),
42 "lists.section.update" => array(__CLASS__, "updateSection"),
43 "lists.section.delete" => array(__CLASS__, "deleteSection"),
44
45 "lists.field.add" => array(__CLASS__, "addField"),
46 "lists.field.get" => array(__CLASS__, "getFields"),
47 "lists.field.update" => array(__CLASS__, "updateField"),
48 "lists.field.delete" => array(__CLASS__, "deleteField"),
49 "lists.field.type.get" => array(__CLASS__, "getFieldTypes"),
50
51 "lists.element.add" => array(__CLASS__, "addElement"),
52 "lists.element.get" => array(__CLASS__, "getElement"),
53 "lists.element.update" => array(__CLASS__, "updateElement"),
54 "lists.element.delete" => array(__CLASS__, "deleteElement"),
55 "lists.element.get.file.url" => array(__CLASS__, "getFileUrl"),
56 )
57 );
58 }
59
60 public static function getIblockTypeId(array $params, $n, \CRestServer $server)
61 {
62 $param = new Param($params);
63
64 $iblockType = new IblockType($param);
65
66 $iblockTypeId = $iblockType->getIblockTypeId();
67 if ($iblockType->hasErrors())
68 {
69 self::throwError($iblockType->getErrors());
70 }
71
72 return $iblockTypeId;
73 }
74
75 public static function addLists(array $params, $n, \CRestServer $server)
76 {
77 $param = new Param($params);
78
79 $iblock = new Iblock($param);
80 if ($iblock->isExist())
81 {
82 self::throwError($iblock->getErrors(), "Iblock already exists", Iblock::ERROR_IBLOCK_ALREADY_EXISTS);
83 }
84
85 global $USER;
86 $rightParam = new RightParam($param);
87 $rightParam->setUser($USER);
88
89 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
90 {
91 throw new AccessException('Available only on extended plans');
92 }
93
94 $right = new Right($rightParam, new IblockRight($rightParam));
95 $right->checkPermission(IblockRight::EDIT);
96 if ($right->hasErrors())
97 {
98 self::throwError($right->getErrors());
99 }
100
101 $conn = Application::getConnection();
102 $conn->startTransaction();
103 $errors = [];
104 try
105 {
106 $iblockId = $iblock->add();
107 if (!$iblockId)
108 {
109 $errors = $iblock->getErrors();
110 }
111 }
112 catch (SqlQueryException)
113 {
114 $iblockId = false;
115 $errors[] = new Error('Internal error adding list. Try adding again.');
116 }
117 if ($iblockId)
118 {
119 $conn->commitTransaction();
120
121 return $iblockId;
122 }
123 else
124 {
125 $conn->rollbackTransaction();
126
127 self::throwError($errors);
128 }
129 }
130
131 public static function getLists(array $params, $n, \CRestServer $server)
132 {
133 $param = new Param($params);
134
135 global $USER;
136 $rightParam = new RightParam($param);
137 $rightParam->setUser($USER);
138
139 if (!\CLists::isListFeatureEnabled((string)$rightParam->getIblockTypeId()))
140 {
141 throw new AccessException('Available only on extended plans');
142 }
143
144 $right = new Right($rightParam, new IblockRight($rightParam));
145 $right->checkPermission(IblockRight::READ);
146 if ($right->hasErrors())
147 {
148 self::throwError($right->getErrors());
149 }
150
151 $iblock = new Iblock($param);
152 list ($iblocks, $queryObject) = $iblock->get(self::getNavData($n));
153 if (empty($iblocks) || $iblock->hasErrors())
154 {
155 return [];
156 }
157 else
158 {
159 return self::setNavData(array_values($iblocks), $queryObject);
160 }
161 }
162
163 public static function updateLists(array $params, $n, \CRestServer $server)
164 {
165 $param = new Param($params);
166
167 $iblock = new Iblock($param);
168 if (!$iblock->isExist())
169 {
170 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
171 }
172
173 global $USER;
174 $rightParam = new RightParam($param);
175 $rightParam->setUser($USER);
176
177 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
178 {
179 throw new AccessException('Available only on extended plans');
180 }
181
182 $right = new Right($rightParam, new IblockRight($rightParam));
183 $right->checkPermission(IblockRight::EDIT);
184 if ($right->hasErrors())
185 {
186 self::throwError($right->getErrors());
187 }
188
189 $conn = Application::getConnection();
190 $conn->startTransaction();
191 $errors = [];
192 try
193 {
194 $success = $iblock->update();
195 if (!$success)
196 {
197 $errors = $iblock->getErrors();
198 }
199 }
200 catch (SqlQueryException)
201 {
202 $success = false;
203 $errors[] = new Error('Internal error updating the list. Try updating again.');
204 }
205 if ($success)
206 {
207 $conn->commitTransaction();
208
209 return true;
210 }
211 else
212 {
213 $conn->rollbackTransaction();
214
215 self::throwError($errors);
216 }
217 }
218
219 public static function deleteLists(array $params, $n, \CRestServer $server)
220 {
221 $param = new Param($params);
222
223 $iblock = new Iblock($param);
224 if (!$iblock->isExist())
225 {
226 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
227 }
228
229 global $USER;
230 $rightParam = new RightParam($param);
231 $rightParam->setUser($USER);
232
233 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
234 {
235 throw new AccessException('Available only on extended plans');
236 }
237
238 $right = new Right($rightParam, new IblockRight($rightParam));
239 $right->checkPermission(IblockRight::EDIT);
240 if ($right->hasErrors())
241 {
242 self::throwError($right->getErrors());
243 }
244
245 $conn = Application::getConnection();
246 $conn->startTransaction();
247 $errors = [];
248 try
249 {
250 $success = $iblock->delete();
251 if (!$success)
252 {
253 $errors = $iblock->getErrors();
254 }
255 }
256 catch (SqlQueryException)
257 {
258 $success = false;
259 $errors[] = new Error('Internal error deleting list. Try deleting again.');
260 }
261 if ($success)
262 {
263 $conn->commitTransaction();
264
265 return true;
266 }
267 else
268 {
269 $conn->rollbackTransaction();
270
271 self::throwError($errors);
272 }
273 }
274
275 public static function addSection(array $params, $n, \CRestServer $server)
276 {
277 $param = new Param($params);
278 $params = $param->getParams();
279
280 global $USER;
281 $rightParam = new RightParam($param);
282 $rightParam->setUser($USER);
283 $rightParam->setEntityId($params["IBLOCK_SECTION_ID"]);
284
285 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
286 {
287 throw new AccessException('Available only on extended plans');
288 }
289
290 $right = new Right($rightParam, new SectionRight($rightParam));
291 $right->checkPermission(SectionRight::ADD);
292 if ($right->hasErrors())
293 {
294 self::throwError($right->getErrors());
295 }
296
297 $section = new Section($param);
298
299 $conn = Application::getConnection();
300 $conn->startTransaction();
301 $errors = [];
302 try
303 {
304 $sectionId = $section->add();
305 if (!$sectionId)
306 {
307 $errors = $section->getErrors();
308 }
309 }
310 catch (SqlQueryException)
311 {
312 $sectionId = false;
313 $errors[] = new Error('Internal error adding list section. Try adding again.');
314 }
315 if ($sectionId)
316 {
317 $conn->commitTransaction();
318
319 return $sectionId;
320 }
321 else
322 {
323 $conn->rollbackTransaction();
324
325 self::throwError($errors);
326 }
327 }
328
329 public static function getSection(array $params, $n, \CRestServer $server)
330 {
331 $param = new Param($params);
332 $params = $param->getParams();
333
334 global $USER;
335 $rightParam = new RightParam($param);
336 $rightParam->setUser($USER);
337 $rightParam->setEntityId($params["IBLOCK_SECTION_ID"]);
338
339 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
340 {
341 throw new AccessException('Available only on extended plans');
342 }
343
344 $right = new Right($rightParam, new SectionRight($rightParam));
345 $right->checkPermission(SectionRight::READ);
346 if ($right->hasErrors())
347 {
348 self::throwError($right->getErrors());
349 }
350
351 $section = new Section($param);
352 list ($sections, $queryObject) = $section->get(self::getNavData($n));
353 if (empty($sections) || $section->hasErrors())
354 {
355 return [];
356 }
357 else
358 {
359 return self::setNavData(array_values($sections), $queryObject);
360 }
361 }
362
363 public static function updateSection(array $params, $n, \CRestServer $server)
364 {
365 $param = new Param($params);
366 $params = $param->getParams();
367
368 $section = new Section($param);
369 if (!$section->isExist())
370 {
371 self::throwError($section->getErrors(), "Section not found", Section::ERROR_SECTION_NOT_FOUND);
372 }
373
374 global $USER;
375 $rightParam = new RightParam($param);
376 $rightParam->setUser($USER);
377 $rightParam->setEntityId($params["IBLOCK_SECTION_ID"]);
378
379 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
380 {
381 throw new AccessException('Available only on extended plans');
382 }
383
384 $right = new Right($rightParam, new SectionRight($rightParam));
385 $right->checkPermission(SectionRight::EDIT);
386 if ($right->hasErrors())
387 {
388 self::throwError($right->getErrors());
389 }
390
391 $conn = Application::getConnection();
392 $conn->startTransaction();
393 $errors = [];
394 try
395 {
396 $success = $section->update();
397 if (!$success)
398 {
399 $errors = $section->getErrors();
400 }
401 }
402 catch (SqlQueryException)
403 {
404 $success = false;
405 $errors[] = new Error('Internal error updating the list section. Try updating again.');
406 }
407 if ($success)
408 {
409 $conn->commitTransaction();
410
411 return true;
412 }
413 else
414 {
415 $conn->rollbackTransaction();
416
417 self::throwError($errors);
418 }
419 }
420
421 public static function deleteSection(array $params, $n, \CRestServer $server)
422 {
423 $param = new Param($params);
424 $params = $param->getParams();
425
426 $section = new Section($param);
427 if (!$section->isExist())
428 {
429 self::throwError($section->getErrors(), "Section not found", Section::ERROR_SECTION_NOT_FOUND);
430 }
431
432 global $USER;
433 $rightParam = new RightParam($param);
434 $rightParam->setUser($USER);
435 $rightParam->setEntityId($params["IBLOCK_SECTION_ID"]);
436
437 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
438 {
439 throw new AccessException('Available only on extended plans');
440 }
441
442 $right = new Right($rightParam, new SectionRight($rightParam));
443 $right->checkPermission(SectionRight::DELETE);
444 if ($right->hasErrors())
445 {
446 self::throwError($right->getErrors());
447 }
448
449 $conn = Application::getConnection();
450 $conn->startTransaction();
451 $errors = [];
452 try
453 {
454 $success = $section->delete();
455 if (!$success)
456 {
457 $errors = $section->getErrors();
458 }
459 }
460 catch (SqlQueryException)
461 {
462 $success = false;
463 $errors[] = new Error('Internal error deleting list section. Try deleting again.');
464 }
465 if ($success)
466 {
467 $conn->commitTransaction();
468
469 return true;
470 }
471 else
472 {
473 $conn->rollbackTransaction();
474
475 self::throwError($errors);
476 }
477 }
478
479 public static function addField(array $params, $n, \CRestServer $server)
480 {
481 $param = new Param($params);
482
483 $iblock = new Iblock($param);
484 if (!$iblock->isExist())
485 {
486 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
487 }
488
489 global $USER;
490 $rightParam = new RightParam($param);
491 $rightParam->setUser($USER);
492
493 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
494 {
495 throw new AccessException('Available only on extended plans');
496 }
497
498 $right = new Right($rightParam, new IblockRight($rightParam));
499 $right->checkPermission(IblockRight::EDIT);
500 if ($right->hasErrors())
501 {
502 self::throwError($right->getErrors());
503 }
504
505 $field = new Field($param);
506 $fieldId = $field->add();
507 if ($field->hasErrors())
508 {
509 self::throwError($field->getErrors());
510 }
511 else
512 {
513 return $fieldId;
514 }
515 }
516
517 public static function getFields(array $params, $n, \CRestServer $server)
518 {
519 $param = new Param($params);
520
521 $iblock = new Iblock($param);
522 if (!$iblock->isExist())
523 {
524 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
525 }
526
527 global $USER;
528 $rightParam = new RightParam($param);
529 $rightParam->setUser($USER);
530
531 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
532 {
533 throw new AccessException('Available only on extended plans');
534 }
535
536 $right = new Right($rightParam, new IblockRight($rightParam));
537 $right->checkPermission();
538 if ($right->hasErrors())
539 {
540 self::throwError($right->getErrors());
541 }
542
543 $field = new Field($param);
544 return $field->get();
545 }
546
547 public static function updateField(array $params, $n, \CRestServer $server)
548 {
549 $param = new Param($params);
550
551 $iblock = new Iblock($param);
552 if (!$iblock->isExist())
553 {
554 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
555 }
556
557 global $USER;
558 $rightParam = new RightParam($param);
559 $rightParam->setUser($USER);
560
561 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
562 {
563 throw new AccessException('Available only on extended plans');
564 }
565
566 $right = new Right($rightParam, new IblockRight($rightParam));
567 $right->checkPermission(IblockRight::EDIT);
568 if ($right->hasErrors())
569 {
570 self::throwError($right->getErrors());
571 }
572
573 $field = new Field($param);
574 if ($field->update())
575 {
576 return true;
577 }
578 else
579 {
580 self::throwError($field->getErrors());
581 }
582 }
583
584 public static function deleteField(array $params, $n, \CRestServer $server)
585 {
586 $param = new Param($params);
587
588 $iblock = new Iblock($param);
589 if (!$iblock->isExist())
590 {
591 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
592 }
593
594 global $USER;
595 $rightParam = new RightParam($param);
596 $rightParam->setUser($USER);
597
598 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
599 {
600 throw new AccessException('Available only on extended plans');
601 }
602
603 $right = new Right($rightParam, new IblockRight($rightParam));
604 $right->checkPermission(IblockRight::EDIT);
605 if ($right->hasErrors())
606 {
607 self::throwError($right->getErrors());
608 }
609
610 $field = new Field($param);
611 $field->delete();
612
613 return true;
614 }
615
616 public static function getFieldTypes(array $params, $n, \CRestServer $server)
617 {
618 $param = new Param($params);
619
620 $iblock = new Iblock($param);
621 if (!$iblock->isExist())
622 {
623 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
624 }
625
626 global $USER;
627 $rightParam = new RightParam($param);
628 $rightParam->setUser($USER);
629
630 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
631 {
632 throw new AccessException('Available only on extended plans');
633 }
634
635 $right = new Right($rightParam, new IblockRight($rightParam));
636 $right->checkPermission(IblockRight::EDIT);
637 if ($right->hasErrors())
638 {
639 self::throwError($right->getErrors());
640 }
641
642 $field = new Field($param);
643 return $field->getAvailableTypes();
644 }
645
646 public static function addElement(array $params, $n, \CRestServer $server)
647 {
648 $param = new Param($params);
649 $params = $param->getParams();
650
651 $iblock = new Iblock($param);
652 if (!$iblock->isExist())
653 {
654 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
655 }
656
657 global $USER;
658 $rightParam = new RightParam($param);
659 $rightParam->setUser($USER);
660 $rightParam->setEntityId($params["IBLOCK_SECTION_ID"]);
661
662 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
663 {
664 throw new AccessException('Available only on extended plans');
665 }
666
667 $elementRight = new ElementRight($rightParam);
668 $right = new Right($rightParam, $elementRight);
669 $right->checkPermission(ElementRight::ADD);
670 if ($right->hasErrors())
671 {
672 self::throwError($right->getErrors());
673 }
674
675 $element = new Element($param);
676 if ($element->isExist())
677 {
678 self::throwError($element->getErrors(), "Element already exists", Element::ERROR_ELEMENT_ALREADY_EXISTS);
679 }
680
681 $conn = Application::getConnection();
682 $conn->startTransaction();
683 $errors = [];
684 try
685 {
686 $elementId = $element->add();
687 if (!$elementId)
688 {
689 $errors = $element->getErrors();
690 }
691 }
692 catch (SqlQueryException)
693 {
694 $elementId = false;
695 $errors[] = new Error('Internal error adding list element. Try adding again.');
696 }
697 if ($elementId)
698 {
699 $conn->commitTransaction();
700
701 return $elementId;
702 }
703 else
704 {
705 $conn->rollbackTransaction();
706
707 self::throwError($errors);
708 }
709 }
710
711 public static function getElement(array $params, $n, \CRestServer $server)
712 {
713 $param = new Param($params);
714 $params = $param->getParams();
715
716 $iblock = new Iblock($param);
717 if (!$iblock->isExist())
718 {
719 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
720 }
721
722 global $USER;
723 $rightParam = new RightParam($param);
724 $rightParam->setUser($USER);
725 $rightParam->setEntityId(Utils::getElementId($param->getParams()));
726
727 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
728 {
729 throw new AccessException('Available only on extended plans');
730 }
731
732 $elementRight = new ElementRight($rightParam);
733 $param->setParam(["CAN_FULL_EDIT" => ($elementRight->canFullEdit() ? "Y" : "N")]);
734
735 $right = new Right($rightParam, $elementRight);
736 $right->checkPermission(ElementRight::READ);
737 if ($right->hasErrors())
738 {
739 self::throwError($right->getErrors());
740 }
741
742 $element = new Element($param);
743 if (is_array($params["FILTER"] ?? null))
744 {
745 list($availableFields, $listCustomFields) = $element->getAvailableFields();
746 $element->resultSanitizeFilter = self::getSanitizeFilter(
747 $params["FILTER"], $availableFields, $listCustomFields);
748 }
749 list ($elements, $queryObject) = $element->get(self::getNavData($n));
750 if ($elements)
751 {
752 return self::setNavData(array_values($elements), $queryObject);
753 }
754 else
755 {
756 return [];
757 }
758 }
759
760 public static function updateElement(array $params, $n, \CRestServer $server)
761 {
762 $param = new Param($params);
763
764 $iblock = new Iblock($param);
765 if (!$iblock->isExist())
766 {
767 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
768 }
769
770 global $USER;
771 $rightParam = new RightParam($param);
772 $rightParam->setUser($USER);
773 $rightParam->setEntityId(Utils::getElementId($param->getParams()));
774
775 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
776 {
777 throw new AccessException('Available only on extended plans');
778 }
779
780 $elementRight = new ElementRight($rightParam);
781 $right = new Right($rightParam, $elementRight);
782 $right->checkPermission(ElementRight::EDIT);
783 if ($right->hasErrors())
784 {
785 self::throwError($right->getErrors());
786 }
787
788 $element = new Element($param);
789 if (!$element->isExist())
790 {
791 self::throwError($element->getErrors(), "Element not found", Element::ERROR_ELEMENT_NOT_FOUND);
792 }
793
794 $conn = Application::getConnection();
795 $conn->startTransaction();
796 $errors = [];
797 try
798 {
799 $success = $element->update();
800 if (!$success)
801 {
802 $errors = $element->getErrors();
803 }
804 }
805 catch (SqlQueryException)
806 {
807 $success = false;
808 $errors[] = new Error('Internal error updating list element. Try updating again.');
809 }
810 if ($success)
811 {
812 $conn->commitTransaction();
813
814 return true;
815 }
816 else
817 {
818 $conn->rollbackTransaction();
819
820 self::throwError($errors);
821 }
822 }
823
824 public static function deleteElement(array $params, $n, \CRestServer $server)
825 {
826 $param = new Param($params);
827
828 $iblock = new Iblock($param);
829 if (!$iblock->isExist())
830 {
831 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
832 }
833
834 global $USER;
835 $rightParam = new RightParam($param);
836 $rightParam->setUser($USER);
837 $rightParam->setEntityId(Utils::getElementId($param->getParams()));
838
839 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
840 {
841 throw new AccessException('Available only on extended plans');
842 }
843
844 $elementRight = new ElementRight($rightParam);
845 $right = new Right($rightParam, $elementRight);
846 $right->checkPermission(ElementRight::EDIT);
847 if ($right->hasErrors())
848 {
849 self::throwError($right->getErrors());
850 }
851
852 $element = new Element($param);
853 if (!$element->isExist())
854 {
855 self::throwError($element->getErrors(), "Element not found", Element::ERROR_ELEMENT_NOT_FOUND);
856 }
857
858 $elementRight->canDelete();
859 if ($elementRight->hasErrors())
860 {
861 self::throwError($elementRight->getErrors());
862 }
863
864 $conn = Application::getConnection();
865 $conn->startTransaction();
866 $errors = [];
867 try
868 {
869 $success = $element->delete();
870 if (!$success)
871 {
872 $errors = $element->getErrors();
873 }
874 }
875 catch (SqlQueryException)
876 {
877 $success = false;
878 $errors[] = new Error('Internal error deleting list element. Try deleting again.');
879 }
880 if ($success)
881 {
882 $conn->commitTransaction();
883
884 return true;
885 }
886 else
887 {
888 $conn->rollbackTransaction();
889
890 self::throwError($errors);
891 }
892 }
893
894 public static function getFileUrl(array $params, $n, \CRestServer $server)
895 {
896 $param = new Param($params);
897
898 $iblock = new Iblock($param);
899 if (!$iblock->isExist())
900 {
901 self::throwError($iblock->getErrors(), "Iblock not found", Iblock::ERROR_IBLOCK_NOT_FOUND);
902 }
903
904 global $USER;
905 $rightParam = new RightParam($param);
906 $rightParam->setUser($USER);
907 $rightParam->setEntityId(Utils::getElementId($param->getParams()));
908
909 if (!\CLists::isListFeatureEnabled($rightParam->getIblockTypeId()))
910 {
911 throw new AccessException('Available only on extended plans');
912 }
913
914 $elementRight = new ElementRight($rightParam);
915 $right = new Right($rightParam, $elementRight);
916 $right->checkPermission(ElementRight::READ);
917 if ($right->hasErrors())
918 {
919 self::throwError($right->getErrors());
920 }
921
922 $element = new Element($param);
923 if (!$element->isExist())
924 {
925 self::throwError($element->getErrors(), "Element not found", Element::ERROR_ELEMENT_NOT_FOUND);
926 }
927
928 return $element->getFileUrl();
929 }
930
931 private static function throwError(array $errors, $message = "", $code = "")
932 {
933 $error = end($errors);
934
935 if ($error instanceof Error)
936 {
937 $message = $error->getMessage();
938 if (is_array($message) && array_key_exists("message", $message))
939 {
940 $message = $message["message"];
941 }
942 else
943 {
944 $message = $message ?: "Unknown error";
945 }
946 throw new RestException($message, $error->getCode());
947 }
948 elseif ($error)
949 {
950 throw new RestException($error, RestException::ERROR_CORE);
951 }
953 {
954 throw new RestException($message, $code);
955 }
956
957 throw new RestException("Unknown error", RestException::ERROR_NOT_FOUND);
958 }
959
960 private static function getSanitizeFilter($filter, $availableFields, $listCustomFields)
961 {
962 return parent::sanitizeFilter(
963 $filter,
964 $availableFields,
965 function($field, $value) use ($listCustomFields)
966 {
967 if (array_key_exists($field, $listCustomFields))
968 {
969 $callback = $listCustomFields[$field];
970 if ($callback instanceof \Closure)
971 {
972 return $callback($value);
973 }
974 else
975 {
976 return call_user_func_array($listCustomFields[$field], [[], ["VALUE" => $value]]);
977 }
978 }
979 return $value;
980 },
981 ["", "!%", ">=", "><", "!><", ">", "<=", "<", "%", "=", "*", "!"]
982 );
983 }
984
989 const ERROR_REQUIRED_PARAMETERS_MISSING = "ERROR_REQUIRED_PARAMETERS_MISSING";
990 const ERROR_IBLOCK_ALREADY_EXISTS = "ERROR_IBLOCK_ALREADY_EXISTS";
991 const ERROR_SAVE_IBLOCK = "ERROR_SAVE_IBLOCK";
992 const ERROR_IBLOCK_NOT_FOUND = "ERROR_IBLOCK_NOT_FOUND";
993 const ERROR_SAVE_FIELD = "ERROR_SAVE_FIELD";
994 const ERROR_PROPERTY_ALREADY_EXISTS = "ERROR_PROPERTY_ALREADY_EXISTS";
995 const ERROR_SAVE_ELEMENT = "ERROR_SAVE_ELEMENT";
996 const ERROR_DELETE_ELEMENT = "ERROR_DELETE_ELEMENT";
997 const ERROR_BIZPROC = "ERROR_BIZPROC";
998}
const ERROR_ELEMENT_NOT_FOUND
Определения element.php:20
const ERROR_ELEMENT_ALREADY_EXISTS
Определения element.php:19
const ERROR_IBLOCK_NOT_FOUND
Определения iblock.php:17
const ERROR_IBLOCK_ALREADY_EXISTS
Определения iblock.php:18
const ERROR_SECTION_NOT_FOUND
Определения section.php:17
static addLists(array $params, $n, \CRestServer $server)
Определения restservice.php:75
const ERROR_PROPERTY_ALREADY_EXISTS
Определения restservice.php:994
static onRestServiceBuildDescription()
Определения restservice.php:29
static getFieldTypes(array $params, $n, \CRestServer $server)
Определения restservice.php:616
static getIblockTypeId(array $params, $n, \CRestServer $server)
Определения restservice.php:60
const ENTITY_LISTS_CODE_PREFIX
Определения restservice.php:988
const ERROR_SAVE_IBLOCK
Определения restservice.php:991
const ERROR_DELETE_ELEMENT
Определения restservice.php:996
const ERROR_IBLOCK_NOT_FOUND
Определения restservice.php:992
const ERROR_IBLOCK_ALREADY_EXISTS
Определения restservice.php:990
static addField(array $params, $n, \CRestServer $server)
Определения restservice.php:479
static getFields(array $params, $n, \CRestServer $server)
Определения restservice.php:517
const ERROR_SAVE_ELEMENT
Определения restservice.php:995
static addElement(array $params, $n, \CRestServer $server)
Определения restservice.php:646
static getElement(array $params, $n, \CRestServer $server)
Определения restservice.php:711
static getSection(array $params, $n, \CRestServer $server)
Определения restservice.php:329
static updateElement(array $params, $n, \CRestServer $server)
Определения restservice.php:760
const ERROR_SAVE_FIELD
Определения restservice.php:993
static deleteSection(array $params, $n, \CRestServer $server)
Определения restservice.php:421
static deleteElement(array $params, $n, \CRestServer $server)
Определения restservice.php:824
static addSection(array $params, $n, \CRestServer $server)
Определения restservice.php:275
static updateSection(array $params, $n, \CRestServer $server)
Определения restservice.php:363
static deleteLists(array $params, $n, \CRestServer $server)
Определения restservice.php:219
static getFileUrl(array $params, $n, \CRestServer $server)
Определения restservice.php:894
static deleteField(array $params, $n, \CRestServer $server)
Определения restservice.php:584
static updateField(array $params, $n, \CRestServer $server)
Определения restservice.php:547
const ERROR_BIZPROC
Определения restservice.php:997
static getLists(array $params, $n, \CRestServer $server)
Определения restservice.php:131
const ERROR_REQUIRED_PARAMETERS_MISSING
Определения restservice.php:989
static updateLists(array $params, $n, \CRestServer $server)
Определения restservice.php:163
Определения error.php:15
Определения loader.php:13
static includeModule($moduleName)
Определения loader.php:67
Определения rest.php:24
Определения rest.php:896
static setNavData($result, $dbRes)
Определения rest.php:927
$right
Определения options.php:8
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$iblockTypeId
Определения group_lists.php:25
$iblockId
Определения iblock_catalog_edit.php:30
$errors
Определения iblock_catalog_edit.php:74
if(! $catalogEdit->isSuccess()) $iblock
Определения iblock_catalog_edit.php:38
$filter
Определения iblock_catalog_list.php:54
global $USER
Определения csv_new_run.php:40
if(!is_null($config))($config as $configItem)(! $configItem->isVisible()) $code
Определения options.php:195
$success
Определения mail_entry.php:69
$value
Определения Param.php:39
Определения restservice.php:2
$message
Определения payment.php:8
if( $daysToExpire >=0 &&$daysToExpire< 60 elseif)( $daysToExpire< 0)
Определения prolog_main_admin.php:393
if($inWords) echo htmlspecialcharsbx(Number2Word_Rus(roundEx($totalVatSum $params['CURRENCY']
Определения template.php:799
$error
Определения subscription_card_product.php:20
$n
Определения update_log.php:107