-
-
Notifications
You must be signed in to change notification settings - Fork 155
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add workflow services and update changelog
This update adds new workflow services which provide support for working with workflow templates. Additionally, a necessary update in the changelog has been made to provide transparency to users about the added 'bizproc' services and new features in the workflow module. This step towards enriching Bitrix24 SDK with workflow enhancements could help in managing workflows better and provide users with more flexibility and control. Signed-off-by: mesilov <mesilov.maxim@gmail.com>
- Loading branch information
Showing
8 changed files
with
200 additions
and
0 deletions.
There are no files selected for viewing
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
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
13 changes: 13 additions & 0 deletions
13
src/Services/Workflows/Common/WorkflowAutoExecutionType.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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Common; | ||
|
||
enum WorkflowAutoExecutionType: int | ||
{ | ||
case withoutAutoExecution = 0; | ||
case whenAdded = 1; | ||
case whenModified = 2; | ||
case whenAddedAndModified = 3; | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Services/Workflows/Template/Result/WorkflowTemplateItemResult.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,50 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Template\Result; | ||
|
||
use Bitrix24\SDK\Core\Result\AbstractItem; | ||
use Bitrix24\SDK\Services\Workflows\Common\WorkflowAutoExecutionType; | ||
use DateTimeImmutable; | ||
|
||
/** | ||
* @property-read int $ID | ||
* @property-read ?string $MODULE_ID | ||
* @property-read ?string $ENTITY | ||
* @property-read ?array $DOCUMENT_TYPE | ||
* @property-read ?WorkflowAutoExecutionType $AUTO_EXECUTE | ||
* @property-read ?string $NAME | ||
* @property-read ?array $TEMPLATE | ||
* @property-read ?array $PARAMETERS | ||
* @property-read ?array $VARIABLES | ||
* @property-read ?array $CONSTANTS | ||
* @property-read ?DateTimeImmutable $MODIFIED | ||
* @property-read ?bool $IS_MODIFIED | ||
* @property-read ?int $USER_ID | ||
* @property-read ?string $SYSTEM_CODE | ||
*/ | ||
class WorkflowTemplateItemResult extends AbstractItem | ||
{ | ||
public function __get($offset) | ||
{ | ||
switch ($offset) { | ||
case 'ID': | ||
case 'USER_ID': | ||
return (int)$this->data[$offset]; | ||
case 'AUTO_EXECUTE': | ||
if ($this->data[$offset] !== null) { | ||
return WorkflowAutoExecutionType::from((int)$this->data[$offset]); | ||
} | ||
return null; | ||
case 'MODIFIED': | ||
if ($this->data[$offset] !== '') { | ||
return DateTimeImmutable::createFromFormat(DATE_ATOM, $this->data[$offset]); | ||
} | ||
return null; | ||
case 'IS_MODIFIED': | ||
return $this->data[$offset] === 'Y'; | ||
} | ||
return $this->data[$offset] ?? null; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/Services/Workflows/Template/Result/WorkflowTemplatesResult.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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Template\Result; | ||
|
||
use Bitrix24\SDK\Core\Exceptions\BaseException; | ||
use Bitrix24\SDK\Core\Result\AbstractItem; | ||
use Bitrix24\SDK\Core\Result\AbstractResult; | ||
use Bitrix24\SDK\Services\CRM\Deal\Result\DealItemResult; | ||
use DateTimeInterface; | ||
|
||
class WorkflowTemplatesResult extends AbstractResult | ||
{ | ||
/** | ||
* @return WorkflowTemplateItemResult[] | ||
* @throws BaseException | ||
*/ | ||
public function getTemplates(): array | ||
{ | ||
$res = []; | ||
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) { | ||
$res[] = new WorkflowTemplateItemResult($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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Template\Service; | ||
|
||
use Bitrix24\SDK\Core\Contracts\BatchOperationsInterface; | ||
use Bitrix24\SDK\Core\Exceptions\BaseException; | ||
use Bitrix24\SDK\Core\Result\AddedItemBatchResult; | ||
use Bitrix24\SDK\Core\Result\DeletedItemBatchResult; | ||
use Bitrix24\SDK\Core\Result\UpdatedItemBatchResult; | ||
use Generator; | ||
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,52 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows\Template\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 Template extends AbstractService | ||
{ | ||
public Batch $batch; | ||
|
||
public function __construct( | ||
Batch $batch, | ||
CoreInterface $core, | ||
LoggerInterface $log | ||
) | ||
{ | ||
parent::__construct($core, $log); | ||
$this->batch = $batch; | ||
} | ||
|
||
/** | ||
* The method bizproc.workflow.template.list returns list of workflow templates, specified for a site. This method requires administrator access permissions. | ||
* @param array $select | ||
* @param array $filter | ||
* @return Workflows\Template\Result\WorkflowTemplatesResult | ||
* @throws BaseException | ||
* @throws TransportException | ||
* @see https://training.bitrix24.com/rest_help/workflows/wirkflow_template/bizproc_workflow_template_list.php | ||
*/ | ||
public function list( | ||
array $select = ['ID', 'MODULE_ID', 'ENTITY', 'DOCUMENT_TYPE', 'AUTO_EXECUTE', 'NAME', 'NAME', 'TEMPLATE', 'PARAMETERS', 'VARIABLES', 'CONSTANTS', 'MODIFIED', 'IS_MODIFIED', 'USER_ID', 'SYSTEM_CODE'], | ||
array $filter = []): Workflows\Template\Result\WorkflowTemplatesResult | ||
{ | ||
return new Workflows\Template\Result\WorkflowTemplatesResult( | ||
$this->core->call( | ||
'bizproc.workflow.template.list', | ||
[ | ||
'select' => $select, | ||
'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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Bitrix24\SDK\Services\Workflows; | ||
|
||
use Bitrix24\SDK\Services\AbstractServiceBuilder; | ||
use Bitrix24\SDK\Services\Workflows; | ||
|
||
class WorkflowsServiceBuilder extends AbstractServiceBuilder | ||
{ | ||
public function template(): Workflows\Template\Service\Template | ||
{ | ||
if (!isset($this->serviceCache[__METHOD__])) { | ||
$this->serviceCache[__METHOD__] = new Workflows\Template\Service\Template( | ||
new Template\Service\Batch($this->batch, $this->log), | ||
$this->core, | ||
$this->log | ||
); | ||
} | ||
|
||
return $this->serviceCache[__METHOD__]; | ||
} | ||
} |