1C-Bitrix 25.700.0
Загрузка...
Поиск...
Не найдено
viewhelper.php
См. документацию.
1<?php
2
7
9{
10 private static $cachedTasks = array();
11
12 public const DESKTOP_CONTEXT = 'desktop';
13 public const MOBILE_CONTEXT = 'mobile';
14
15 public static function renderUserSearch($ID, $searchInputID, $dataInputID, $componentName, $siteID = '', $nameFormat = '', $delay = 0)
16 {
17 $ID = strval($ID);
18 $searchInputID = strval($searchInputID);
19 $dataInputID = strval($dataInputID);
21
22 $siteID = strval($siteID);
23 if($siteID === '')
24 {
26 }
27
28 $nameFormat = strval($nameFormat);
29 if($nameFormat === '')
30 {
31 $nameFormat = CSite::GetNameFormat(false);
32 }
33
34 $delay = intval($delay);
35 if($delay < 0)
36 {
37 $delay = 0;
38 }
39
40 echo '<input type="text" id="', htmlspecialcharsbx($searchInputID) ,'" style="width:200px;" >',
41 '<input type="hidden" id="', htmlspecialcharsbx($dataInputID),'" name="', htmlspecialcharsbx($dataInputID),'" value="">';
42
43 echo '<script>',
44 'BX.ready(function(){',
45 'BX.CrmUserSearchPopup.deletePopup("', $ID, '");',
46 'BX.CrmUserSearchPopup.create("', $ID, '", { searchInput: BX("', CUtil::JSEscape($searchInputID), '"), dataInput: BX("', CUtil::JSEscape($dataInputID),'"), componentName: "', CUtil::JSEscape($componentName),'", user: {} }, ', $delay,');',
47 '});</script>';
48
49 $GLOBALS['APPLICATION']->IncludeComponent(
50 'bitrix:intranet.user.selector.new',
51 '',
52 array(
53 'MULTIPLE' => 'N',
54 'NAME' => $componentName,
55 'INPUT_NAME' => $searchInputID,
56 'SHOW_EXTRANET_USERS' => 'NONE',
57 'POPUP' => 'Y',
58 'SITE_ID' => $siteID,
59 'NAME_TEMPLATE' => $nameFormat
60 ),
61 null,
62 array('HIDE_ICONS' => 'Y')
63 );
64 }
65
66 public static function getWorkflowTasks($workflowId, $withUsers = false, $extendUserInfo = false)
67 {
68 $withUsers = $withUsers ? 1 : 0;
69 $extendUserInfo = $extendUserInfo ? 1 : 0;
70
71 if (!$workflowId)
72 {
73 return ['COMPLETED' => [], 'RUNNING' => []];
74 }
75
76 if (!isset(self::$cachedTasks[$workflowId][$withUsers][$extendUserInfo]))
77 {
78 $tasks = array('COMPLETED' => array(), 'RUNNING' => array());
79 $ids = array();
80 $taskIterator = CBPTaskService::GetList(
81 ['ID' => 'DESC'],
82 ['WORKFLOW_ID' => $workflowId],
83 false,
84 ['nTopCount' => 50],
85 [
86 'ID',
87 'MODIFIED',
88 'NAME',
89 'DESCRIPTION',
90 'PARAMETERS',
91 'STATUS',
92 'IS_INLINE',
93 'ACTIVITY',
94 'ACTIVITY_NAME',
95 'CREATED_DATE',
96 'DELEGATION_TYPE',
97 'OVERDUE_DATE',
98 ],
99 );
100 while ($task = $taskIterator->getNext())
101 {
102 $key = $task['STATUS'] == CBPTaskStatus::Running ? 'RUNNING' : 'COMPLETED';
103 $tasks[$key][] = $task;
104 $ids[] = $task['ID'];
105 }
106 if ($withUsers && sizeof($ids))
107 {
108 $taskUsers = \CBPTaskService::getTaskUsers($ids);
109 self::joinUsersToTasks($tasks['COMPLETED'], $taskUsers, $extendUserInfo);
110 $tasks['RUNNING_ALL_USERS'] = self::joinUsersToTasks($tasks['RUNNING'], $taskUsers, $extendUserInfo);
111 }
112 $tasks['COMPLETED_CNT'] = sizeof($tasks['COMPLETED']);
113 $tasks['RUNNING_CNT'] = sizeof($tasks['RUNNING']);
114
115 self::$cachedTasks[$workflowId][$withUsers][$extendUserInfo] = $tasks;
116 }
117
118 return self::$cachedTasks[$workflowId][$withUsers][$extendUserInfo];
119 }
120
121 protected static function joinUsersToTasks(&$tasks, &$taskUsers, $extendUserInfo = false)
122 {
123 $allUsers = array();
124 foreach ($tasks as &$t)
125 {
126 $t['USERS'] = array();
127 $t['USERS_CNT'] = 0;
128 if (isset($taskUsers[$t['ID']]))
129 {
130 foreach ($taskUsers[$t['ID']] as $u)
131 {
132 if ($extendUserInfo)
133 {
134 if (empty($u['FULL_NAME']))
135 $u['FULL_NAME'] = self::getUserFullName($u);
136 if (empty($u['PHOTO_SRC']))
137 $u['PHOTO_SRC'] = self::getUserPhotoSrc($u);
138 }
139 $t['USERS'][] = $u;
140 $t['USERS_CNT'] = sizeof($t['USERS']);
141 $allUsers[] = $u;
142 }
143 }
144 }
145 return $allUsers;
146 }
147
148 public static function getUserPhotoSrc(array $user)
149 {
150 if (empty($user['PERSONAL_PHOTO']))
151 return '';
152 $arFileTmp = \CFile::ResizeImageGet(
153 $user["PERSONAL_PHOTO"],
154 array('width' => 58, 'height' => 58),
156 false
157 );
158 return $arFileTmp['src'];
159 }
160
161 public static function getUserFullNameById(int $userId): ?string
162 {
164 'filter' => ['ID' => $userId],
165 'select' => ['ID', 'NAME', 'LAST_NAME', 'SECOND_NAME', 'LOGIN'],
166 ]);
167 if ($user)
168 {
169 return self::getUserFullName($user);
170 }
171
172 return null;
173 }
174
175 public static function getUserFullName(array $user)
176 {
177 return \CUser::FormatName(\CSite::GetNameFormat(false), $user, true, false);
178 }
179
180 public static function getHtmlEditor($id, $fieldName, $content = '')
181 {
182 $id = htmlspecialcharsbx($id);
183 $fieldName = htmlspecialcharsbx($fieldName);
184
185 if (is_array($content) && isset($content['TEXT']))
186 {
187 $content = $content['TEXT'];
188 }
189
190 $result = '<textarea rows="5" cols="40" id="'.$id.'" name="'.$fieldName.'">'.htmlspecialcharsbx(\CBPHelper::stringify($content)).'</textarea>';
191
192 if (CModule::includeModule("fileman"))
193 {
194 $editor = new \CHTMLEditor;
195 $res = array(
196 'useFileDialogs' => false,
197 'height' => 200,
198 'minBodyWidth' => 350,
199 'normalBodyWidth' => 555,
200 'bAllowPhp' => false,
201 'limitPhpAccess' => false,
202 'showTaskbars' => false,
203 'showNodeNavi' => false,
204 'askBeforeUnloadPage' => true,
205 'bbCode' => false,
206 'siteId' => SITE_ID,
207 'autoResize' => true,
208 'autoResizeOffset' => 40,
209 'saveOnBlur' => true,
210 'controlsMap' => array(
211 array('id' => 'Bold', 'compact' => true, 'sort' => 80),
212 array('id' => 'Italic', 'compact' => true, 'sort' => 90),
213 array('id' => 'Underline', 'compact' => true, 'sort' => 100),
214 array('id' => 'Strikeout', 'compact' => true, 'sort' => 110),
215 array('id' => 'RemoveFormat', 'compact' => true, 'sort' => 120),
216 array('id' => 'Color', 'compact' => true, 'sort' => 130),
217 array('id' => 'FontSelector', 'compact' => false, 'sort' => 135),
218 array('id' => 'FontSize', 'compact' => false, 'sort' => 140),
219 array('separator' => true, 'compact' => false, 'sort' => 145),
220 array('id' => 'OrderedList', 'compact' => true, 'sort' => 150),
221 array('id' => 'UnorderedList', 'compact' => true, 'sort' => 160),
222 array('id' => 'AlignList', 'compact' => false, 'sort' => 190),
223 array('separator' => true, 'compact' => false, 'sort' => 200),
224 array('id' => 'InsertLink', 'compact' => true, 'sort' => 210, 'wrap' => 'bx-b-link-'.$id),
225 array('id' => 'InsertImage', 'compact' => false, 'sort' => 220),
226 array('id' => 'InsertVideo', 'compact' => true, 'sort' => 230, 'wrap' => 'bx-b-video-'.$id),
227 array('id' => 'InsertTable', 'compact' => false, 'sort' => 250),
228 array('id' => 'Code', 'compact' => true, 'sort' => 260),
229 array('id' => 'Quote', 'compact' => true, 'sort' => 270, 'wrap' => 'bx-b-quote-'.$id),
230 array('id' => 'Smile', 'compact' => false, 'sort' => 280),
231 array('separator' => true, 'compact' => false, 'sort' => 290),
232 array('id' => 'Fullscreen', 'compact' => false, 'sort' => 310),
233 array('id' => 'BbCode', 'compact' => true, 'sort' => 340),
234 array('id' => 'More', 'compact' => true, 'sort' => 400)
235 ),
236
237 'name' => $fieldName.'[TEXT]',
238 'inputName' => $fieldName.'[TEXT]',
239 'id' => $id,
240 'width' => '100%',
241 'content' => htmlspecialcharsback($content),
242 );
243
244 ob_start();
245 echo '<input type="hidden" name="'.$fieldName.'[TYPE]" value="html">';
246 $editor->show($res);
247 $result = ob_get_contents();
248 ob_end_clean();
249 }
250
251 return $result;
252 }
253
254 public static function prepareTaskDescription($description)
255 {
256 $description = self::replaceFileLinks($description ?? '');
257
258 if (\Bitrix\Main\Loader::includeModule('disk'))
259 {
260 $description = self::replaceDiskLinks($description);
261 }
262
263 return nl2br(trim($description));
264 }
265
267 {
268 $description = self::replaceFileLinks($description ?? '', true);
269
270 if (\Bitrix\Main\Loader::includeModule('disk'))
271 {
272 $description = self::replaceDiskLinks($description, true);
273 }
274
275 return nl2br($description);
276 }
277
278 private static function replaceFileLinks(string $description, $isMobile = false)
279 {
280 $callback = $isMobile ? self::getMobileFileLinksReplaceCallback() : self::getFileLinksReplaceCallback();
281
282 return preg_replace_callback(
283 '|<a href="(/bitrix/tools/bizproc_show_file.php\?)([^"]+)"[^>]*>|',
284 $callback,
286 );
287 }
288
289 private static function getFileLinksReplaceCallback()
290 {
291 return function($matches)
292 {
294 parse_str($matches[2], $query);
295 if (isset($query['i']))
296 {
297 try
298 {
299 $attributes = \Bitrix\Main\UI\Viewer\ItemAttributes::buildByFileId(
300 $query['i'],
301 $matches[1].$matches[2]
302 );
303 return "<a href=\"".$matches[1].$matches[2]."\" ".$attributes.">";
304 }
305 catch (ArgumentException $e)
306 {
307 return sprintf(
308 '<a class="bizproc-file-not-found" data-hint="%s" data-hint-no-icon data-hint-center>',
309 Loc::getMessage('BIZPROC_VIEW_HELPER_FILE_NOT_FOUND')
310 );
311 }
312 }
313
314 return $matches[0];
315 };
316 }
317
318 private static function getMobileFileLinksReplaceCallback()
319 {
320 return function ($matches)
321 {
323 parse_str($matches[2], $query);
324 $filename = '';
325 if (isset($query['f']))
326 {
327 $query['hash'] = md5($query['f']);
328 $filename = $query['f'];
329 unset($query['f']);
330 }
331 $query['mobile_action'] = 'bp_show_file';
332 $query['filename'] = $filename;
333
334 return '<a href="#" data-url="' . SITE_DIR . 'mobile/ajax.php?' . http_build_query($query)
335 . '" data-name="' . htmlspecialcharsbx($filename)
336 . '" onclick="BXMobileApp.UI.Document.open({url: this.getAttribute(\'data-url\'), '
337 . 'filename: this.getAttribute(\'data-name\')}); return false;">'
338 ;
339 };
340 }
341
342 private static function replaceDiskLinks(string $description, $isMobile = false)
343 {
344 $callback = $isMobile ? self::getMobileDiskLinksReplaceCallback() : self::getDiskLinksReplaceCallback();
345
346 return preg_replace_callback(
347 '|<a href="(/bitrix/tools/disk/uf.php\?)([^"]+)"[^>]*>([^<]+)|',
348 $callback,
350 );
351 }
352
353 private static function getDiskLinksReplaceCallback()
354 {
355 return function($matches)
356 {
358 parse_str($matches[2], $query);
359 if (isset($query['attachedId']))
360 {
361 $attach = \Bitrix\Disk\AttachedObject::loadById($query['attachedId']);
362 if ($attach)
363 {
364 try
365 {
366 $attributes = \Bitrix\Main\UI\Viewer\ItemAttributes::buildByFileId(
367 $attach->getFileId(),
368 $matches[1].$matches[2]
369 );
370 return "<a href=\"".$matches[1].$matches[2]."\" ".$attributes.">".$matches[3];
371 }
372 catch (ArgumentException $e)
373 {
374 return sprintf(
375 '<a class="bizproc-file-not-found" data-hint="%s" data-hint-no-icon data-hint-center>',
376 Loc::getMessage('BIZPROC_VIEW_HELPER_FILE_NOT_FOUND')
377 );
378 }
379 }
380 }
381
382 return $matches[0];
383 };
384 }
385
386 private static function getMobileDiskLinksReplaceCallback()
387 {
388 return function($matches)
389 {
391 parse_str($matches[2], $query);
393 $query['mobile_action'] = 'disk_uf_view';
394 $query['filename'] = $filename;
395
396 return '<a href="#" data-url="'.SITE_DIR.'mobile/ajax.php?'.http_build_query($query)
397 .'" data-name="'.htmlspecialcharsbx($filename).'" onclick="BXMobileApp.UI.Document.open({url: this.getAttribute(\'data-url\'), filename: this.getAttribute(\'data-name\')}); return false;">'.$matches[3];
398 };
399 }
400
401 public static function getWorkflowResult(
402 string $workflowId,
403 int $userId,
404 string $context = self::DESKTOP_CONTEXT
405 ): array
406 {
407 static $cache = [];
408
409 if (!isset($cache[$workflowId]))
410 {
411 $cache[$workflowId] = ResultTable::getList([
412 'filter' => [
413 '=WORKFLOW_ID' => $workflowId,
414 ],
415 'select' => ['ACTIVITY', 'RESULT'],
416 ])->fetch();
417 }
418
419 $result = $cache[$workflowId];
420 $renderedResult = null;
421 if ($result)
422 {
423 $renderedResult = \CBPActivity::callStaticMethod(
424 $result['ACTIVITY'],
425 'renderResult',
426 [
427 $result['RESULT'],
428 $workflowId,
429 $userId,
430 ],
431 );
432 }
433
434 $processedResult =
435 ($context === self::MOBILE_CONTEXT)
436 ? (new \Bitrix\Bizproc\Result\MobileResultHandler($workflowId))->handle($renderedResult)
437 : (new \Bitrix\Bizproc\Result\WebResultHandler($workflowId))->handle($renderedResult)
438 ;
439
440 return $processedResult;
441 }
442
443 public static function formatDateTime(?DateTime $date): string
444 {
445 if (!$date)
446 {
447 return '';
448 }
449
450 $thisYear = $date->format('Y') === date('Y');
451 $culture = \Bitrix\Main\Application::getInstance()->getContext()->getCulture();
452 $df = $thisYear
453 ? $culture?->getDayMonthFormat() ?? 'j F'
454 : $culture?->getLongDateFormat() ?? 'j F Y'
455 ;
456 $tf = $culture?->getShortTimeFormat() ?? 'H:i';
457
458 return \FormatDate("$df, $tf", $date->toUserTime());
459 }
460}
if(!is_object($USER)||! $USER->IsAuthorized()) $userId
Определения check_mail.php:18
static getInstance()
Определения application.php:98
static getRow(array $parameters)
Определения datamanager.php:398
format($format)
Определения date.php:110
toUserTime()
Определения datetime.php:155
static callStaticMethod($code, $method, $arParameters=array())
Определения activity.php:1375
static GetList($arOrder=array("ID"=> "DESC"), $arFilter=array(), $arGroupBy=false, $arNavStartParams=false, $arSelectFields=array())
Определения taskservice.php:138
static getTaskUsers($taskId)
Определения taskservice.php:99
const Running
Определения constants.php:258
Определения viewhelper.php:9
static renderUserSearch($ID, $searchInputID, $dataInputID, $componentName, $siteID='', $nameFormat='', $delay=0)
Определения viewhelper.php:15
static getUserFullNameById(int $userId)
Определения viewhelper.php:161
static getUserFullName(array $user)
Определения viewhelper.php:175
static getUserPhotoSrc(array $user)
Определения viewhelper.php:148
static getWorkflowResult(string $workflowId, int $userId, string $context=self::DESKTOP_CONTEXT)
Определения viewhelper.php:401
static getHtmlEditor($id, $fieldName, $content='')
Определения viewhelper.php:180
static formatDateTime(?DateTime $date)
Определения viewhelper.php:443
static prepareMobileTaskDescription($description)
Определения viewhelper.php:266
static getWorkflowTasks($workflowId, $withUsers=false, $extendUserInfo=false)
Определения viewhelper.php:66
const DESKTOP_CONTEXT
Определения viewhelper.php:12
const MOBILE_CONTEXT
Определения viewhelper.php:13
static prepareTaskDescription($description)
Определения viewhelper.php:254
static joinUsersToTasks(&$tasks, &$taskUsers, $extendUserInfo=false)
Определения viewhelper.php:121
$content
Определения commerceml.php:144
$componentName
Определения component_props2.php:49
$nameFormat
Определения discount_coupon_list.php:278
$filename
Определения file_edit.php:47
</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
if($ajaxMode) $ID
Определения get_user.php:27
if(Loader::includeModule( 'bitrix24')) elseif(Loader::includeModule('intranet') &&CIntranetUtils::getPortalZone() !=='ru') $description
Определения .description.php:24
$siteID
Определения cron_frame.php:12
$context
Определения csv_new_setup.php:223
const BX_RESIZE_IMAGE_EXACT
Определения constants.php:12
const SITE_DIR(!defined('LANG'))
Определения include.php:72
$culture
Определения include.php:61
htmlspecialcharsback($str)
Определения tools.php:2693
htmlspecialcharsbx($string, $flags=ENT_COMPAT, $doubleEncode=true)
Определения tools.php:2701
if(empty($signedUserToken)) $key
Определения quickway.php:257
$matches
Определения index.php:22
const SITE_ID
Определения sonet_set_content_view.php:12
$GLOBALS['_____370096793']
Определения update_client.php:1