Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
documentuserfield.php
1<?php
2
4
10
11final class DocumentUserField extends Base
12{
13 public function getFields()
14 {
15 return [
16 'DOCUMENT_ID' => [
17 'TYPE' => DataType::TYPE_INT,
18 'CANONICAL_NAME' => 'ID',
19 ],
20 'DOCUMENT_TYPE' => [
21 'TYPE' => DataType::TYPE_CHAR,
22 'ATTRIBUTES' => [
23 Attributes::REQUIRED,
24 ],
25 'CANONICAL_NAME' => 'DOC_TYPE',
26 ],
27 ];
28 }
29
30 public function internalizeFieldsUpdate($fields, $fieldsInfo = []): array
31 {
32 $documentType = $fields['DOCUMENT_TYPE'];
33 $fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $this->getFieldMapForType($documentType));
34
35 return parent::internalizeFieldsUpdate($fields, $fieldsInfo);
36 }
37
38 public function internalizeFieldsList($arguments, $fieldsInfo = []): array
39 {
40 $documentType = $arguments['filter']['DOCUMENT_TYPE'];
41 $fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $this->getFieldMapForType($documentType));
42
43 return parent::internalizeFieldsList($arguments, $fieldsInfo);
44 }
45
46 protected function internalizeExtendedTypeValue($value, $info): Result
47 {
48 $isDynamic = in_array(Attributes::DYNAMIC, $info['ATTRIBUTES'], true);
49 $isMultiple = in_array(Attributes::MULTIPLE, $info['ATTRIBUTES'], true);
50 if (empty($value) && $isDynamic && $isMultiple)
51 {
52 $value = [''];
53 }
54
55 if ($info['USER_FIELD_TYPE'] === 'file')
56 {
57 if ($isMultiple)
58 {
59 $internalizedValue = [];
60 foreach ($value as $item)
61 {
62 $internalizedValue[] = $this->internalizeFileValue($item);
63 }
64 $value = $internalizedValue;
65 }
66 else
67 {
68 $value = $this->internalizeFileValue($value);
69 }
70 }
71
72 return parent::internalizeExtendedTypeValue($value, $info);
73 }
74
75 public function externalizeFieldsGet($fields, $fieldsInfo = []): array
76 {
77 $documentType = $fields['DOC_TYPE'];
78 $fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $this->getFieldMapForType($documentType));
79
80 return parent::externalizeFieldsGet($fields, $fieldsInfo);
81 }
82
83 public function externalizeListFields($list, $fieldsInfo = []): array
84 {
85 $documentType = $list[0]['DOC_TYPE'];
86 $fieldsInfo = array_merge($fieldsInfo, $this->getFields(), $this->getFieldMapForType($documentType));
87
88 return parent::externalizeListFields($list, $fieldsInfo);
89 }
90
91 private function getFieldMapForType($documentType)
92 {
93 global $USER_FIELD_MANAGER;
94
95 $ufEntityId = StoreDocumentTableManager::getUfEntityIds()[$documentType] ?? '';
96 if (!$ufEntityId)
97 {
98 return [];
99 }
100
101 $userFieldsDescriptions = $USER_FIELD_MANAGER->GetUserFields($ufEntityId, 0);
102
103 $result = [];
104 foreach ($userFieldsDescriptions as $userField)
105 {
106 $attributes = [Attributes::DYNAMIC];
107 if ($userField['MULTIPLE'] === 'Y')
108 {
109 $attributes[] = Attributes::MULTIPLE;
110 }
111 $result['FIELD_' . $userField['ID']] = [
112 'ATTRIBUTES' => $attributes,
113 'CANONICAL_NAME' => $userField['FIELD_NAME'],
114 'USER_FIELD_TYPE' => $userField['USER_TYPE_ID']
115 ];
116 }
117
118 return $result;
119 }
120}
internalizeFieldsList($arguments, $fieldsInfo=[])