/** * Create new workflow * * @param User $client * @param WorkflowableInterface $object * @param integer $type * @param DocumentSignature|DocumentSignature[] $signatures * @param array $objectIds * @return Workflow|null * @throws \InvalidArgumentException */ public function createWorkflow(User $client, WorkflowableInterface $object, $type, $signatures = null, array $objectIds = null) { $class = $this->om->getClassMetadata(get_class($object))->getName(); $workflow = new Workflow(); $workflow->setClient($client); $workflow->setType($type); $workflow->setObjectType($class); $workflow->setMessageCode($object->getWorkflowMessageCode()); if (method_exists($object, 'getId') && null !== $object->getId()) { $workflow->setObjectId($object->getId()); } if ($type == Workflow::TYPE_PAPERWORK) { $documentSignatures = array(); if (null === $signatures && $object instanceof SignableInterface) { $signature = $this->signatureManager->findDocumentSignatureBySource($object); if ($signature) { $documentSignatures[] = $signature; } } else { if (is_object($signatures)) { if (!$signatures instanceof DocumentSignature) { throw new \InvalidArgumentException('Parameter signatures must be array or instance of DocumentSignature.'); } $documentSignatures[] = $signatures; } elseif (is_array($signatures)) { $documentSignatures = $signatures; } } if (count($documentSignatures)) { foreach ($documentSignatures as $documentSignature) { $workflow->addDocumentSignature($documentSignature); } $this->updateClientStatusByDocumentSignatures($workflow); } if ($object instanceof ClientPortfolio) { $this->updateClientStatusByClientPortfolio($workflow, $object); } } elseif ($object instanceof SystemAccount) { $this->updateClientStatusBySystemAccount($workflow, $object); } if (null !== $objectIds) { $workflow->setObjectIds($objectIds); } if ($object instanceof PaymentWorkflowableInterface) { $workflow->setAmount($object->getWorkflowAmount()); } $this->om->persist($workflow); $this->om->flush(); return $workflow; }