Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
TaskUploaderController.php
1<?php
2
4
9
11{
12 public function __construct(array $options)
13 {
14 $options['taskId'] = (int)($options['taskId'] ?? 0);
15 $options['fieldId'] = (string)($options['fieldName'] ?? 0);
16
17 parent::__construct($options);
18 }
19
20 public function isAvailable(): bool
21 {
22 return true;
23 }
24
26 {
27 return new Configuration();
28 }
29
30 public function canUpload(): bool
31 {
32 [
33 'taskId' => $taskId,
34 'fieldId' => $fieldId,
35 ] = $this->getOptions();
36
37 if (!$taskId)
38 {
39 return false;
40 }
41
42 $userId = (int)(CurrentUser::get()?->getId() ?? 0);
43 $taskUserIds = \CBPTaskService::getTaskUserIds($taskId);
44
45 if (!in_array($userId, $taskUserIds, true))
46 {
47 return false;
48 }
49
50 $task = \CBPTaskService::getList(
51 arFilter: ['ID' => $taskId],
52 arSelectFields: ['ACTIVITY', 'PARAMETERS', 'STATUS']
53 )->fetch();
54
55 if ($task && (int)$task['STATUS'] === \CBPTaskStatus::Running)
56 {
57 $taskFields = \CBPDocument::getTaskControls($task)['FIELDS'] ?? [];
58
59 $editableFields = array_filter(
60 $taskFields,
61 static fn($field) => $field['Id'] === $fieldId && in_array($field['Type'], ['file', 'S:DiskFile']),
62 );
63
64 return count($editableFields) > 0;
65 }
66
67 return false;
68 }
69
70 public function verifyFileOwner(FileOwnershipCollection $files): void
71 {
72 $stop = true;
73
74 // $entityFiles = $this->fetchToDoActivityFiles();
75 // foreach ($files as $file)
76 // {
77 // if (in_array($file->getId(), $entityFiles, true))
78 // {
79 // $file->markAsOwn();
80 // }
81 // }
82 }
83
84 public function canView(): bool
85 {
86 return true;// todo: check?
87 }
88
89 public function canRemove(): bool
90 {
91 return false;
92 }
93}