-
-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Workflow service and associated classes
The update introduces a new Workflow service in the WorkflowsServiceBuilder, including supporting classes such as Batch and WorkflowInstanceItemResult. It also includes methods for workflow instances and their results. The additions provide functionality to list launched workflows and handle batch operations. Signed-off-by: mesilov <[email protected]>
- Loading branch information
Showing
5 changed files
with
159 additions
and
1 deletion.
There are no files selected for viewing
46 changes: 46 additions & 0 deletions
46
src/Services/Workflows/Workflow/Result/WorkflowInstanceItemResult.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Workflow\Result; | ||
|
||
use Bitrix24\SDK\Core\Result\AbstractItem; | ||
use Bitrix24\SDK\Services\Workflows\Common\WorkflowAutoExecutionType; | ||
use DateTimeImmutable; | ||
use DateTimeInterface; | ||
|
||
/** | ||
* @property-read string $ID workflow ID | ||
* @property-read DateTimeImmutable $MODIFIED | ||
* @property-read ?DateTimeImmutable $OWNED_UNTIL time for blocking of a workflow. Process is considered as unresponsive, if the difference of blocking time with the current time is more than 5 minutes; | ||
* @property-read ?DateTimeImmutable $STARTED workflow launch date; | ||
* @property-read ?string $MODULE_ID module ID (as per document); | ||
* @property-read ?string $ENTITY entity ID (as per document); | ||
* @property-read ?int $DOCUMENT_ID document ID; | ||
* @property-read ?int $STARTED_BY who launched the workflow; | ||
* @property-read ?int $TEMPLATE_ID workflow template ID. | ||
*/ | ||
class WorkflowInstanceItemResult extends AbstractItem | ||
{ | ||
public function __get($offset) | ||
{ | ||
switch ($offset) { | ||
case 'STARTED_BY': | ||
case 'TEMPLATE_ID': | ||
return (int)$this->data[$offset]; | ||
case 'DOCUMENT_ID': | ||
if ($this->data[$offset] !== '') { | ||
// "DEAL_158310" | ||
return (int)substr($this->data[$offset], strpos($this->data[$offset], '_')+1); | ||
} | ||
return null; | ||
case 'MODIFIED': | ||
case 'STARTED': | ||
if ($this->data[$offset] !== '') { | ||
return DateTimeImmutable::createFromFormat(DATE_ATOM, $this->data[$offset]); | ||
} | ||
return null; | ||
} | ||
return $this->data[$offset] ?? null; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/Services/Workflows/Workflow/Result/WorkflowInstancesResult.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Workflow\Result; | ||
|
||
use Bitrix24\SDK\Core\Exceptions\BaseException; | ||
use Bitrix24\SDK\Core\Result\AbstractItem; | ||
use Bitrix24\SDK\Core\Result\AbstractResult; | ||
|
||
class WorkflowInstancesResult extends AbstractResult | ||
{ | ||
/** | ||
* @return WorkflowInstanceItemResult[] | ||
* @throws BaseException | ||
*/ | ||
public function getInstances(): array | ||
{ | ||
$res = []; | ||
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) { | ||
$res[] = new WorkflowInstanceItemResult($item); | ||
} | ||
|
||
return $res; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Workflow\Service; | ||
|
||
use Bitrix24\SDK\Core\Contracts\BatchOperationsInterface; | ||
use Psr\Log\LoggerInterface; | ||
|
||
readonly class Batch | ||
{ | ||
public function __construct( | ||
protected BatchOperationsInterface $batch, | ||
protected LoggerInterface $log) | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Workflow\Service; | ||
|
||
use Bitrix24\SDK\Core\Contracts\CoreInterface; | ||
use Bitrix24\SDK\Core\Exceptions\BaseException; | ||
use Bitrix24\SDK\Core\Exceptions\TransportException; | ||
use Bitrix24\SDK\Services\AbstractService; | ||
use Bitrix24\SDK\Services\Workflows; | ||
use Psr\Log\LoggerInterface; | ||
|
||
|
||
class Workflow extends AbstractService | ||
{ | ||
public Batch $batch; | ||
|
||
public function __construct( | ||
Batch $batch, | ||
CoreInterface $core, | ||
LoggerInterface $log | ||
) | ||
{ | ||
parent::__construct($core, $log); | ||
$this->batch = $batch; | ||
} | ||
|
||
/** | ||
* returns list of launched workflows | ||
* | ||
* @param array $select | ||
* @param array $order | ||
* @param array $filter | ||
* @return Workflows\Workflow\Result\WorkflowInstancesResult | ||
* @throws BaseException | ||
* @throws TransportException | ||
* @see https://training.bitrix24.com/rest_help/workflows/workflow/bizproc_workflow_instances.php | ||
*/ | ||
public function instances( | ||
array $select = ['ID', 'MODIFIED', 'OWNED_UNTIL', 'MODULE_ID', 'ENTITY', 'DOCUMENT_ID', 'STARTED', 'STARTED_BY', 'TEMPLATE_ID'], | ||
array $order = ['STARTED' => 'DESC'], | ||
array $filter = []): Workflows\Workflow\Result\WorkflowInstancesResult | ||
{ | ||
return new Workflows\Workflow\Result\WorkflowInstancesResult( | ||
$this->core->call( | ||
'bizproc.workflow.instances', | ||
[ | ||
'select' => $select, | ||
'order' => $order, | ||
'filter' => $filter, | ||
] | ||
) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters