Skip to content

Commit 159a7b5

Browse files
authored
Merge pull request #139 from Info-Expert-B24/feature/138-add-crm-address
Feature/138 add crm address
2 parents 9507ba6 + 2e1ab24 commit 159a7b5

39 files changed

+1275
-288
lines changed

.php-cs-fixer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
$finder = Finder::create()
88
->in(__DIR__ . '/src/Infrastructure/Console/Commands/')
9+
->in(__DIR__ . '/src/Services/CRM/Address/')
910
->in(__DIR__ . '/src/Services/CRM/Item/Service/')
1011
->in(__DIR__ . '/src/Services/CRM/Contact/')
1112
->in(__DIR__ . '/src/Services/CRM/Quote/')

CHANGELOG.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,13 @@
112112
- `get` get localizations
113113
- `fields` get localization fields
114114
- `delete` delete currency, with batch calls support
115+
- Added service `Services\CRM\Address\Service\Address` with support methods,
116+
see [add crm.address REST methods](https://github.com/bitrix24/b24phpsdk/issues/138):
117+
- `list` get item list
118+
- `add` add new item, with batch calls support
119+
- `delete` delete item, with batch calls support
120+
- `update` update item, with batch calls support
121+
- Added enum `Services\CRM\Enum\OwnerType`
115122
- Developer experience: added make command `lint-all` for run all code linters step by step, [see details](https://github.com/bitrix24/b24phpsdk/issues/183)
116123

117124
### Fixed
@@ -173,8 +180,8 @@ work in progress
173180
see [fix entity.item.* methods](https://github.com/bitrix24/b24phpsdk/issues/53):
174181
- `get` get item, with batch calls support
175182
- `add` add new item, with batch calls support
176-
- `delete` delete item, with batch calls support
177-
- `update` update item, with batch calls support
183+
- `delete` delete item
184+
- `update` update item
178185
- Added service `Services\Entity\Service\Entity` with support methods,
179186
see [fix entity.* methods](https://github.com/bitrix24/b24phpsdk/issues/53):
180187
- `get` get entity

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,14 @@ test-integration-scope-entity:
182182
.PHONY: test-integration-scope-ai-admin
183183
test-integration-scope-ai-admin:
184184
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_ai_admin
185+
186+
.PHONY: test-integration-scope-crm
187+
test-integration-scope-crm:
188+
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm
189+
190+
.PHONY: integration_tests_scope_crm_address
191+
integration_tests_scope_crm_address:
192+
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm_address
185193

186194
.PHONY: integration_tests_scope_crm_deal_details
187195
integration_tests_scope_crm_deal_details:

phpstan.neon.dist

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ parameters:
1111
- tests/Integration/Services/IMOpenLines
1212
- tests/Integration/Services/Main
1313
- tests/Integration/Services/Placement
14+
- tests/Integration/Services/CRM/Address
1415
- tests/Integration/Services/CRM/Deal/Service/DealRecurringTest.php
1516
- tests/Integration/Services/CRM/Lead/Service/LeadContactTest.php
1617
- tests/Integration/Services/CRM/Item/Service/ItemDetailsConfigurationTest.php

phpunit.xml.dist

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,12 @@
4343
<testsuite name="integration_tests_scope_ai_admin">
4444
<directory>./tests/Integration/Services/AI/</directory>
4545
</testsuite>
46+
<testsuite name="integration_tests_scope_crm">
47+
<directory>./tests/Integration/Services/CRM/</directory>
48+
</testsuite>
49+
<testsuite name="integration_tests_scope_crm_address">
50+
<directory>./tests/Integration/Services/CRM/Address/</directory>
51+
</testsuite>
4652
<testsuite name="integration_tests_scope_crm_deal_details">
4753
<file>./tests/Integration/Services/CRM/Deal/Service/DealDetailsConfigurationTest.php</file>
4854
</testsuite>

rector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
__DIR__ . '/tests/Integration/Services/IM',
3131
__DIR__ . '/src/Services/IMOpenLines',
3232
__DIR__ . '/tests/Integration/Services/IMOpenLines',
33-
__DIR__ . '/src/Services/CRM/Automation',
34-
__DIR__ . '/tests/Integration/Services/CRM/Automation',
33+
__DIR__ . '/src/Services/CRM/Address',
34+
__DIR__ . '/tests/Integration/Services/CRM/Address',
3535
__DIR__ . '/src/Services/Main',
3636
__DIR__ . '/tests/Integration/Services/Main',
3737
__DIR__ . '/src/Services/Placement',

src/Core/Batch.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,13 @@ public function deleteEntityItems(
125125
'additionalParameters' => $additionalParameters,
126126
]
127127
);
128+
129+
$useFieldsInsteadOfId = $apiMethod === 'crm.address.delete';
128130

129131
try {
130132
$this->clearCommands();
131133
foreach ($entityItemId as $cnt => $itemId) {
132-
if (!is_int($itemId)) {
134+
if (!$useFieldsInsteadOfId && !is_int($itemId)) {
133135
throw new InvalidArgumentException(
134136
sprintf(
135137
'invalid type «%s» of entity id «%s» at position %s, entity id must be integer type',
@@ -140,7 +142,8 @@ public function deleteEntityItems(
140142
);
141143
}
142144

143-
$parameters = ['ID' => $itemId];
145+
$parameters = $useFieldsInsteadOfId ? ['fields' => $itemId] : ['ID' => $itemId];
146+
// TODO: delete after migration to RestAPI v2
144147
if ($apiMethod === 'entity.item.delete') {
145148
$parameters = array_merge($parameters, $additionalParameters);
146149
}
@@ -201,8 +204,11 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera
201204

202205
try {
203206
$this->clearCommands();
207+
208+
$useFieldsInsteadOfId = $apiMethod === 'crm.address.update';
209+
204210
foreach ($entityItems as $entityItemId => $entityItem) {
205-
if (!is_int($entityItemId)) {
211+
if (!$useFieldsInsteadOfId && !is_int($entityItemId)) {
206212
throw new InvalidArgumentException(
207213
sprintf(
208214
'invalid type «%s» of entity id «%s», entity id must be integer type',
@@ -219,10 +225,17 @@ public function updateEntityItems(string $apiMethod, array $entityItems): Genera
219225
);
220226
}
221227

222-
$cmdArguments = [
223-
'id' => $entityItemId,
224-
'fields' => $entityItem['fields']
225-
];
228+
if ($useFieldsInsteadOfId) {
229+
$cmdArguments = [
230+
'fields' => $entityItem['fields']
231+
];
232+
} else {
233+
$cmdArguments = [
234+
'id' => $entityItemId,
235+
'fields' => $entityItem['fields']
236+
];
237+
}
238+
226239
if (array_key_exists('params', $entityItem)) {
227240
$cmdArguments['params'] = $entityItem['params'];
228241
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Vadim Soluyanov <vadimsallee@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace Bitrix24\SDK\Services\CRM\Address\Result;
15+
16+
use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem;
17+
18+
/**
19+
* Class AddressItemResult
20+
*
21+
* @property-read int $TYPE_ID
22+
* @property-read int $ENTITY_TYPE_ID
23+
* @property-read int $ENTITY_ID
24+
* @property-read string|null $ADDRESS_1
25+
* @property-read string|null $ADDRESS_2
26+
* @property-read string|null $CITY
27+
* @property-read string|null $POSTAL_CODE
28+
* @property-read string|null $REGION
29+
* @property-read string|null $PROVINCE
30+
* @property-read string|null $COUNTRY
31+
* @property-read string|null $COUNTRY_CODE
32+
* @property-read int|null $LOC_ADDR_ID
33+
* @property-read int|null $ANCHOR_TYPE_ID
34+
* @property-read int|null $ANCHOR_ID
35+
*/
36+
class AddressItemResult extends AbstractCrmItem
37+
{
38+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Vadim Soluyanov <vadimsallee@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
13+
declare(strict_types=1);
14+
15+
namespace Bitrix24\SDK\Services\CRM\Address\Result;
16+
17+
use Bitrix24\SDK\Core\Result\AbstractResult;
18+
19+
/**
20+
* Class AddressResult
21+
*
22+
* @package Bitrix24\SDK\Services\CRM\Address\Result
23+
*/
24+
class AddressResult extends AbstractResult
25+
{
26+
/**
27+
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
28+
*/
29+
public function address(): AddressItemResult
30+
{
31+
return new AddressItemResult($this->getCoreResponse()->getResponseData()->getResult());
32+
}
33+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Vadim Soluyanov <vadimsallee@gmail.com>
7+
*
8+
* For the full copyright and license information, please view the MIT-LICENSE.txt
9+
* file that was distributed with this source code.
10+
*/
11+
12+
13+
declare(strict_types=1);
14+
15+
namespace Bitrix24\SDK\Services\CRM\Address\Result;
16+
17+
use Bitrix24\SDK\Core\Exceptions\BaseException;
18+
use Bitrix24\SDK\Core\Result\AbstractResult;
19+
20+
/**
21+
* Class AddressesResult
22+
*
23+
* @package Bitrix24\SDK\Services\CRM\Address\Result
24+
*/
25+
class AddressesResult extends AbstractResult
26+
{
27+
/**
28+
* @return AddressItemResult[]
29+
* @throws BaseException
30+
*/
31+
public function getAddresses(): array
32+
{
33+
$items = [];
34+
foreach ($this->getCoreResponse()->getResponseData()->getResult() as $item) {
35+
$items[] = new AddressItemResult($item);
36+
}
37+
38+
return $items;
39+
}
40+
}

0 commit comments

Comments
 (0)