Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
workflowtemplate.php
1<?php
2
4
7
24class WorkflowTemplateTable extends Main\Entity\DataManager
25{
29 public static function getTableName()
30 {
31 return 'b_bp_workflow_template';
32 }
33
34 public static function getObjectClass()
35 {
36 return Tpl::class;
37 }
38
42 public static function getMap()
43 {
44 $serializeCallback = [__CLASS__, 'toSerializedForm'];
45 $unserializeCallback = [__CLASS__, 'getFromSerializedForm'];
46
47 return [
48 'ID' => [
49 'data_type' => 'integer',
50 'primary' => true,
51 ],
52 'MODULE_ID' => [
53 'data_type' => 'string',
54 ],
55 'ENTITY' => [
56 'data_type' => 'string',
57 ],
58 'DOCUMENT_TYPE' => [
59 'data_type' => 'string',
60 ],
61 'DOCUMENT_STATUS' => [
62 'data_type' => 'string',
63 ],
64 'AUTO_EXECUTE' => [
65 'data_type' => 'integer',
66 ],
67 'NAME' => [
68 'data_type' => 'string',
69 ],
70 'DESCRIPTION' => [
71 'data_type' => 'string',
72 ],
73 'TEMPLATE' => (
74 (new Main\ORM\Fields\ArrayField('TEMPLATE'))
75 ->configureSerializeCallback($serializeCallback)
76 ->configureUnserializeCallback($unserializeCallback)
77 ),
78 'PARAMETERS' => (
79 (new Main\ORM\Fields\ArrayField('PARAMETERS'))
80 ->configureSerializeCallback($serializeCallback)
81 ->configureUnserializeCallback($unserializeCallback)
82 ),
83 'VARIABLES' => (
84 (new Main\ORM\Fields\ArrayField('VARIABLES'))
85 ->configureSerializeCallback($serializeCallback)
86 ->configureUnserializeCallback($unserializeCallback)
87 ),
88 'CONSTANTS' => (
89 (new Main\ORM\Fields\ArrayField('CONSTANTS'))
90 ->configureSerializeCallback($serializeCallback)
91 ->configureUnserializeCallback($unserializeCallback)
92 ),
93 'MODIFIED' => [
94 'data_type' => 'datetime',
95 ],
96 'IS_MODIFIED' => [
97 'data_type' => 'boolean',
98 'values' => ['N', 'Y'],
99 ],
100 'USER_ID' => [
101 'data_type' => 'integer',
102 ],
103 'SYSTEM_CODE' => [
104 'data_type' => 'string',
105 ],
106 'ACTIVE' => [
107 'data_type' => 'boolean',
108 'values' => ['N', 'Y'],
109 ],
110 'ORIGINATOR_ID' => [
111 'data_type' => 'string',
112 ],
113 'ORIGIN_ID' => [
114 'data_type' => 'string',
115 ],
116 'USER' => [
117 'data_type' => Main\UserTable::class,
118 'reference' => [
119 '=this.USER_ID' => 'ref.ID',
120 ],
121 'join_type' => 'LEFT',
122 ],
123 'IS_SYSTEM' => [
124 'data_type' => 'boolean',
125 'values' => ['N', 'Y'],
126 ],
127 'SORT' => [
128 'data_type' => 'integer',
129 'default_value' => 10,
130 ],
131 ];
132 }
133
134 public static function getFromSerializedForm($value)
135 {
136 if (!empty($value))
137 {
138 if (self::shouldUseCompression())
139 {
140 $value1 = @gzuncompress($value);
141 if ($value1 !== false)
142 {
143 $value = $value1;
144 }
145 }
146
147 $value = unserialize($value, ['allowed_classes' => false]);
148 if (!is_array($value))
149 {
150 $value = [];
151 }
152 }
153 else
154 {
155 $value = [];
156 }
157
158 return $value;
159 }
160
161 public static function toSerializedForm($value)
162 {
163 if (empty($value))
164 {
165 return null;
166 }
167
168 $buffer = serialize($value);
169 if (self::shouldUseCompression())
170 {
171 $buffer = gzcompress($buffer, 9);
172 }
173
174 return $buffer;
175 }
176
177 public static function getIdsByDocument(array $documentType): array
178 {
179 $documentType = \CBPHelper::ParseDocumentId($documentType);
180 $rows = static::getList([
181 'select' => ['ID'],
182 'filter' => [
183 '=MODULE_ID' => $documentType[0],
184 '=ENTITY' => $documentType[1],
185 '=DOCUMENT_TYPE' => $documentType[2],
186 ],
187 ])->fetchAll();
188
189 return array_column($rows, 'ID');
190 }
191
193 public static function update($primary, array $data)
194 {
195 throw new Main\NotImplementedException("Use CBPTemplateLoader class.");
196 }
197
198 private static function shouldUseCompression(): bool
199 {
200 static $useCompression;
201 if ($useCompression === null)
202 {
203 $useCompression = \CBPWorkflowTemplateLoader::useGZipCompression();
204 }
205
206 return $useCompression;
207 }
208}