1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
MobileResultHandler.php
См. документацию.
1<?php
2
3namespace Bitrix\Bizproc\Result;
4
5use Bitrix\Disk\AttachedObject;
6use Bitrix\Main\Loader;
7use Bitrix\Main\Localization\Loc;
8use Bitrix\Main\Web\MimeType;
9use Bitrix\Bizproc\Workflow\Entity\WorkflowStateTable;
10
12{
13 protected string $workflowId;
14
15 public function __construct(string $workflowId)
16 {
17 $this->workflowId = $workflowId;
18 }
19
20 public function handle(RenderedResult $renderedResult = null): array
21 {
22 static $cache = [];
23
24 $files = [];
25 $noResult = [
26 'text' => Loc::getMessage('BIZPROC_RESULT_BP_WORKFLOW_NO_RESULT'),
28 'files' => $files
29 ];
30 $text = $this->extractFromSource($renderedResult->text ?? '', $files);
31
32 if (is_null($renderedResult))
33 {
34 if (isset($cache[$this->workflowId]))
35 {
36 return $cache[$this->workflowId];
37 }
38
39 $state = WorkflowStateTable::getByPrimary(
40 $this->workflowId,
41 ['select' => ['STARTED_BY', 'MODULE_ID', 'ENTITY', 'DOCUMENT_ID']]
42 )->fetchObject();
43 if (!$state)
44 {
45 $cache[$this->workflowId] = $noResult;
46
47 return $cache[$this->workflowId];
48 }
49
50 $startedBy = $state->getStartedBy();
51 if (empty($startedBy))
52 {
53 $startedBy = \CCrmBizProcHelper::getDocumentResponsibleId($state->getComplexDocumentId());
54 }
55
57
58 if ($userName)
59 {
60 $userLink = '[URL=/company/personal/user/' . $startedBy . '/]' . $userName . '[/URL]';
61 $text = Loc::getMessage('BIZPROC_RESULT_BP_WORKFLOW_RESULT_USER', ['#USER#' => $userLink]) ?? '';
62
63 $cache[$this->workflowId] = [
64 'text' => $text,
66 'files' => $files
67 ];
68
69 return $cache[$this->workflowId];
70 }
71
72 $cache[$this->workflowId] = $noResult;
73
74 return $cache[$this->workflowId];
75 }
76
77 switch ($renderedResult->status)
78 {
80 return [
81 'text' => $text,
82 'status' => $renderedResult->status,
83 'files' => $files,
84 ];
85
87 return [
88 'text' => Loc::getMessage(
89 'BIZPROC_RESULT_BP_WORKFLOW_RESULT_USER', ['#USER#' => $renderedResult->text]
90 ) ?? '',
91 'status' => $renderedResult->status,
92 'files' => $files,
93 ];
94
96 return [
97 'text' => Loc::getMessage('BIZPROC_RESULT_BP_RESULT_NO_RIGHTS') ?? '',
98 'status' => $renderedResult->status,
99 'files' => $files,
100 ];
102 return $noResult;
103 }
104 }
105
106 private function extractFromSource(string $sourceText, array &$files): string
107 {
108 $sourceText = preg_replace_callback(
109 '|\[url\s*=\s*/bitrix/tools/bizproc_show_file\.php\?([^]]+)]|',
110 $this->getFileLinksReplacer($files),
111 $sourceText,
112 );
113
114 if (Loader::includeModule('disk'))
115 {
116 $sourceText = preg_replace_callback(
117 '|\[url\s*=\s*/bitrix/tools/disk/uf.php\?([^]]+)]|',
118 $this->getDiskFileLinksReplacer($files),
119 $sourceText
120 );
121 }
122
123 return $sourceText;
124 }
125
126 private function getFileLinksReplacer(array& $files): callable
127 {
128 return function ($matches) use (&$files)
129 {
130 parse_str(htmlspecialcharsback($matches[1]), $query);
131 $fileId = $query['i'] ?? null;
132 if (isset($fileId))
133 {
134 $fileId = (int)$fileId;
135 $file = \CFile::GetFileArray($fileId);
136 if (!$file)
137 {
138 return $matches[0];
139 }
140 $uri = 'fid://' . $fileId;
141 $fileName = $file['ORIGINAL_NAME'] ?: $file['FILE_NAME'];
142 $files[$uri] = [
143 'id' => (int)$file['ID'],
144 'name' => $fileName,
145 'url' => $file['SRC'],
146 'type' => MimeType::getByFilename($fileName),
147 ];
148
149 return '[url=' . $uri . ']';
150 }
151
152 return $matches[0];
153 };
154 }
155
156 private function getDiskFileLinksReplacer(array& $files): callable
157 {
158 return function ($matches) use (&$files)
159 {
160 parse_str(htmlspecialcharsback($matches[1]), $query);
161 $attachedModel = AttachedObject::loadById($query['attachedId'] ?? null);
162 $diskFile = $attachedModel?->getFile();
163 if (isset($diskFile))
164 {
165 $file = \CFile::GetFileArray($diskFile->getFileId());
166 if (!$file)
167 {
168 return $matches[0];
169 }
170
171 $uri = 'fid://' . $diskFile->getFileId();
172 $fileName = $file['ORIGINAL_NAME'] ?: $file['FILE_NAME'];
173 $files[$uri] = [
174 'id' => (int)$file['ID'],
175 'name' => $fileName,
176 'url' => $file['SRC'],
177 'type' => MimeType::getByFilename($fileName),
178 ];
179
180 return '[url=' . $uri . ']';
181 }
182
183 return $matches[0];
184 };
185 }
186}
handle(RenderedResult $renderedResult=null)
Определения MobileResultHandler.php:20
__construct(string $workflowId)
Определения MobileResultHandler.php:15
static getUserFullNameById(int $userId)
Определения viewhelper.php:161
</td ></tr ></table ></td ></tr >< tr >< td class="bx-popup-label bx-width30"><?=GetMessage("PAGE_NEW_TAGS")?> array( $site)
Определения file_new.php:804
$query
Определения get_search.php:11
if(file_exists($_SERVER['DOCUMENT_ROOT'] . "/urlrewrite.php")) $uri
Определения urlrewrite.php:61
htmlspecialcharsback($str)
Определения tools.php:2693
$files
Определения mysql_to_pgsql.php:30
$fileName
Определения quickway.php:305
$text
Определения template_pdf.php:79
else $userName
Определения order_form.php:75
$matches
Определения index.php:22