1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
userfield.php
См. документацию.
1<?php
2namespace Bitrix\Rest\Api;
3
4use Bitrix\Rest\RestException;
5use Bitrix\Rest\UserFieldProxy;
6
8{
9 private static $nameFullPrefix = 'UF_USR_';
10 private const ENTITY_ID = 'USER';
11 private const ALLOWED_FIELD_PROP_LIST = [
12 'FIELD_NAME',
13 'USER_TYPE_ID',
14 'XML_ID',
15 'MULTIPLE',
16 'SHOW_FILTER',
17 'SORT',
18 'LABEL',
19 'LIST_FILTER_LABEL',
20 'LIST_COLUMN_LABEL',
21 'EDIT_FORM_LABEL',
22 'ERROR_MESSAGE',
23 'HELP_MESSAGE',
24 'SETTINGS',
25 'LIST',
26 ];
27 public const SCOPE_USER_USERFIELD = 'user.userfield';
28 protected $namePrefix = 'USR';
29
30 public static function getTargetEntityId()
31 {
32 return static::ENTITY_ID;
33 }
34
35 public static function addRest($query, $n, \CRestServer $server)
36 {
37 $fields = [];
38
39 $query = array_change_key_case($query, CASE_UPPER);
40 if (isset($query['FIELDS']) && is_array($query['FIELDS']))
41 {
42 $fields = static::checkFields($query['FIELDS']);
43 }
44
45 $instance = new static(static::getTargetEntityId());
46
47 return $instance->add($fields);
48 }
49
50 public static function updateRest($query, $n, \CRestServer $server)
51 {
52 $query = array_change_key_case($query, CASE_UPPER);
53 $id = (int)($query['ID'] ?? 0);
54 if ($id <= 0)
55 {
56 throw new RestException('ID is not defined or invalid.');
57 }
58
59 if (!static::checkAccessField($id))
60 {
61 throw new RestException('Access denied.');
62 }
63
64 $fields = [];
65 if (isset($query['FIELDS']) && is_array($query['FIELDS']))
66 {
67 $fields = static::checkFields($query['FIELDS']);
68 }
69
70 $instance = new static(static::getTargetEntityId());
71
72 return $instance->update($id, $fields);
73 }
74
75 public static function deleteRest($query, $n, \CRestServer $server)
76 {
77 $query = array_change_key_case($query, CASE_UPPER);
78 $id = (int)($query['ID'] ?? 0);
79 if ($id <= 0)
80 {
81 throw new RestException('ID is not defined or invalid.');
82 }
83
84 if (!static::checkAccessField($id))
85 {
86 throw new RestException('Access denied.');
87 }
88
89 $instance = new static(static::getTargetEntityId());
90
91 return $instance->delete($id);
92 }
93
94 public static function getListRest($query, $n, \CRestServer $server)
95 {
96 $order = [];
97 $filter = [];
98 $query = array_change_key_case($query, CASE_UPPER);
99 if (isset($query['ORDER']) && is_array($query['ORDER']))
100 {
101 $order = $query['ORDER'];
102 }
103 if (isset($query['FILTER']) && is_array($query['FILTER']))
104 {
105 $filter = $query['FILTER'];
106 }
107
108 $instance = new static(static::getTargetEntityId());
109 $result = $instance->getList($order, $filter);
110
111 if (is_array($result))
112 {
113 unset($result['total']);
114 foreach ($result as $key => $item)
115 {
116 if (mb_strpos($item['FIELD_NAME'], static::$nameFullPrefix) !== 0)
117 {
118 unset($result[$key]);
119 }
120 }
121 $result = array_values($result);
122 $result['total'] = count($result);
123 }
124
125 return $result;
126 }
127
128 private static function checkFields(array $fields) : array
129 {
130 return array_intersect_key($fields, array_fill_keys(self::ALLOWED_FIELD_PROP_LIST, true));
131 }
132
133 private static function checkAccessField($fieldId)
134 {
135 $result = false;
136 if ($fieldId > 0)
137 {
138 $entity = new \CUserTypeEntity();
139 $res = $entity->getList(
140 [],
141 [
142 'ENTITY_ID' => static::getTargetEntityId(),
143 'ID' => $fieldId
144 ]
145 );
146
147 if ($field = $res->fetch())
148 {
149 if (mb_strpos($field['FIELD_NAME'], static::$nameFullPrefix) === 0)
150 {
151 $result = true;
152 }
153 }
154 }
155
156 return $result;
157 }
158}
const SCOPE_USER_USERFIELD
Определения userfield.php:27
static updateRest($query, $n, \CRestServer $server)
Определения userfield.php:50
static addRest($query, $n, \CRestServer $server)
Определения userfield.php:35
static deleteRest($query, $n, \CRestServer $server)
Определения userfield.php:75
static getTargetEntityId()
Определения userfield.php:30
static getListRest($query, $n, \CRestServer $server)
Определения userfield.php:94
Определения rest.php:24
</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
$query
Определения get_search.php:11
$entity
$filter
Определения iblock_catalog_list.php:54
$order
Определения payment.php:8
$instance
Определения ps_b24_final.php:14
if(empty($signedUserToken)) $key
Определения quickway.php:257
</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
$n
Определения update_log.php:107
$fields
Определения yandex_run.php:501