Skip to content

Commit

Permalink
Add workflow services and update changelog
Browse files Browse the repository at this point in the history
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
mesilov committed Mar 31, 2024
1 parent f554364 commit 7acaf7a
Show file tree
Hide file tree
Showing 8 changed files with 200 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 2.0-beta.2 — 1.04.2024

### Added
* add `bizproc` [services](https://github.com/mesilov/bitrix24-php-sdk/issues/376)
### Changed
* updated [dependencies versions](https://github.com/mesilov/bitrix24-php-sdk/issues/373):
* require
Expand Down
10 changes: 10 additions & 0 deletions src/Services/ServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Bitrix24\SDK\Services\User\UserServiceBuilder;
use Bitrix24\SDK\Services\UserConsent\UserConsentServiceBuilder;
use Bitrix24\SDK\Services\Placement\PlacementServiceBuilder;
use Bitrix24\SDK\Services\Workflows\WorkflowsServiceBuilder;

class ServiceBuilder extends AbstractServiceBuilder
{
Expand Down Expand Up @@ -120,4 +121,13 @@ public function getTelephonyScope(): TelephonyServiceBuilder

return $this->serviceCache[__METHOD__];
}

public function getBizProcScope(): WorkflowsServiceBuilder
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new WorkflowsServiceBuilder($this->core, $this->batch, $this->bulkItemsReader, $this->log);
}

return $this->serviceCache[__METHOD__];
}
}
13 changes: 13 additions & 0 deletions src/Services/Workflows/Common/WorkflowAutoExecutionType.php
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;
}
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 src/Services/Workflows/Template/Result/WorkflowTemplatesResult.php
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;
}
}
22 changes: 22 additions & 0 deletions src/Services/Workflows/Template/Service/Batch.php
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)
{
}
}
52 changes: 52 additions & 0 deletions src/Services/Workflows/Template/Service/Template.php
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,
]
)
);
}
}
24 changes: 24 additions & 0 deletions src/Services/Workflows/WorkflowsServiceBuilder.php
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__];
}
}

0 comments on commit 7acaf7a

Please sign in to comment.