Bitrix-D7 22.6
 
Загрузка...
Поиск...
Не найдено
base.php
1<?php
2
4
9
10abstract class Base extends \CBitrixComponent implements Errorable
11{
14
15 public function __construct($component = null)
16 {
17 parent::__construct($component);
18
19 $this->errorCollection = new ErrorCollection();
20 }
21
22 public function getErrors(): array
23 {
24 return $this->errorCollection->toArray();
25 }
26
27 public function getErrorByCode($code): ?Error
28 {
29 return $this->errorCollection->getErrorByCode($code);
30 }
31
32 public static function getTemplateViewData(array $template, $documentType)
33 {
34 foreach ($template['ROBOTS'] as $i => $robot)
35 {
36 $template['ROBOTS'][$i]['viewData'] = static::getRobotViewData($robot, $documentType);
37 }
38
39 return $template;
40 }
41
42 public static function getRobotViewData($robot, array $documentType): array
43 {
44 $availableRobots = \Bitrix\Bizproc\Automation\Engine\Template::getAvailableRobots($documentType);
45 $result = [
46 'responsibleLabel' => '',
47 'responsibleUrl' => '',
48 'responsibleId' => 0,
49 ];
50
51 $type = mb_strtolower($robot['Type']);
52 if (isset($availableRobots[$type]) && isset($availableRobots[$type]['ROBOT_SETTINGS']))
53 {
54 $settings = $availableRobots[$type]['ROBOT_SETTINGS'];
55
56 if (!empty($settings['RESPONSIBLE_TO_HEAD']) && $robot['Properties'][$settings['RESPONSIBLE_TO_HEAD']] === 'Y')
57 {
58 $result['responsibleLabel'] = Loc::getMessage('BIZPROC_AUTOMATION_COMPONENT_BASE_TO_HEAD');
59 }
60
61 if (isset($settings['RESPONSIBLE_PROPERTY']))
62 {
63 $users = static::getUsersFromResponsibleProperty($robot, $settings['RESPONSIBLE_PROPERTY']);
64 $usersLabel = \CBPHelper::UsersArrayToString($users, [], $documentType, false);
65
66 if ($result['responsibleLabel'] && $usersLabel)
67 {
68 $result['responsibleLabel'] .= ', ';
69 }
70 $result['responsibleLabel'] .= $usersLabel;
71
72 if ($users && count($users) === 1 && $users[0] && mb_strpos($users[0], 'user_') === 0)
73 {
74 $id = (int) \CBPHelper::StripUserPrefix($users[0]);
75 $result['responsibleUrl'] = \CComponentEngine::MakePathFromTemplate(
76 '/company/personal/user/#user_id#/',
77 array('user_id' => $id)
78 );
79 $result['responsibleId'] = $id;
80 }
81 }
82 }
83
84 return $result;
85 }
86
87 protected static function getUsersFromResponsibleProperty(array $robot, $propertyName): ?array
88 {
89 $value = null;
90 $props = $robot['Properties'];
91 $path = explode('.', $propertyName);
92
93 foreach ($path as $chain)
94 {
95 $value = ($props && is_array($props) && isset($props[$chain])) ? $props[$chain] : null;
96 $props = $value;
97 }
98
99 return $value ? (array)$value : null;
100 }
101}
static getTemplateViewData(array $template, $documentType)
Definition: base.php:32
static getUsersFromResponsibleProperty(array $robot, $propertyName)
Definition: base.php:87
static getRobotViewData($robot, array $documentType)
Definition: base.php:42
static getMessage($code, $replace=null, $language=null)
Definition: loc.php:29