*/ class FlowchartDataLoader implements Loader { public function __construct( private EntityManager $entityManager ) {} public function process(Entity $entity, Params $params): void { $flowchartData = $entity->get('flowchartData') ?? (object) []; $list = $flowchartData->list ?? []; $flowNodes = $this->entityManager ->getRDBRepositoryByClass(BpmnFlowNode::class) ->where(['processId' => $entity->getId()]) ->order('number', true) ->limit(0, 400) ->find(); foreach ($list as $item) { $this->loadOutlineData($item, $flowNodes); } $entity->set('flowchartData', $flowchartData); } /** * @param stdClass $item * @param Collection $flowNodeList */ private function loadOutlineData($item, $flowNodeList): void { $type = $item->type ?? null; $id = $item->id ?? null; if (!$type || !$id) { return; } if ($type === 'flow') { return; } if ($type === 'eventSubProcess' || $type === 'subProcess') { $list = $item->dataList ?? []; foreach ($flowNodeList as $flowNode) { if ($flowNode->get('elementId') == $id) { $subProcessId = $flowNode->getDataItemValue('subProcessId'); $spFlowNodeList = $this->entityManager ->getRDBRepositoryByClass(BpmnFlowNode::class) ->where(['processId' => $subProcessId]) ->order('number', true) ->limit(0, 400) ->find(); foreach ($list as $spItem) { $this->loadOutlineData($spItem, $spFlowNodeList); } break; } } } foreach ($flowNodeList as $flowNode) { $status = $flowNode->get('status'); if ($flowNode->get('elementId') == $id) { if ($status === BpmnFlowNode::STATUS_PROCESSED) { $item->outline = 3; return; } } } foreach ($flowNodeList as $flowNode) { $status = $flowNode->get('status'); if ($flowNode->get('elementId') == $id) { if ($status === BpmnFlowNode::STATUS_IN_PROCESS) { $item->outline = 1; return; } } } foreach ($flowNodeList as $flowNode) { $status = $flowNode->get('status'); if ($flowNode->get('elementId') == $id) { if ($status === BpmnFlowNode::STATUS_PENDING) { $item->outline = 2; return; } } } foreach ($flowNodeList as $flowNode) { $status = $flowNode->get('status'); if ($flowNode->get('elementId') == $id) { if ( $status === BpmnFlowNode::STATUS_FAILED || $status === BpmnFlowNode::STATUS_INTERRUPTED ) { $item->outline = 4; return; } } } } }