21 $this->useCompression =
true;
26 $this->useCompression =
false;
31 $documentService = CBPRuntime::GetRuntime(
true)->getDocumentService();
33 $documentFieldsAliasesMap = CBPDocument::getDocumentFieldsAliasesMap($documentFieldsTmp);
36 $len = mb_strlen(
"_PRINTABLE");
37 foreach ($documentFieldsTmp as $k => $v)
39 if (mb_strtoupper(mb_substr($k, -$len)) !=
"_PRINTABLE")
41 $documentFields[$k] = $v;
45 $tplData = $tpl->collectValues();
47 if ($documentFieldsAliasesMap)
49 self::replaceTemplateDocumentFieldsAliases($tplData[
'TEMPLATE'], $documentFieldsAliasesMap);
50 self::replaceVariablesDocumentFieldsAliases($tplData[
'PARAMETERS'], $documentFieldsAliasesMap);
51 self::replaceVariablesDocumentFieldsAliases($tplData[
'VARIABLES'], $documentFieldsAliasesMap);
52 self::replaceVariablesDocumentFieldsAliases($tplData[
'CONSTANTS'], $documentFieldsAliasesMap);
57 "TEMPLATE" => self::ConvertArrayCharset($tplData[
"TEMPLATE"], static::DIRECTION_EXPORT),
58 "PARAMETERS" => self::ConvertArrayCharset($tplData[
"PARAMETERS"], static::DIRECTION_EXPORT),
59 "VARIABLES" => self::ConvertArrayCharset($tplData[
"VARIABLES"], static::DIRECTION_EXPORT),
60 "CONSTANTS" => self::ConvertArrayCharset($tplData[
"CONSTANTS"], static::DIRECTION_EXPORT),
61 "DOCUMENT_FIELDS" => self::ConvertArrayCharset($documentFields, static::DIRECTION_EXPORT),
68 $datum = serialize($datum);
70 if ($this->useCompression)
75 return (
new Result\Pack())->setPackage($datum);
78 public function unpack($data)
82 $datumTmp = \CheckSerializedData($data) ? @unserialize($data, [
'allowed_classes' =>
false]) : null;
84 if (!is_array($datumTmp) || is_array($datumTmp) && !array_key_exists(
"TEMPLATE", $datumTmp))
87 $datumTmp = \CheckSerializedData($datumTmp) ? @unserialize($datumTmp, [
'allowed_classes' =>
false]) : null;
90 if (!is_array($datumTmp) || is_array($datumTmp) && !array_key_exists(
"TEMPLATE", $datumTmp))
96 if (array_key_exists(
"VERSION", $datumTmp) && $datumTmp[
"VERSION"] == 2)
98 $datumTmp[
"TEMPLATE"] = self::ConvertArrayCharset($datumTmp[
"TEMPLATE"], static::DIRECTION_IMPORT);
99 $datumTmp[
"PARAMETERS"] = self::ConvertArrayCharset($datumTmp[
"PARAMETERS"], static::DIRECTION_IMPORT);
100 $datumTmp[
"VARIABLES"] = self::ConvertArrayCharset($datumTmp[
"VARIABLES"], static::DIRECTION_IMPORT);
101 $datumTmp[
"CONSTANTS"] = isset($datumTmp[
"CONSTANTS"])?
102 self::ConvertArrayCharset($datumTmp[
"CONSTANTS"], static::DIRECTION_IMPORT)
104 $datumTmp[
"DOCUMENT_FIELDS"] = self::ConvertArrayCharset($datumTmp[
"DOCUMENT_FIELDS"], static::DIRECTION_IMPORT);
108 $tpl = WorkflowTemplateTable::createObject();
109 $tpl->set(
'TEMPLATE', $datumTmp[
'TEMPLATE']);
110 $tpl->set(
'PARAMETERS', $datumTmp[
'PARAMETERS']);
111 $tpl->set(
'VARIABLES', $datumTmp[
'VARIABLES']);
112 $tpl->set(
'CONSTANTS', $datumTmp[
'CONSTANTS']);
113 $result->setTpl($tpl);
115 if (is_array($datumTmp[
'DOCUMENT_FIELDS'] ??
null))
117 $result->setDocumentFields($datumTmp[
'DOCUMENT_FIELDS']);
123 private static function replaceTemplateDocumentFieldsAliases(&$template, $aliases)
125 foreach ($template as &$activity)
127 self::replaceActivityDocumentFieldsAliases($activity, $aliases);
128 if (is_array($activity[
"Children"]))
130 self::replaceTemplateDocumentFieldsAliases($activity[
'Children'], $aliases);
135 private static function replaceActivityDocumentFieldsAliases(&$activity, $aliases)
137 if (!is_array($activity[
'Properties']))
140 foreach ($activity[
'Properties'] as $key => $value)
142 $activity[
'Properties'][$key] = self::replaceValueDocumentFieldsAliases($value, $aliases);
144 if ($activity[
'Type'] ===
'IfElseBranchActivity' && $key ===
'fieldcondition')
146 $activity[
'Properties'][$key] = self::replaceFieldConditionsDocumentFieldsAliases(
147 $activity[
'Properties'][$key],
154 private static function replaceVariablesDocumentFieldsAliases(&$variables, $aliases)
156 if (!is_array($variables))
159 foreach ($variables as $key => &$variable)
161 $variable[
'Default'] = self::replaceValueDocumentFieldsAliases($variable[
'Default'], $aliases);
164 isset($variable[
'Options'])
165 && is_scalar($variable[
'Options'])
166 && array_key_exists($variable[
'Options'], $aliases)
169 $variable[
'Options'] = $aliases[$variable[
'Options']];
174 private static function replaceValueDocumentFieldsAliases($value, $aliases)
176 if (is_array($value))
178 $replacesValue = array();
179 foreach ($value as $key => $val)
181 if (array_key_exists($key, $aliases))
182 $key = $aliases[$key];
184 $replacesValue[$key] = self::replaceValueDocumentFieldsAliases($val, $aliases);
188 sizeof($replacesValue) == 2
189 && isset($replacesValue[0])
190 && $replacesValue[0] ==
'Document'
191 && isset($replacesValue[1])
192 && array_key_exists($replacesValue[1], $aliases)
195 $replacesValue[1] = $aliases[$replacesValue[1]];
197 $value = $replacesValue;
201 foreach ($aliases as $search => $replace)
203 $value = preg_replace(
'#(\{=\s*Document\s*\:\s*)'.$search.
'#i',
'\\1'.$replace, $value);
210 private static function replaceFieldConditionsDocumentFieldsAliases($conditions, $aliases)
212 foreach ($conditions as $key => $condition)
214 if (array_key_exists($condition[0], $aliases))
215 $conditions[$key][0] = $aliases[$condition[0]];
221 private static function convertValueCharset($s, $direction)
223 if (
"utf-8" == mb_strtolower(LANG_CHARSET))
229 if ($direction == static::DIRECTION_EXPORT)
231 $s = Main\Text\Encoding::convertEncoding($s, LANG_CHARSET,
"UTF-8");
235 $s = Main\Text\Encoding::convertEncoding($s,
"UTF-8", LANG_CHARSET);
241 private static function convertArrayCharset($value, $direction = self::DIRECTION_EXPORT)
243 if (is_array($value))
246 foreach ($value as $k => $v)
248 $k = self::ConvertValueCharset($k, $direction);
249 $v = self::ConvertArrayCharset($v, $direction);
256 $value = self::ConvertValueCharset($value, $direction);
static getMessage($code, $replace=null, $language=null)