Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.

Commit 83f11ca

Browse files
authored
Merge pull request #235 from mesilov/dev
Dev
2 parents 3e184fb + cf40ef9 commit 83f11ca

29 files changed

+1503
-94
lines changed

CHANGELOG.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
# bitrix24-php-sdk change log
22

3-
## 2.0-alpha.5 – 26.11.2021
3+
## 2.0-alpha.5 – 28.11.2021
44

55
### Added
66

77
* add method `countByFilter` for all related services, see
88
issue [Добавить для всех сущностей метод подсчёта количества элементов по фильтру #228](https://github.com/mesilov/bitrix24-php-sdk/issues/228)
9+
* add in scope «CRM» Userfield service and integration test
10+
* add in scope «CRM» ContactUserfield service and integration test, see
11+
issue [Добавить сервис по работе с юзерфилдами контакта #231](https://github.com/mesilov/bitrix24-php-sdk/issues/231)
12+
* add method getUserfieldByFieldName for `ContactItemResult`
13+
* add in scope «CRM» DealUserfield service and integration test, see
14+
issue [Добавить сервис по работе с юзерфилдами cделки #232](https://github.com/mesilov/bitrix24-php-sdk/issues/232)
15+
* add method getUserfieldByFieldName for `DealItemResult`
16+
* add exception `UserfieldNotFoundException`
917

1018
### Removed
1119

1220
* remove all `0.*` and `1.*` code from `2.*` branch
1321

22+
### Changed
23+
24+
* update type definition for `ContactItemResult`, now return types will be cast to real types: DateTimeInterface, int, boolean etc
25+
1426
## 2.0-alpha.4 – 25.11.2021
1527

1628
### Changed

src/Core/Credentials/Scope.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,12 @@ class Scope
1616
/**
1717
* @var string[]
1818
*/
19-
protected $availableScope = [
19+
protected array $availableScope = [
2020
'app',
2121
'bizproc',
2222
'calendar',
2323
'call',
24+
'catalog',
2425
'contact_center',
2526
'crm',
2627
'delivery',
@@ -60,7 +61,7 @@ class Scope
6061
/**
6162
* @var array
6263
*/
63-
protected $currentScope = [];
64+
protected array $currentScope = [];
6465

6566
/**
6667
* Scope constructor.

src/Core/Result/AbstractItem.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*/
1414
abstract class AbstractItem implements \IteratorAggregate
1515
{
16-
private array $data;
16+
protected array $data;
1717

1818
/**
1919
* AbstractItem constructor.
@@ -75,4 +75,14 @@ public function getIterator()
7575
{
7676
return new \ArrayIterator($this->data);
7777
}
78+
79+
/**
80+
* @param string $key
81+
*
82+
* @return bool
83+
*/
84+
protected function isKeyExists(string $key): bool
85+
{
86+
return array_key_exists($key, $this->data);
87+
}
7888
}

src/Services/CRM/CRMServiceBuilder.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,21 @@ public function deal(): Deal\Service\Deal
7070
return $this->serviceCache[__METHOD__];
7171
}
7272

73+
/**
74+
* @return \Bitrix24\SDK\Services\CRM\Deal\Service\DealUserfield
75+
*/
76+
public function dealUserfield(): Deal\Service\DealUserfield
77+
{
78+
if (!isset($this->serviceCache[__METHOD__])) {
79+
$this->serviceCache[__METHOD__] = new Deal\Service\DealUserfield(
80+
$this->core,
81+
$this->log
82+
);
83+
}
84+
85+
return $this->serviceCache[__METHOD__];
86+
}
87+
7388
/**
7489
* @return Contact\Service\Contact
7590
*/
@@ -86,6 +101,21 @@ public function contact(): Contact\Service\Contact
86101
return $this->serviceCache[__METHOD__];
87102
}
88103

104+
/**
105+
* @return \Bitrix24\SDK\Services\CRM\Contact\Service\ContactUserfield
106+
*/
107+
public function contactUserfield(): Contact\Service\ContactUserfield
108+
{
109+
if (!isset($this->serviceCache[__METHOD__])) {
110+
$this->serviceCache[__METHOD__] = new Contact\Service\ContactUserfield(
111+
$this->core,
112+
$this->log
113+
);
114+
}
115+
116+
return $this->serviceCache[__METHOD__];
117+
}
118+
89119
/**
90120
* @return Deal\Service\DealProductRows
91121
*/
@@ -125,4 +155,19 @@ public function product(): Product\Service\Product
125155

126156
return $this->serviceCache[__METHOD__];
127157
}
158+
159+
/**
160+
* @return Userfield\Service\Userfield
161+
*/
162+
public function userfield(): Userfield\Service\Userfield
163+
{
164+
if (!isset($this->serviceCache[__METHOD__])) {
165+
$this->serviceCache[__METHOD__] = new Userfield\Service\Userfield(
166+
$this->core,
167+
$this->log
168+
);
169+
}
170+
171+
return $this->serviceCache[__METHOD__];
172+
}
128173
}
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Common\Result;
6+
7+
use Bitrix24\SDK\Core\Result\AbstractItem;
8+
use Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException;
9+
use DateTimeImmutable;
10+
11+
class AbstractCrmItem extends AbstractItem
12+
{
13+
private const CRM_USERFIELD_PREFIX = 'UF_CRM_';
14+
15+
/**
16+
* @param int|string $offset
17+
*
18+
* @return bool|\DateTimeImmutable|int|mixed|null
19+
*/
20+
public function __get($offset)
21+
{
22+
// todo унести в отдельный класс и покрыть тестами
23+
// приведение полей к реальным типам данных для основных сущностей CRM
24+
switch ($offset) {
25+
case 'ID':
26+
case 'ASSIGNED_BY_ID':
27+
case 'CREATED_BY_ID':
28+
case 'MODIFY_BY_ID':
29+
// deal
30+
case 'LEAD_ID':
31+
case 'CONTACT_ID':
32+
case 'QUOTE_ID':
33+
if ($this->data[$offset] !== '' && $this->data[$offset] !== null) {
34+
return (int)$this->data[$offset];
35+
}
36+
37+
return null;
38+
case 'COMPANY_ID':
39+
if ($this->data[$offset] !== '' && $this->data[$offset] !== null && $this->data[$offset] !== '0') {
40+
return (int)$this->data[$offset];
41+
}
42+
43+
return null;
44+
45+
// contact
46+
case 'EXPORT':
47+
case 'HAS_PHONE':
48+
case 'HAS_EMAIL':
49+
case 'HAS_IMOL':
50+
case 'OPENED':
51+
// deal
52+
case 'IS_MANUAL_OPPORTUNITY':
53+
case 'CLOSED':
54+
case 'IS_NEW':
55+
case 'IS_RECURRING':
56+
case 'IS_RETURN_CUSTOMER':
57+
case 'IS_REPEATED_APPROACH':
58+
return $this->data[$offset] === 'Y';
59+
case 'DATE_CREATE':
60+
case 'DATE_MODIFY':
61+
case 'BIRTHDATE':
62+
case 'BEGINDATE':
63+
case 'CLOSEDATE':
64+
if ($this->data[$offset] !== '') {
65+
return DateTimeImmutable::createFromFormat(DATE_ATOM, $this->data[$offset]);
66+
}
67+
68+
return null;
69+
default:
70+
return $this->data[$offset] ?? null;
71+
}
72+
}
73+
74+
/**
75+
* get userfield by field name
76+
*
77+
* @param string $fieldName
78+
*
79+
* @return mixed|null
80+
* @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException
81+
*/
82+
protected function getKeyWithUserfieldByFieldName(string $fieldName)
83+
{
84+
$fieldName = self::CRM_USERFIELD_PREFIX . $fieldName;
85+
if (!$this->isKeyExists($fieldName)) {
86+
throw new UserfieldNotFoundException(sprintf('crm userfield not found by field name %s', $fieldName));
87+
}
88+
89+
return $this->$fieldName;
90+
}
91+
}

src/Services/CRM/Contact/Result/ContactItemResult.php

Lines changed: 60 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -4,59 +4,70 @@
44

55
namespace Bitrix24\SDK\Services\CRM\Contact\Result;
66

7-
use Bitrix24\SDK\Core\Result\AbstractItem;
7+
use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem;
8+
use DateTimeInterface;
89

910
/**
1011
* Class ContactItemResult
1112
*
12-
* @property-read int $ID
13-
* @property-read string $HONORIFIC
14-
* @property-read string $NAME
15-
* @property-read string $SECOND_NAME
16-
* @property-read string $LAST_NAME
17-
* @property-read string $PHOTO
18-
* @property-read string $BIRTHDATE
19-
* @property-read string $TYPE_ID
20-
* @property-read string $SOURCE_ID
21-
* @property-read string $SOURCE_DESCRIPTION
22-
* @property-read string $POST
23-
* @property-read string $ADDRESS
24-
* @property-read string $ADDRESS_2
25-
* @property-read string $ADDRESS_CITY
26-
* @property-read string $ADDRESS_POSTAL_CODE
27-
* @property-read string $ADDRESS_REGION
28-
* @property-read string $ADDRESS_PROVINCE
29-
* @property-read string $ADDRESS_COUNTRY
30-
* @property-read string $ADDRESS_COUNTRY_CODE
31-
* @property-read int $ADDRESS_LOC_ADDR_ID
32-
* @property-read string $COMMENTS
33-
* @property-read string $OPENED
34-
* @property-read string $EXPORT
35-
* @property-read string $HAS_PHONE
36-
* @property-read string $HAS_EMAIL
37-
* @property-read string $HAS_IMOL
38-
* @property-read string $ASSIGNED_BY_ID
39-
* @property-read string $CREATED_BY_ID
40-
* @property-read string $MODIFY_BY_ID
41-
* @property-read string $DATE_CREATE
42-
* @property-read string $DATE_MODIFY
43-
* @property-read string $COMPANY_ID
44-
* @property-read string $COMPANY_IDS
45-
* @property-read string $LEAD_ID
46-
* @property-read string $ORIGINATOR_ID
47-
* @property-read string $ORIGIN_ID
48-
* @property-read string $ORIGIN_VERSION
49-
* @property-read int $FACE_ID
50-
* @property-read string $UTM_SOURCE
51-
* @property-read string $UTM_MEDIUM
52-
* @property-read string $UTM_CAMPAIGN
53-
* @property-read string $UTM_CONTENT
54-
* @property-read string $UTM_TERM
55-
* @property-read string $PHONE
56-
* @property-read string $EMAIL
57-
* @property-read string $WEB
58-
* @property-read string $IM
13+
* @property-read int $ID
14+
* @property-read string $HONORIFIC
15+
* @property-read string $NAME
16+
* @property-read string $SECOND_NAME
17+
* @property-read string $LAST_NAME
18+
* @property-read string $PHOTO
19+
* @property-read null|DateTimeInterface $BIRTHDATE
20+
* @property-read string $TYPE_ID
21+
* @property-read string $SOURCE_ID
22+
* @property-read string $SOURCE_DESCRIPTION
23+
* @property-read string $POST
24+
* @property-read string $ADDRESS
25+
* @property-read string $ADDRESS_2
26+
* @property-read string $ADDRESS_CITY
27+
* @property-read string $ADDRESS_POSTAL_CODE
28+
* @property-read string $ADDRESS_REGION
29+
* @property-read string $ADDRESS_PROVINCE
30+
* @property-read string $ADDRESS_COUNTRY
31+
* @property-read string $ADDRESS_COUNTRY_CODE
32+
* @property-read int $ADDRESS_LOC_ADDR_ID
33+
* @property-read string $COMMENTS
34+
* @property-read string $OPENED
35+
* @property-read bool $EXPORT
36+
* @property-read string $HAS_PHONE
37+
* @property-read string $HAS_EMAIL
38+
* @property-read string $HAS_IMOL
39+
* @property-read int $ASSIGNED_BY_ID
40+
* @property-read int $CREATED_BY_ID
41+
* @property-read int $MODIFY_BY_ID
42+
* @property-read DateTimeInterface $DATE_CREATE
43+
* @property-read DateTimeInterface $DATE_MODIFY
44+
* @property-read string $COMPANY_ID
45+
* @property-read string $COMPANY_IDS
46+
* @property-read string $LEAD_ID
47+
* @property-read string $ORIGINATOR_ID
48+
* @property-read string $ORIGIN_ID
49+
* @property-read string $ORIGIN_VERSION
50+
* @property-read int $FACE_ID
51+
* @property-read string $UTM_SOURCE
52+
* @property-read string $UTM_MEDIUM
53+
* @property-read string $UTM_CAMPAIGN
54+
* @property-read string $UTM_CONTENT
55+
* @property-read string $UTM_TERM
56+
* @property-read string $PHONE
57+
* @property-read string $EMAIL
58+
* @property-read string $WEB
59+
* @property-read string $IM
5960
*/
60-
class ContactItemResult extends AbstractItem
61+
class ContactItemResult extends AbstractCrmItem
6162
{
63+
/**
64+
* @param string $userfieldName
65+
*
66+
* @return mixed|null
67+
* @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException
68+
*/
69+
public function getUserfieldByFieldName(string $userfieldName)
70+
{
71+
return $this->getKeyWithUserfieldByFieldName($userfieldName);
72+
}
6273
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Contact\Result;
6+
7+
use Bitrix24\SDK\Services\CRM\Userfield\Result\AbstractUserfieldItemResult;
8+
9+
class ContactUserfieldItemResult extends AbstractUserfieldItemResult
10+
{
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Bitrix24\SDK\Services\CRM\Contact\Result;
6+
7+
use Bitrix24\SDK\Core\Result\AbstractResult;
8+
9+
class ContactUserfieldResult extends AbstractResult
10+
{
11+
/**
12+
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
13+
*/
14+
public function userfieldItem(): ContactUserfieldItemResult
15+
{
16+
return new ContactUserfieldItemResult($this->getCoreResponse()->getResponseData()->getResult()->getResultData());
17+
}
18+
}

0 commit comments

Comments
 (0)