Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
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 'isInvalid' => false,
50 ];
51
52 $type = mb_strtolower($robot['Type']);
53 if (isset($availableRobots[$type]['ROBOT_SETTINGS']))
54 {
55 $settings = $availableRobots[$type]['ROBOT_SETTINGS'];
56
57 if (!empty($settings['RESPONSIBLE_TO_HEAD']) && $robot['Properties'][$settings['RESPONSIBLE_TO_HEAD']] === 'Y')
58 {
59 $result['responsibleLabel'] = Loc::getMessage('BIZPROC_AUTOMATION_COMPONENT_BASE_TO_HEAD');
60 }
61
62 if (isset($settings['RESPONSIBLE_PROPERTY']))
63 {
64 $users = static::getUsersFromResponsibleProperty($robot, $settings['RESPONSIBLE_PROPERTY']);
65 $usersLabel = \CBPHelper::UsersArrayToString($users, [], $documentType, false);
66
67 if ($result['responsibleLabel'] && $usersLabel)
68 {
69 $result['responsibleLabel'] .= ', ';
70 }
71 $result['responsibleLabel'] .= $usersLabel;
72
73 if ($users && count($users) === 1 && $users[0] && mb_strpos($users[0], 'user_') === 0)
74 {
75 $id = (int) \CBPHelper::StripUserPrefix($users[0]);
76 $result['responsibleUrl'] = \CComponentEngine::MakePathFromTemplate(
77 '/company/personal/user/#user_id#/',
78 array('user_id' => $id)
79 );
80 $result['responsibleId'] = $id;
81 }
82 }
83 }
84 elseif (!isset($availableRobots[$type]))
85 {
86 $result['isInvalid'] = true;
87 }
88
89 return $result;
90 }
91
92 protected static function getUsersFromResponsibleProperty(array $robot, $propertyName): ?array
93 {
94 $value = null;
95 $props = $robot['Properties'];
96 $path = explode('.', $propertyName);
97
98 foreach ($path as $chain)
99 {
100 $value = ($props && is_array($props) && isset($props[$chain])) ? $props[$chain] : null;
101 $props = $value;
102 }
103
104 return $value ? (array)$value : null;
105 }
106}
static getTemplateViewData(array $template, $documentType)
Definition base.php:32
static getUsersFromResponsibleProperty(array $robot, $propertyName)
Definition base.php:92
static getRobotViewData($robot, array $documentType)
Definition base.php:42
static getMessage($code, $replace=null, $language=null)
Definition loc.php:29