Skip to content

Commit 68c7a34

Browse files
authored
Merge pull request #174 from Info-Expert-B24/feature/172-add-lead-detailes
Feature/172 add lead detailes
2 parents 78e24b5 + 721b09c commit 68c7a34

File tree

8 files changed

+387
-2
lines changed

8 files changed

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

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44

55
### Added
66

7+
- Added service `CRM\Lead\Service\LeadDetailsConfiguration` with support methods,
8+
see [add crm.lead.details.* methods](https://github.com/bitrix24/b24phpsdk/issues/172):
9+
- `getPersonal` method retrieves the settings of lead cards for personal user
10+
- `getGeneral` method retrieves the settings of lead cards for all users
11+
- `resetPersonal` method reset for item user settings
12+
- `resetGeneral` method reset all card settings for all users
13+
- `setPersonal` method set card configuration
14+
- `setGeneral` method set card configuration for all users
15+
- `setForceCommonConfigForAll` method set common detail form for All Users
716
- Added service `Services\CRM\Lead\Service\LeadProductRows` with support methods,
817
see [add crm.lead.productrows* methods](https://github.com/bitrix24/b24phpsdk/issues/175):
918
- `set` Adds products to a lead

Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,10 @@ integration_tests_scope_crm_currency:
199199
integration_tests_deal_recurring:
200200
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_deal_recurring
201201

202+
.PHONY: integration_tests_lead_details
203+
integration_tests_lead_details:
204+
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_lead_details
205+
202206
.PHONY: integration_tests_scope_automation
203207
integration_tests_scope_automation:
204208
docker-compose run --rm php-cli vendor/bin/phpunit --testsuite integration_tests_scope_automation

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

phpunit.xml.dist

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@
6161
<testsuite name="integration_tests_deal_recurring">
6262
<file>./tests/Integration/Services/CRM/Deal/Service/DealRecurringTest.php</file>
6363
</testsuite>
64-
<testsuite name="integration_tests_scope_automation">
65-
<directory>./tests/Integration/Services/CRM/Automation/</directory>
64+
<testsuite name="integration_tests_lead_details">
65+
<file>./tests/Integration/Services/CRM/Lead/Service/LeadDetailsConfigurationTest.php</file>
6666
</testsuite>
6767
<testsuite name="integration_tests_crm_quote">
6868
<directory>./tests/Integration/Services/CRM/Quote/</directory>

src/Services/CRM/CRMServiceBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,18 @@ public function companyDetailsConfiguration(): Company\Service\CompanyDetailsCon
7272
return $this->serviceCache[__METHOD__];
7373
}
7474

75+
public function leadDetailsConfiguration(): Lead\Service\LeadDetailsConfiguration
76+
{
77+
if (!isset($this->serviceCache[__METHOD__])) {
78+
$this->serviceCache[__METHOD__] = new Lead\Service\LeadDetailsConfiguration(
79+
$this->core,
80+
$this->log
81+
);
82+
}
83+
84+
return $this->serviceCache[__METHOD__];
85+
}
86+
7587
public function contactDetailsConfiguration(): Contact\Service\ContactDetailsConfiguration
7688
{
7789
if (!isset($this->serviceCache[__METHOD__])) {
Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,201 @@
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\Lead\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 LeadDetailsConfiguration extends AbstractService
28+
{
29+
/**
30+
* The method retrieves the settings of lead cards for personal user.
31+
*
32+
* @param non-negative-int $userId
33+
* @param array $extras
34+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-get.html
35+
*/
36+
#[ApiEndpointMetadata(
37+
'crm.lead.details.configuration.get',
38+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-get.html',
39+
'The method crm.lead.details.configuration.get retrieves the settings of lead cards for personal user.'
40+
)]
41+
public function getPersonal(int $userId, ?array $extras = []): CardConfigurationsResult
42+
{
43+
return new CardConfigurationsResult($this->core->call('crm.lead.details.configuration.get', [
44+
'scope' => 'P',
45+
'userId' => $userId,
46+
'extras' => $extras
47+
]));
48+
}
49+
50+
/**
51+
* The method retrieves the settings of lead cards for all users.
52+
*
53+
* @param array $extras
54+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-get.html
55+
*/
56+
#[ApiEndpointMetadata(
57+
'crm.lead.details.configuration.get',
58+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-get.html',
59+
'The method crm.lead.details.configuration.get retrieves the settings of lead cards for all users.'
60+
)]
61+
public function getGeneral(?array $extras = []): CardConfigurationsResult
62+
{
63+
return new CardConfigurationsResult($this->core->call('crm.lead.details.configuration.get', [
64+
'scope' => 'C',
65+
'extras' => $extras
66+
]));
67+
}
68+
69+
/**
70+
* The method resets the settings of lead cards for personal user.
71+
*
72+
* @param non-negative-int $userId
73+
* @param array $extras
74+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-reset.html
75+
*/
76+
#[ApiEndpointMetadata(
77+
'crm.lead.details.configuration.reset',
78+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-reset.html',
79+
'The method crm.lead.details.configuration.get retrieves the settings of lead cards for personal user.'
80+
)]
81+
public function resetPersonal(int $userId, ?array $extras = []): UpdatedItemResult
82+
{
83+
return new UpdatedItemResult($this->core->call('crm.lead.details.configuration.reset', [
84+
'scope' => 'P',
85+
'userId' => $userId,
86+
'extras' => $extras
87+
]));
88+
}
89+
90+
/**
91+
* The method resets the settings of lead cards for all users.
92+
*
93+
* @param array $extras
94+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-reset.html
95+
*/
96+
#[ApiEndpointMetadata(
97+
'crm.lead.details.configuration.reset',
98+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-reset.html',
99+
'The method crm.lead.details.configuration.get retrieves the settings of lead cards for all users.'
100+
)]
101+
public function resetGeneral(?array $extras = []): UpdatedItemResult
102+
{
103+
return new UpdatedItemResult($this->core->call('crm.lead.details.configuration.reset', [
104+
'scope' => 'C',
105+
'extras' => $extras
106+
]));
107+
}
108+
109+
/**
110+
* Set Parameters for Individual CRM Lead Detail Card Configuration
111+
* @param CardSectionConfiguration[] $cardConfiguration
112+
* @param non-negative-int $userId
113+
* @param array $extras
114+
* @throws InvalidArgumentException
115+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-set.html
116+
*/
117+
#[ApiEndpointMetadata(
118+
'crm.lead.details.configuration.set',
119+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-set.html',
120+
'Set Parameters for Individual CRM Lead Detail Card Configuration.'
121+
)]
122+
public function setPersonal(array $cardConfiguration, int $userId, ?array $extras = []): UpdatedItemResult
123+
{
124+
$rawData = [];
125+
foreach ($cardConfiguration as $sectionItem) {
126+
if (!$sectionItem instanceof CardSectionConfiguration) {
127+
throw new InvalidArgumentException(
128+
sprintf(
129+
'card configuration section mus be «%s» type, current type «%s»',
130+
CardFieldConfiguration::class,
131+
gettype($sectionItem)
132+
)
133+
);
134+
}
135+
136+
$rawData[] = $sectionItem->toArray();
137+
}
138+
139+
return new UpdatedItemResult($this->core->call('crm.lead.details.configuration.set', [
140+
'scope' => 'P',
141+
'userId' => $userId,
142+
'data' => $rawData,
143+
'extras' => $extras
144+
]));
145+
}
146+
147+
/**
148+
* Set CRM Lead Detail Card Configuration for all users.
149+
* @param CardSectionConfiguration[] $cardConfiguration
150+
* @param array $extras
151+
* @throws InvalidArgumentException
152+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-set.html
153+
*/
154+
#[ApiEndpointMetadata(
155+
'crm.lead.details.configuration.set',
156+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-set.html',
157+
'Set CRM Lead Detail Card Configuration for all users.'
158+
)]
159+
public function setGeneral(array $cardConfiguration, ?array $extras = []): UpdatedItemResult
160+
{
161+
$rawData = [];
162+
foreach ($cardConfiguration as $sectionItem) {
163+
if (!$sectionItem instanceof CardSectionConfiguration) {
164+
throw new InvalidArgumentException(
165+
sprintf(
166+
'card configuration section mus be «%s» type, current type «%s»',
167+
CardFieldConfiguration::class,
168+
gettype($sectionItem)
169+
)
170+
);
171+
}
172+
173+
$rawData[] = $sectionItem->toArray();
174+
}
175+
176+
return new UpdatedItemResult($this->core->call('crm.lead.details.configuration.set', [
177+
'scope' => 'C',
178+
'data' => $rawData,
179+
'extras' => $extras
180+
]));
181+
}
182+
183+
/**
184+
* Set Common Detail Form for All Users
185+
*
186+
* @param array $extras
187+
* @throws InvalidArgumentException
188+
* @link https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-force-common-scope-for-all.html
189+
*/
190+
#[ApiEndpointMetadata(
191+
'crm.lead.details.configuration.forceCommonScopeForAll',
192+
'https://apidocs.bitrix24.com/api-reference/crm/leads/custom-form/crm-lead-details-configuration-force-common-scope-for-all.html',
193+
'Set Common Detail Form for All Users.'
194+
)]
195+
public function setForceCommonConfigForAll(?array $extras = []): UpdatedItemResult
196+
{
197+
return new UpdatedItemResult($this->core->call('crm.lead.details.configuration.forceCommonScopeForAll', [
198+
'extras' => $extras
199+
]));
200+
}
201+
}

0 commit comments

Comments
 (0)