1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
file.php
См. документацию.
1<?php
2
3namespace Bitrix\Rest\Controller;
4
5use Bitrix\Main\Engine;
6use Bitrix\Main\Engine\ActionFilter;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\Engine\Response\BFile;
9use Bitrix\Main\Engine\Response\AjaxJson;
10use Bitrix\Rest\RestException;
11use Bitrix\Main\ErrorCollection;
12use Bitrix\Main\Error;
13
14
15Loc::loadMessages(__FILE__);
16
18{
19 private $allowEntityList = [
20 'USER'
21 ];
22
23 private $entityScope = [
24 'USER' => 'user'
25 ];
26
27 public function getAction($entity, $id, $field, $value, \CRestServer $restServer = null)
28 {
30 if (in_array($entity, $this->allowEntityList, true))
31 {
32 if ($restServer && $this->entityScope[$entity])
33 {
34 $authScope = $restServer->getAuthScope();
35 if (!in_array($this->entityScope[$entity], $authScope, true))
36 {
38 [
39 new Error('Invalid request credentials', 'INVALID_CREDENTIALS')
40 ]
41 );
42 }
43 }
44
45 if ($errorCollection->isEmpty())
46 {
48 $userFieldsData = $USER_FIELD_MANAGER->getUserFields($entity, (int) $id, LANGUAGE_ID);
49
50 if (
51 $userFieldsData[$field]['USER_TYPE_ID'] === 'file'
52 && (int) $value > 0
53 && !empty($userFieldsData[$field]['VALUE']))
54 {
55 if (
56 (int) $value === (int) $userFieldsData[$field]['VALUE']
57 || (
58 is_array($userFieldsData[$field]['VALUE'])
59 && in_array((int) $value, $userFieldsData[$field]['VALUE'], true)
60 )
61
62 )
63 {
64 return BFile::createByFileId((int) $value);
65 }
66
68 [
69 new Error('File not found.', 'FILE_NOT_FOUND')
70 ]
71 );
72 }
73 else
74 {
76 [
77 new Error('Entity not allow.', 'ENTITY_NOT_ALLOW')
78 ]
79 );
80 }
81 }
82 }
83 else
84 {
86 [
87 new Error('Access denied.', 'ACCESS_DENIED')
88 ]
89 );
90 }
91
92 if (!$errorCollection->isEmpty() && Engine\Controller::getScope() === Engine\Controller::SCOPE_REST)
93 {
95 $error = $errorCollection->current();
96 if ($error)
97 {
98 return new RestException(
99 $error->getMessage(),
100 $error->getCode()
101 );
102
103 }
104 }
105
106 return AjaxJson::createError($errorCollection);
107 }
108
109 public function getDefaultPreFilters()
110 {
111 return [
113 ];
114 }
115}
Определения error.php:15
getDefaultPreFilters()
Определения file.php:109
global $USER_FIELD_MANAGER
Определения attempt.php:6
$entity
Определения action.php:3
Определения Image.php:9
$error
Определения subscription_card_product.php:20