Skip to content

Commit 6bbbe00

Browse files
committed
add activity read models
Signed-off-by: mesilov <[email protected]>
1 parent 1520b90 commit 6bbbe00

22 files changed

+748
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@
88
* add new scope `Placements` and services [add Placements support](https://github.com/mesilov/bitrix24-php-sdk/issues/274)
99
* add in scope `CRM` new service `Leads` in scope «CRM» [add Leads support](https://github.com/mesilov/bitrix24-php-sdk/issues/282)
1010
* add in scope `CRM` new service `Activity` in scope «CRM» [add Activity support](https://github.com/mesilov/bitrix24-php-sdk/issues/283)
11+
* add in scope `CRM` for entity Deal method `Services\CRM\Deal\Service\Batch::update` batch update deals
12+
* add in scope `CRM` for entity Contact method `Services\CRM\Contact\Service\Batch::delete` batch delete contacts
13+
* add in scope `CRM` [read models](https://github.com/mesilov/bitrix24-php-sdk/issues/300) for activity `Services\CRM\Activity\ReadModel`
14+
for activity types: `EmailFetcher`, `OpenLineFetcher`, `VoximplantFetcher`, `WebFormFetcher`
1115
* add in scope «Main» new service `Events` [add incoming events support](https://github.com/mesilov/bitrix24-php-sdk/issues/296)
1216
* add support Application level events: `ONAPPINSTALL`
1317
and `ONAPPUNINSTALL` [add incoming events support](https://github.com/mesilov/bitrix24-php-sdk/issues/296)
1418
* add support Application level event: `PortalDomainUrlChangedEvent`
1519
* add method `Core\Batch::updateEntityItems` for [update items in batch mode](https://github.com/mesilov/bitrix24-php-sdk/issues/268) and
1620
integration test
1721
* add method to interface `Core\Contracts\BatchInterface::updateEntityItems` for update items in batch mode
18-
* add in scope `CRM` for entity Deal method `Services\CRM\Deal\Service\Batch::update` batch update deals
19-
* add in scope `CRM` for entity Contact method `Services\CRM\Contact\Service\Batch::delete` batch delete contacts
2022
* add in scope `Placements` service `Placement\Service\UserFieldType` for work with user fields embedding
2123
* add `ApplicationStatus` with application status codes description
2224
* add fabric method `AccessToken::initFromPlacementRequest` when application init form placement request
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Activity;
6+
7+
use Bitrix24\SDK\Services\AbstractServiceBuilder;
8+
use Bitrix24\SDK\Services\CRM\Contact;
9+
use Bitrix24\SDK\Services\CRM\Deal;
10+
use Bitrix24\SDK\Services\CRM\Product;
11+
use Bitrix24\SDK\Services\CRM\Settings;
12+
use Bitrix24\SDK\Services\CRM\Activity;
13+
14+
class ActivityFetcherBuilder extends AbstractServiceBuilder
15+
{
16+
/**
17+
* @return \Bitrix24\SDK\Services\CRM\Activity\ReadModel\EmailFetcher
18+
*/
19+
public function emailFetcher(): Activity\ReadModel\EmailFetcher
20+
{
21+
if (!isset($this->serviceCache[__METHOD__])) {
22+
$this->serviceCache[__METHOD__] = new Activity\ReadModel\EmailFetcher($this->bulkItemsReader);
23+
}
24+
25+
return $this->serviceCache[__METHOD__];
26+
}
27+
28+
/**
29+
* @return \Bitrix24\SDK\Services\CRM\Activity\ReadModel\OpenLineFetcher
30+
*/
31+
public function openLineFetcher(): Activity\ReadModel\OpenLineFetcher
32+
{
33+
if (!isset($this->serviceCache[__METHOD__])) {
34+
$this->serviceCache[__METHOD__] = new Activity\ReadModel\OpenLineFetcher($this->bulkItemsReader);
35+
}
36+
37+
return $this->serviceCache[__METHOD__];
38+
}
39+
40+
/**
41+
* @return \Bitrix24\SDK\Services\CRM\Activity\ReadModel\VoximplantFetcher
42+
*/
43+
public function voximplantFetcher(): Activity\ReadModel\VoximplantFetcher
44+
{
45+
if (!isset($this->serviceCache[__METHOD__])) {
46+
$this->serviceCache[__METHOD__] = new Activity\ReadModel\VoximplantFetcher($this->bulkItemsReader);
47+
}
48+
49+
return $this->serviceCache[__METHOD__];
50+
}
51+
52+
/**
53+
* @return \Bitrix24\SDK\Services\CRM\Activity\ReadModel\WebFormFetcher
54+
*/
55+
public function webFormFetcher(): Activity\ReadModel\WebFormFetcher
56+
{
57+
if (!isset($this->serviceCache[__METHOD__])) {
58+
$this->serviceCache[__METHOD__] = new Activity\ReadModel\WebFormFetcher($this->bulkItemsReader);
59+
}
60+
61+
return $this->serviceCache[__METHOD__];
62+
}
63+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
4+
declare(strict_types=1);
5+
6+
namespace Bitrix24\SDK\Services\CRM\Activity\ReadModel;
7+
8+
use Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface;
9+
use Bitrix24\SDK\Services\CRM\Activity\Result\Email\EmailActivityItemResult;
10+
use Generator;
11+
12+
class EmailFetcher
13+
{
14+
private BulkItemsReaderInterface $bulkItemsReader;
15+
16+
/**
17+
* @param \Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface $bulkItemsReader
18+
*/
19+
public function __construct(BulkItemsReaderInterface $bulkItemsReader)
20+
{
21+
$this->bulkItemsReader = $bulkItemsReader;
22+
}
23+
24+
/**
25+
* @param array $order
26+
* @param array $filter
27+
* @param array $select
28+
* @param int|null $limit
29+
*
30+
* @return EmailActivityItemResult[]|Generator
31+
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
32+
*/
33+
public function getList(array $order, array $filter, array $select, ?int $limit = null): Generator
34+
{
35+
$filter = array_merge($filter, [
36+
'PROVIDER_ID' => 'CRM_EMAIL',
37+
'PROVIDER_TYPE_ID' => 'EMAIL',
38+
]);
39+
40+
foreach ($this->bulkItemsReader->getTraversableList('crm.activity.list', $order, $filter, $select, $limit) as $cnt => $item) {
41+
yield $cnt => new EmailActivityItemResult($item);
42+
}
43+
}
44+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
4+
declare(strict_types=1);
5+
6+
namespace Bitrix24\SDK\Services\CRM\Activity\ReadModel;
7+
8+
use Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface;
9+
use Bitrix24\SDK\Services\CRM\Activity\Result\OpenLine\OpenLineActivityItemResult;
10+
use Generator;
11+
12+
class OpenLineFetcher
13+
{
14+
private BulkItemsReaderInterface $bulkItemsReader;
15+
16+
/**
17+
* @param \Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface $bulkItemsReader
18+
*/
19+
public function __construct(BulkItemsReaderInterface $bulkItemsReader)
20+
{
21+
$this->bulkItemsReader = $bulkItemsReader;
22+
}
23+
24+
/**
25+
* @param array $order
26+
* @param array $filter
27+
* @param array $select
28+
* @param int|null $openLineTypeId
29+
* @param int|null $limit
30+
*
31+
* @return OpenLineActivityItemResult[]|Generator
32+
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
33+
*/
34+
public function getList(array $order, array $filter, array $select, ?int $openLineTypeId = null, ?int $limit = null): Generator
35+
{
36+
if ($openLineTypeId !== null) {
37+
$filter = array_merge($filter, [
38+
'PROVIDER_ID' => 'IMOPENLINES_SESSION',
39+
'PROVIDER_TYPE_ID' => $openLineTypeId,
40+
]);
41+
} else {
42+
$filter = array_merge($filter, ['PROVIDER_ID' => 'IMOPENLINES_SESSION']);
43+
}
44+
45+
foreach ($this->bulkItemsReader->getTraversableList('crm.activity.list', $order, $filter, $select, $limit) as $cnt => $item) {
46+
yield $cnt => new OpenLineActivityItemResult($item);
47+
}
48+
}
49+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
4+
declare(strict_types=1);
5+
6+
namespace Bitrix24\SDK\Services\CRM\Activity\ReadModel;
7+
8+
use Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface;
9+
use Bitrix24\SDK\Services\CRM\Activity\Result\ActivityItemResult;
10+
use Generator;
11+
12+
class VoximplantFetcher
13+
{
14+
private BulkItemsReaderInterface $bulkItemsReader;
15+
16+
/**
17+
* @param \Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface $bulkItemsReader
18+
*/
19+
public function __construct(BulkItemsReaderInterface $bulkItemsReader)
20+
{
21+
$this->bulkItemsReader = $bulkItemsReader;
22+
}
23+
24+
/**
25+
* @param array $order
26+
* @param array $filter
27+
* @param array $select
28+
* @param int|null $limit
29+
*
30+
* @return \Bitrix24\SDK\Services\CRM\Activity\Result\ActivityItemResult[]|Generator
31+
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
32+
*/
33+
public function getList(array $order, array $filter, array $select, ?int $limit = null): Generator
34+
{
35+
$filter = array_merge($filter, [
36+
'PROVIDER_ID' => 'VOXIMPLANT_CALL',
37+
'PROVIDER_TYPE_ID' => 'CALL',
38+
]);
39+
40+
foreach ($this->bulkItemsReader->getTraversableList('crm.activity.list', $order, $filter, $select, $limit) as $cnt => $item) {
41+
yield $cnt => new ActivityItemResult($item);
42+
}
43+
}
44+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
4+
declare(strict_types=1);
5+
6+
namespace Bitrix24\SDK\Services\CRM\Activity\ReadModel;
7+
8+
use Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface;
9+
use Bitrix24\SDK\Services\CRM\Activity\Result\WebForm\WebFormActivityItemResult;
10+
use Generator;
11+
12+
class WebFormFetcher
13+
{
14+
private BulkItemsReaderInterface $bulkItemsReader;
15+
16+
/**
17+
* @param \Bitrix24\SDK\Core\Contracts\BulkItemsReaderInterface $bulkItemsReader
18+
*/
19+
public function __construct(BulkItemsReaderInterface $bulkItemsReader)
20+
{
21+
$this->bulkItemsReader = $bulkItemsReader;
22+
}
23+
24+
/**
25+
* @param array $order
26+
* @param array $filter
27+
* @param array $select
28+
* @param int|null $webFormId
29+
* @param int|null $limit
30+
*
31+
* @return WebFormActivityItemResult[]|Generator
32+
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
33+
*/
34+
public function getList(array $order, array $filter, array $select, ?int $webFormId = null, ?int $limit = null): Generator
35+
{
36+
if ($webFormId !== null) {
37+
$filter = array_merge($filter, [
38+
'PROVIDER_ID' => 'CRM_WEBFORM',
39+
'PROVIDER_TYPE_ID' => $webFormId,
40+
]);
41+
} else {
42+
$filter = array_merge($filter, ['PROVIDER_ID' => 'CRM_WEBFORM']);
43+
}
44+
foreach ($this->bulkItemsReader->getTraversableList('crm.activity.list', $order, $filter, $select, $limit) as $cnt => $item) {
45+
yield $cnt => new WebFormActivityItemResult($item);
46+
}
47+
}
48+
}

src/Services/CRM/Activity/Result/ActivityItemResult.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,22 @@
3636
* @property-read string $AUTHOR_ID // Activity author ID
3737
* @property-read string $LAST_UPDATED // Date of the last update date
3838
* @property-read string $EDITOR_ID // Editor
39-
* @property-read string $SETTINGS
39+
* @property-read array $SETTINGS
4040
* @property-read string $ORIGIN_ID
4141
* @property-read string $ORIGINATOR_ID
4242
* @property-read int $RESULT_STATUS
4343
* @property-read int $RESULT_STREAM
4444
* @property-read string $RESULT_SOURCE_ID
45-
* @property-read string $PROVIDER_PARAMS
45+
* @property-read array $PROVIDER_PARAMS
4646
* @property-read string $PROVIDER_DATA
4747
* @property-read int $RESULT_MARK
4848
* @property-read string $RESULT_VALUE
4949
* @property-read string $RESULT_SUM
5050
* @property-read string $RESULT_CURRENCY_ID
5151
* @property-read int $AUTOCOMPLETE_RULE // Autocompletion
5252
* @property-read string $BINDINGS // Bindings
53-
* @property-read string $COMMUNICATIONS // type crm_activity_communication
54-
* @property-read string $FILES // Added files with diskfile type
53+
* @property-read array $COMMUNICATIONS // type crm_activity_communication
54+
* @property-read array $FILES // Added files with diskfile type
5555
* @property-read string $WEBDAV_ELEMENTS
5656
*/
5757
class ActivityItemResult extends AbstractCrmItem
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Activity\Result\Email;
6+
7+
use Bitrix24\SDK\Services\CRM\Activity\Result\ActivityItemResult;
8+
9+
/**
10+
* @property-read \Bitrix24\SDK\Services\CRM\Activity\Result\Email\EmailSettings $SETTINGS
11+
*/
12+
class EmailActivityItemResult extends ActivityItemResult
13+
{
14+
public function __get($offset)
15+
{
16+
if ($offset === 'SETTINGS') {
17+
return new EmailSettings($this->data[$offset]);
18+
}
19+
20+
return parent::__get($offset);
21+
}
22+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Activity\Result\Email;
6+
7+
use Bitrix24\SDK\Core\Result\AbstractItem;
8+
9+
/**
10+
* @property-read string $__email
11+
* @property-read string $from
12+
* @property-read string $replyTo
13+
* @property-read string $to
14+
* @property-read string $cc
15+
* @property-read string $bcc
16+
*/
17+
class EmailMeta extends AbstractItem
18+
{
19+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Activity\Result\Email;
6+
7+
use Bitrix24\SDK\Core\Result\AbstractItem;
8+
9+
/**
10+
* @property-read bool|null $IS_BATCH_EMAIL
11+
* @property-read array|null $MESSAGE_HEADERS
12+
* @property-read EmailMeta|null $EMAIL_META
13+
*/
14+
class EmailSettings extends AbstractItem
15+
{
16+
public function __get($offset)
17+
{
18+
if ($offset === 'EMAIL_META') {
19+
if (array_key_exists($offset, $this->data)) {
20+
return new EmailMeta($this->data[$offset]);
21+
}
22+
23+
return null;
24+
}
25+
26+
return parent::__get($offset);
27+
}
28+
}

0 commit comments

Comments
 (0)