Skip to content

Commit

Permalink
add multifields
Browse files Browse the repository at this point in the history
Signed-off-by: mesilov <[email protected]>
  • Loading branch information
mesilov committed Jan 4, 2024
1 parent 6a6ccef commit 5d65828
Show file tree
Hide file tree
Showing 12 changed files with 286 additions and 14 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@

### Added

* ❗️add php 8.3 support
* add `Symfony\Component\Uid\Uuid` requirements
* add contracts for bitrix24 applications based on bitrix24-php-sdk - `Bitrix24\SDK\Application\Contracts`, now
added `Bitrix24Account`
* add [service builder factory](https://github.com/mesilov/bitrix24-php-sdk/issues/328)
* add method `Bitrix24\SDK\Core\Credentials\Scope::initFromString`
* add method `Bitrix24\SDK\Application\ApplicationStatus::initFromString`
* ❗️add php 8.2 support
* add system CRM multi-field type `Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Phone`
* add scope `user`,`user_basic`,`user_brief`,`user.userfield` and
services [add scope user support](https://github.com/mesilov/bitrix24-php-sdk/issues/339)
Expand All @@ -25,6 +25,11 @@
* add enum `DealStageSemanticId`
* add Duplicate search support for `Bitrix24\SDK\Services\CRM\Duplicates\Service\Duplicate`
* add `x-request-id` [header support](https://github.com/mesilov/bitrix24-php-sdk/issues/354)
* add CRM multifields support [header support](https://github.com/mesilov/bitrix24-php-sdk/issues/338)
* `Email`
* `Phone`
* `Website`
* `IM`

### Changed

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@
"symfony/dotenv": "7.0.*",
"symfony/debug-bundle": "7.0.*",
"symfony/stopwatch": "7.0.*",
"roave/security-advisories": "dev-master"
"roave/security-advisories": "dev-master",
"fakerphp/faker": "1.23.*"
},
"autoload": {
"psr-4": {
Expand Down
43 changes: 38 additions & 5 deletions src/Services/CRM/Common/Result/AbstractCrmItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,19 @@
namespace Bitrix24\SDK\Services\CRM\Common\Result;

use Bitrix24\SDK\Core\Result\AbstractItem;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Email;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\InstantMessenger;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Phone;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\PhoneValueType;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Website;
use Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException;
use DateTimeImmutable;
use Money\Currency;
use Money\Money;

class AbstractCrmItem extends AbstractItem
{
private const CRM_USERFIELD_PREFIX = 'UF_CRM_';
private const string CRM_USERFIELD_PREFIX = 'UF_CRM_';

/**
* @var Currency
Expand All @@ -32,7 +35,7 @@ public function __construct(array $data, Currency $currency = null)
/**
* @param int|string $offset
*
* @return bool|\DateTimeImmutable|int|mixed|null
* @return bool|DateTimeImmutable|int|mixed|null
*/

public function __get($offset)
Expand Down Expand Up @@ -132,8 +135,38 @@ public function __get($offset)
}

$items = [];
foreach ($this->data[$offset] as $phone) {
$items[] = new Phone($phone);
foreach ($this->data[$offset] as $item) {
$items[] = new Phone($item);
}
return $items;
case 'EMAIL':
if (!$this->isKeyExists($offset)) {
return [];
}

$items = [];
foreach ($this->data[$offset] as $item) {
$items[] = new Email($item);
}
return $items;
case 'WEB':
if (!$this->isKeyExists($offset)) {
return [];
}

$items = [];
foreach ($this->data[$offset] as $item) {
$items[] = new Website($item);
}
return $items;
case 'IM':
if (!$this->isKeyExists($offset)) {
return [];
}

$items = [];
foreach ($this->data[$offset] as $item) {
$items[] = new InstantMessenger($item);
}
return $items;
case 'currencyId':
Expand All @@ -154,7 +187,7 @@ public function __get($offset)
*/
protected function getKeyWithUserfieldByFieldName(string $fieldName)
{
if(!str_starts_with($fieldName, self::CRM_USERFIELD_PREFIX)) {
if (!str_starts_with($fieldName, self::CRM_USERFIELD_PREFIX)) {
$fieldName = self::CRM_USERFIELD_PREFIX . $fieldName;
}
if (!$this->isKeyExists($fieldName)) {
Expand Down
25 changes: 25 additions & 0 deletions src/Services/CRM/Common/Result/SystemFields/Types/Email.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* @property-read string $VALUE
* @property-read int $ID
* @property-read PhoneValueType $VALUE_TYPE
*/
class Email extends AbstractItem
{
public function __get($offset)
{
return match ($offset) {
'VALUE' => $this->data[$offset],
'ID' => (int)$this->data['ID'],
'VALUE_TYPE' => EmailValueType::from($this->data['VALUE_TYPE']),
default => parent::__get($offset),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types;

enum EmailValueType: string
{
case work = 'WORK';
case home = 'HOME';
case other = 'OTHER';
case mailing = 'MAILING';
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* @property-read string $VALUE
* @property-read int $ID
* @property-read PhoneValueType $VALUE_TYPE
*/
class InstantMessenger extends AbstractItem
{
public function __get($offset)
{
return match ($offset) {
'VALUE' => $this->data[$offset],
'ID' => (int)$this->data['ID'],
'VALUE_TYPE' => EmailValueType::from($this->data['VALUE_TYPE']),
default => parent::__get($offset),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types;

enum InstantMessengerValueType: string
{
case facebook = 'FACEBOOK';
case telegram = 'TELEGRAM';
case vk = 'VK';
case skype = 'SKYPE';
case viber = 'VIBER';
case instagram = 'INSTAGRAM';
case bitrix24 = 'BITRIX24';
case openline = 'OPENLINE';
case imol = 'IMOL';
case icq = 'ICQ';
case msn = 'MSN';
case jabber = 'JABBER';
case other = 'OTHER';
}
25 changes: 25 additions & 0 deletions src/Services/CRM/Common/Result/SystemFields/Types/Website.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types;

use Bitrix24\SDK\Core\Result\AbstractItem;

/**
* @property-read string $VALUE
* @property-read int $ID
* @property-read PhoneValueType $VALUE_TYPE
*/
class Website extends AbstractItem
{
public function __get($offset)
{
return match ($offset) {
'VALUE' => $this->data[$offset],
'ID' => (int)$this->data['ID'],
'VALUE_TYPE' => EmailValueType::from($this->data['VALUE_TYPE']),
default => parent::__get($offset),
};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types;

enum WebsiteValueType: string
{
case work = 'WORK';
case home = 'HOME';
case facebook = 'FACEBOOK';
case vk = 'VK';
case livejournal = 'LIVEJOURNAL';
case twitter = 'TWITTER';
case other = 'OTHER';
}
9 changes: 6 additions & 3 deletions src/Services/CRM/Contact/Result/ContactItemResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
namespace Bitrix24\SDK\Services\CRM\Contact\Result;

use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Email;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\InstantMessenger;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Phone;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Website;
use Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException;
use DateTimeInterface;

Expand Down Expand Up @@ -56,9 +59,9 @@
* @property-read string $UTM_CONTENT
* @property-read string $UTM_TERM
* @property-read Phone[] $PHONE
* @property-read string $EMAIL
* @property-read string $WEB
* @property-read string $IM
* @property-read Email[] $EMAIL
* @property-read Website[] $WEB
* @property-read InstantMessenger[] $IM
*/
class ContactItemResult extends AbstractCrmItem
{
Expand Down
12 changes: 8 additions & 4 deletions src/Services/CRM/Lead/Result/LeadItemResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
namespace Bitrix24\SDK\Services\CRM\Lead\Result;

use Bitrix24\SDK\Services\CRM\Common\Result\AbstractCrmItem;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Email;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\InstantMessenger;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Phone;
use Bitrix24\SDK\Services\CRM\Common\Result\SystemFields\Types\Website;
use DateTimeInterface;

/**
Expand Down Expand Up @@ -60,10 +64,10 @@
* @property-read string $UTM_CAMPAIGN
* @property-read string $UTM_CONTENT
* @property-read string $UTM_TERM
* @property-read string $PHONE
* @property-read string $EMAIL
* @property-read string $WEB
* @property-read string $IM
* @property-read Phone[] $PHONE
* @property-read Email[] $EMAIL
* @property-read Website[] $WEB
* @property-read InstantMessenger[] $IM
* @property-read string $LINK
*/
class LeadItemResult extends AbstractCrmItem
Expand Down
Loading

0 comments on commit 5d65828

Please sign in to comment.