Bitrix-D7 23.9
 
Загрузка...
Поиск...
Не найдено
tracker.php
1<?php
3
5use Bitrix\Bizproc\WorkflowTemplateTable;
8
9class Tracker
10{
11 const STATUS_WAITING = 0;
12 const STATUS_RUNNING = 1;
15
17 protected $target;
18
20 {
21 $this->target = $target;
22 }
23
24 public function getLog(array $statuses)
25 {
26 return $this->getBizprocTrackingEntries($statuses);
27 }
28
29 private function getBizprocTrackingEntries($statuses)
30 {
31 $entries = [];
32
33 $states = $this->getStatusesStates($statuses);
34
35 if ($states)
36 {
37 $trackIterator = \CBPTrackingService::GetList(
38 ['ID' => 'ASC'],
39 ['@WORKFLOW_ID' => array_keys($states)]
40 );
41
42 $workflowStatuses = [];
43
44 while ($row = $trackIterator->fetch())
45 {
46 if (!array_key_exists($row['WORKFLOW_ID'], $workflowStatuses))
47 {
48 $hasInstance = $row['WORKFLOW_ID'] && WorkflowInstanceTable::exists($row['WORKFLOW_ID']);
49 $workflowStatus = $hasInstance ? \CBPWorkflowStatus::Running : \CBPWorkflowStatus::Completed;
50
51 $workflowStatuses[$row['WORKFLOW_ID']] = $workflowStatus;
52 }
53
54 $status = $states[$row['WORKFLOW_ID']];
55 $row['WORKFLOW_STATUS'] = $workflowStatuses[$row['WORKFLOW_ID']];
56 $entries[$status][] = $row;
57 }
58 }
59
60 return $entries;
61 }
62
63 private function getStatusesStates($statuses)
64 {
65 $states = array();
66 $templateIds = $this->getBizprocTemplateIds($statuses);
67
68 if (!$templateIds)
69 return $states;
70
71 $stateIterator = WorkflowStateTable::getList(array(
72 'select' => array('ID', 'WORKFLOW_TEMPLATE_ID'),
73 'filter' => array(
74 '=DOCUMENT_ID' => $this->target->getDocumentId(),
75 '@WORKFLOW_TEMPLATE_ID' => array_keys($templateIds)
76 ),
77 'order' => array('STARTED' => 'DESC')
78 ));
79
80 while ($row = $stateIterator->fetch())
81 {
82 $status = $templateIds[$row['WORKFLOW_TEMPLATE_ID']];
83 if (!in_array($status, $states))
84 $states[$row['ID']] = $status;
85 }
86
87 return $states;
88 }
89
90 private function getBizprocTemplateIds($statuses)
91 {
92 $documentType = $this->target->getDocumentType();
93 $ids = array();
94
95 $iterator = WorkflowTemplateTable::getList(array(
96 'select' => array('ID', 'DOCUMENT_STATUS'),
97 'filter' => array(
98 '=MODULE_ID' => $documentType[0],
99 '=ENTITY' => $documentType[1],
100 '=DOCUMENT_TYPE' => $documentType[2],
101 //'=AUTO_EXECUTE' => \CBPDocumentEventType::Automation,
102 '@DOCUMENT_STATUS' => $statuses
103 )
104 ));
105
106 while ($row = $iterator->fetch())
107 {
108 $ids[$row['ID']] = $row['DOCUMENT_STATUS'];
109 }
110
111 return $ids;
112 }
113}
__construct(BaseTarget $target)
Definition tracker.php:19