Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
file.php
1<?php
2
4
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 {
47 global $USER_FIELD_MANAGER;
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
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 [
112 new ActionFilter\Authentication()
113 ];
114 }
115}
static loadMessages($file)
Definition loc.php:64