Skip to content

Commit 78e24b5

Browse files
authored
Merge pull request #154 from Info-Expert-B24/feature/153-add-contact-detail-configuration
Feature/153 add contact detail configuration
2 parents 12abb53 + 539ea99 commit 78e24b5

File tree

9 files changed

+366
-2
lines changed

9 files changed

+366
-2
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/Contact/')
910
->in(__DIR__ . '/src/Services/CRM/Quote/')
1011
->in(__DIR__ . '/src/Services/CRM/Lead/')
1112
->in(__DIR__ . '/src/Services/CRM/Currency/')

CHANGELOG.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ work in progress
106106

107107
### Added
108108

109+
- Added service `CRM\Contact\Service\ContactDetailsConfiguration` with support methods,
110+
see [add crm.contact.details.* methods](https://github.com/bitrix24/b24phpsdk/issues/153):
111+
- `getPersonal` method retrieves the settings of contact cards for personal user
112+
- `getGeneral` method retrieves the settings of contact cards for all users
113+
- `resetPersonal` method reset for item user settings
114+
- `resetGeneral` method reset all card settings for all users
115+
- `setPersonal` method set card configuration
116+
- `setGeneral` method set card configuration for all users
117+
- `setForceCommonConfigForAll` method set common detail form for All Users
109118
- Added **PHP 8.4** [support](https://github.com/bitrix24/b24phpsdk/issues/120) 🚀
110119
- Added method `Bitrix24\SDK\Services\Main\Service::guardValidateCurrentAuthToken` for validate current auth token with
111120
api-call `app.info` on vendor OAUTH server.
@@ -485,4 +494,4 @@ Supported in bitrix24-php-sdk methods with batch wrapper count: 22
485494

486495
## 1.0
487496

488-
* Initial release
497+
* Initial release

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ test-integration-scope-entity:
179179
test-integration-scope-ai-admin:
180180
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_ai_admin
181181

182+
.PHONY: integration_tests_scope_crm_contact_details
183+
integration_tests_scope_crm_contact_details:
184+
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_crm_contact_details
185+
182186
.PHONY: integration_tests_lead_userfield
183187
integration_tests_lead_userfield:
184188
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_lead_userfield

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/Contact/Service/ContactDetailsConfigurationTest.php
1415
- tests/Integration/Services/CRM/Lead/Service/LeadProductRowsTest.php
1516
- tests/Integration/Services/CRM/Quote/Service/QuoteTest.php
1617
- tests/Integration/Services/CRM/Quote/Service/BatchTest.php

phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@
4343
<testsuite name="integration_tests_scope_ai_admin">
4444
<directory>./tests/Integration/Services/AI/</directory>
4545
</testsuite>
46+
<testsuite name="integration_tests_scope_crm_contact_details">
47+
<file>./tests/Integration/Services/CRM/Contact/Service/ContactDetailsConfigurationTest.php</file>
48+
</testsuite>
4649
<testsuite name="integration_tests_lead_productrows">
4750
<file>./tests/Integration/Services/CRM/Lead/Service/LeadProductRowsTest.php</file>
4851
</testsuite>

rector.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
__DIR__ . '/tests/Integration/Services/Main',
3737
__DIR__ . '/src/Services/Placement',
3838
__DIR__ . '/tests/Integration/Services/Placement',
39+
__DIR__ . '/src/Services/CRM/Contact/Service/ContactDetailsConfiguration.php',
40+
__DIR__ . '/tests/Integration/Services/CRM/Contact/Service/ContactDetailsConfigurationTest.php',
3941
__DIR__ . '/src/Services/CRM/Lead',
4042
__DIR__ . '/tests/Integration/Services/CRM/Lead/Service',
4143
__DIR__ . '/src/Services/CRM/Quote',

src/Services/CRM/CRMServiceBuilder.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,18 @@ public function companyDetailsConfiguration(): Company\Service\CompanyDetailsCon
7171

7272
return $this->serviceCache[__METHOD__];
7373
}
74+
75+
public function contactDetailsConfiguration(): Contact\Service\ContactDetailsConfiguration
76+
{
77+
if (!isset($this->serviceCache[__METHOD__])) {
78+
$this->serviceCache[__METHOD__] = new Contact\Service\ContactDetailsConfiguration(
79+
$this->core,
80+
$this->log
81+
);
82+
}
83+
84+
return $this->serviceCache[__METHOD__];
85+
}
7486

7587
public function vat(): VatRates\Service\Vat
7688
{
@@ -455,4 +467,4 @@ public function duplicate(): Duplicates\Service\Duplicate
455467

456468
return $this->serviceCache[__METHOD__];
457469
}
458-
}
470+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
<?php
2+
3+
/**
4+
* This file is part of the bitrix24-php-sdk package.
5+
*
6+
* © Vadim Soluyanov <[email protected]>
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\Contact\Service;
15+
16+
use Bitrix24\SDK\Attributes\ApiEndpointMetadata;
17+
use Bitrix24\SDK\Attributes\ApiServiceMetadata;
18+
use Bitrix24\SDK\Core\Credentials\Scope;
19+
use Bitrix24\SDK\Core\Exceptions\InvalidArgumentException;
20+
use Bitrix24\SDK\Core\Result\UpdatedItemResult;
21+
use Bitrix24\SDK\Services\AbstractService;
22+
use Bitrix24\SDK\Services\CRM\Common\CardFieldConfiguration;
23+
use Bitrix24\SDK\Services\CRM\Common\CardSectionConfiguration;
24+
use Bitrix24\SDK\Services\CRM\Common\Result\ElementCardConfiguration\CardConfigurationsResult;
25+
26+
#[ApiServiceMetadata(new Scope(['crm']))]
27+
class ContactDetailsConfiguration extends AbstractService
28+
{
29+
/**
30+
* The method retrieves the settings of contact cards for personal user.
31+
*
32+
* @param non-negative-int|null $userId
33+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-get.html
34+
*/
35+
#[ApiEndpointMetadata(
36+
'crm.contact.details.configuration.get',
37+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-get.html',
38+
'The method crm.contact.details.configuration.get retrieves the settings of contact cards for personal user'
39+
)]
40+
public function getPersonal(?int $userId = null): CardConfigurationsResult
41+
{
42+
return new CardConfigurationsResult($this->core->call('crm.contact.details.configuration.get', [
43+
'scope' => 'P',
44+
'userId' => $userId
45+
]));
46+
}
47+
48+
/**
49+
* The method retrieves the settings of contact cards for all users.
50+
*
51+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-get.html
52+
*/
53+
#[ApiEndpointMetadata(
54+
'crm.contact.details.configuration.get',
55+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-get.html',
56+
'The method crm.contact.details.configuration.get retrieves the settings of contact cards for all users'
57+
)]
58+
public function getGeneral(): CardConfigurationsResult
59+
{
60+
return new CardConfigurationsResult($this->core->call('crm.contact.details.configuration.get', [
61+
'scope' => 'C',
62+
]));
63+
}
64+
65+
/**
66+
* The method resets the settings of contact cards for personal user.
67+
*
68+
* @param non-negative-int|null $userId
69+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-reset.html
70+
*/
71+
#[ApiEndpointMetadata(
72+
'crm.contact.details.configuration.reset',
73+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-reset.html',
74+
'The method crm.contact.details.configuration.reset resets the settings of contact cards for personal user'
75+
)]
76+
public function resetPersonal(?int $userId = null): UpdatedItemResult
77+
{
78+
return new UpdatedItemResult($this->core->call('crm.contact.details.configuration.reset', [
79+
'scope' => 'P',
80+
'userId' => $userId
81+
]));
82+
}
83+
84+
/**
85+
* The method resets the settings of contact cards for all users.
86+
*
87+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-reset.html
88+
*/
89+
#[ApiEndpointMetadata(
90+
'crm.contact.details.configuration.reset',
91+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-reset.html',
92+
'The method crm.contact.details.configuration.reset resets the settings of contact cards for all users'
93+
)]
94+
public function resetGeneral(): UpdatedItemResult
95+
{
96+
return new UpdatedItemResult($this->core->call('crm.contact.details.configuration.reset', [
97+
'scope' => 'C',
98+
]));
99+
}
100+
101+
/**
102+
* Set Parameters for Individual CRM Contact Detail Card Configuration
103+
* @param CardSectionConfiguration[] $cardConfiguration
104+
* @throws InvalidArgumentException
105+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-set.html
106+
*/
107+
#[ApiEndpointMetadata(
108+
'crm.contact.details.configuration.set',
109+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-set.html',
110+
'Set Parameters for Individual CRM Contact Detail Card Configuration'
111+
)]
112+
public function setPersonal(array $cardConfiguration, ?int $userId = null): UpdatedItemResult
113+
{
114+
$rawData = [];
115+
foreach ($cardConfiguration as $sectionItem) {
116+
if (!$sectionItem instanceof CardSectionConfiguration) {
117+
throw new InvalidArgumentException(
118+
sprintf(
119+
'card configuration section mus be «%s» type, current type «%s»',
120+
CardFieldConfiguration::class,
121+
gettype($sectionItem)
122+
)
123+
);
124+
}
125+
126+
$rawData[] = $sectionItem->toArray();
127+
}
128+
129+
return new UpdatedItemResult($this->core->call('crm.contact.details.configuration.set', [
130+
'scope' => 'P',
131+
'userId' => $userId,
132+
'data' => $rawData
133+
]));
134+
}
135+
136+
/**
137+
* Set Parameters of CRM Contact Detail Card Configuration for all users
138+
* @param CardSectionConfiguration[] $cardConfiguration
139+
* @throws InvalidArgumentException
140+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-set.html
141+
*/
142+
#[ApiEndpointMetadata(
143+
'crm.contact.details.configuration.set',
144+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-set.html',
145+
'Set Parameters of CRM Contact Detail Card Configuration for all users'
146+
)]
147+
public function setGeneral(array $cardConfiguration): UpdatedItemResult
148+
{
149+
$rawData = [];
150+
foreach ($cardConfiguration as $sectionItem) {
151+
if (!$sectionItem instanceof CardSectionConfiguration) {
152+
throw new InvalidArgumentException(
153+
sprintf(
154+
'card configuration section mus be «%s» type, current type «%s»',
155+
CardFieldConfiguration::class,
156+
gettype($sectionItem)
157+
)
158+
);
159+
}
160+
161+
$rawData[] = $sectionItem->toArray();
162+
}
163+
164+
return new UpdatedItemResult($this->core->call('crm.contact.details.configuration.set', [
165+
'scope' => 'C',
166+
'data' => $rawData
167+
]));
168+
}
169+
170+
/**
171+
* Set Common Detail Form for All Users
172+
* @throws InvalidArgumentException
173+
* @link https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-force-common-scope-for-all.html
174+
*/
175+
#[ApiEndpointMetadata(
176+
'crm.contact.details.configuration.forceCommonScopeForAll',
177+
'https://apidocs.bitrix24.com/api-reference/crm/contacts/custom-form/crm-contact-details-configuration-force-common-scope-for-all.html',
178+
'Set Common Detail Form for All Users '
179+
)]
180+
public function setForceCommonConfigForAll(): UpdatedItemResult
181+
{
182+
return new UpdatedItemResult($this->core->call('crm.contact.details.configuration.forceCommonScopeForAll'));
183+
}
184+
}

0 commit comments

Comments
 (0)