Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
ParametersUploaderController.php
1<?php
2
4
10
11Loader::requireModule('ui');
12
14{
15 public function __construct(array $options)
16 {
17 $complexDocumentId = null;
18 $complexDocumentType = null;
19
20 if (isset($options['signedDocument']) && is_string($options['signedDocument']))
21 {
22 $unsignedDocument = \CBPDocument::unSignParameters($options['signedDocument']);
23 if (!empty($unsignedDocument) && count($unsignedDocument) === 2)
24 {
25 try
26 {
27 $complexDocumentType = \CBPHelper::parseDocumentId($unsignedDocument[0]);
28 $complexDocumentId = \CBPHelper::parseDocumentId(
29 [$complexDocumentType[0], $complexDocumentType[1], $unsignedDocument[1]]
30 );
31 }
32 catch (\CBPArgumentNullException $e)
33 {}
34 }
35 }
36
37 $options['complexDocumentId'] = $complexDocumentId;
38 $options['complexDocumentType'] = $complexDocumentType;
39 $options['templateId'] = is_numeric($options['templateId'] ?? null) ? (int)$options['templateId'] : 0;
40
41 parent::__construct($options);
42 }
43
44 public function isAvailable(): bool
45 {
46 return $this->hasRights();
47 }
48
50 {
51 return new Configuration();
52 }
53
54 public function canUpload()
55 {
56 return $this->hasRights();
57 }
58
59 public function canView(): bool
60 {
61 return $this->hasRights();
62 }
63
64 public function verifyFileOwner(FileOwnershipCollection $files): void
65 {}
66
67 public function canRemove(): bool
68 {
69 return $this->hasRights();
70 }
71
72 private function hasRights(): bool
73 {
74 [
75 'complexDocumentId' => $complexDocumentId,
76 'complexDocumentType' => $complexDocumentType,
77 'templateId' => $templateId
78 ] = $this->getOptions();
79
80 if ($templateId <= 0 || !is_array($complexDocumentType))
81 {
82 return false;
83 }
84
85 $currentUser = CurrentUser::get();
86 $currentUserId = (int)$currentUser->getId();
87
88 if ($currentUserId > 0)
89 {
90 if ($complexDocumentId)
91 {
92 return \CBPDocument::canUserOperateDocument(
93 \CBPCanUserOperateOperation::StartWorkflow,
94 $currentUserId,
95 $complexDocumentId,
96 [
97 'UserGroups' => \CUser::GetUserGroup($currentUserId),
98 'DocumentStates' => \CBPDocument::getActiveStates($complexDocumentId),
99 'WorkflowTemplateId' => $templateId,
100 ]
101 );
102 }
103
104 return \CBPDocument::canUserOperateDocumentType(
105 \CBPCanUserOperateOperation::StartWorkflow,
106 $currentUserId,
107 $complexDocumentType,
108 [
109 'UserGroups' => \CUser::GetUserGroup($currentUserId),
110 'DocumentStates' => \CBPDocument::getDocumentStates($complexDocumentType, $complexDocumentId),
111 'WorkflowTemplateId' => $templateId,
112 ]
113 );
114 }
115
116 return false;
117 }
118}