Skip to content
This repository was archived by the owner on Feb 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
* add method `countByFilter` for all related services, see
issue [Добавить для всех сущностей метод подсчёта количества элементов по фильтру #228](https://github.com/mesilov/bitrix24-php-sdk/issues/228)
* add in scope «CRM» Userfield service and integration test
* add in scope «CRM» ContactUserfield service and integration test
* add in scope «CRM» ContactUserfield service and integration test, see
issue [Добавить для всех сущностей метод подсчёта количества элементов по фильтру #231](https://github.com/mesilov/bitrix24-php-sdk/issues/231)
* add method getUserfieldByFieldName for `ContactItemResult`
* add in scope «CRM» DealUserfield service and integration test, see
issue [Добавить для всех сущностей метод подсчёта количества элементов по фильтру #232](https://github.com/mesilov/bitrix24-php-sdk/issues/232)
* add method getUserfieldByFieldName for `DealItemResult`
* add exception `UserfieldNotFoundException`

### Removed
Expand Down
15 changes: 15 additions & 0 deletions src/Services/CRM/CRMServiceBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,21 @@ public function deal(): Deal\Service\Deal
return $this->serviceCache[__METHOD__];
}

/**
* @return \Bitrix24\SDK\Services\CRM\Deal\Service\DealUserfield
*/
public function dealUserfield(): Deal\Service\DealUserfield
{
if (!isset($this->serviceCache[__METHOD__])) {
$this->serviceCache[__METHOD__] = new Deal\Service\DealUserfield(
$this->core,
$this->log
);
}

return $this->serviceCache[__METHOD__];
}

/**
* @return Contact\Service\Contact
*/
Expand Down
10 changes: 10 additions & 0 deletions src/Services/CRM/Deal/Result/DealItemResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,14 @@
*/
class DealItemResult extends AbstractCrmItem
{
/**
* @param string $userfieldName
*
* @return mixed|null
* @throws \Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNotFoundException
*/
public function getUserfieldByFieldName(string $userfieldName)
{
return $this->getKeyWithUserfieldByFieldName($userfieldName);
}
}
12 changes: 12 additions & 0 deletions src/Services/CRM/Deal/Result/DealUserfieldItemResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php


declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Deal\Result;

use Bitrix24\SDK\Services\CRM\Userfield\Result\AbstractUserfieldItemResult;

class DealUserfieldItemResult extends AbstractUserfieldItemResult
{
}
19 changes: 19 additions & 0 deletions src/Services/CRM/Deal/Result/DealUserfieldResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php


declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Deal\Result;

use Bitrix24\SDK\Core\Result\AbstractResult;

class DealUserfieldResult extends AbstractResult
{
/**
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
*/
public function userfieldItem(): DealUserfieldItemResult
{
return new DealUserfieldItemResult($this->getCoreResponse()->getResponseData()->getResult()->getResultData());
}
}
26 changes: 26 additions & 0 deletions src/Services/CRM/Deal/Result/DealUserfieldsResult.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php


declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Deal\Result;

use Bitrix24\SDK\Core\Exceptions\BaseException;
use Bitrix24\SDK\Core\Result\AbstractResult;

class DealUserfieldsResult extends AbstractResult
{
/**
* @return \Bitrix24\SDK\Services\CRM\Deal\Result\DealUserfieldItemResult[]
* @throws BaseException
*/
public function getUserfields(): array
{
$res = [];
foreach ($this->getCoreResponse()->getResponseData()->getResult()->getResultData() as $item) {
$res[] = new DealUserfieldItemResult($item);
}

return $res;
}
}
2 changes: 1 addition & 1 deletion src/Services/CRM/Deal/Service/Deal.php
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ public function list(array $order, array $filter, array $select, int $startItem
* @throws BaseException
* @throws TransportException
*/
public function update(int $id, array $fields, array $params): UpdatedItemResult
public function update(int $id, array $fields, array $params = []): UpdatedItemResult
{
return new UpdatedItemResult(
$this->core->call(
Expand Down
205 changes: 205 additions & 0 deletions src/Services/CRM/Deal/Service/DealUserfield.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,205 @@
<?php

declare(strict_types=1);

namespace Bitrix24\SDK\Services\CRM\Deal\Service;

use Bitrix24\SDK\Core\Result\AddedItemResult;
use Bitrix24\SDK\Core\Result\DeletedItemResult;
use Bitrix24\SDK\Core\Result\UpdatedItemResult;
use Bitrix24\SDK\Services\AbstractService;
use Bitrix24\SDK\Services\CRM\Deal\Result\DealUserfieldResult;
use Bitrix24\SDK\Services\CRM\Deal\Result\DealUserfieldsResult;
use Bitrix24\SDK\Services\CRM\Userfield\Exceptions\UserfieldNameIsTooLongException;

class DealUserfield extends AbstractService
{
/**
* Returns list of user deal fields by filter.
*
* @param array{
* ID?: string,
* ENTITY_ID?: string,
* FIELD_NAME?: string,
* USER_TYPE_ID?: string,
* XML_ID?: string,
* SORT?: string,
* MULTIPLE?: string,
* MANDATORY?: string,
* SHOW_FILTER?: string,
* SHOW_IN_LIST?: string,
* EDIT_IN_LIST?: string,
* IS_SEARCHABLE?: string,
* EDIT_FORM_LABEL?: string,
* LIST_COLUMN_LABEL?: string,
* LIST_FILTER_LABEL?: string,
* ERROR_MESSAGE?: string,
* HELP_MESSAGE?: string,
* LIST?: string,
* SETTINGS?: string,
* } $order
* @param array{
* ID?: string,
* ENTITY_ID?: string,
* FIELD_NAME?: string,
* USER_TYPE_ID?: string,
* XML_ID?: string,
* SORT?: string,
* MULTIPLE?: string,
* MANDATORY?: string,
* SHOW_FILTER?: string,
* SHOW_IN_LIST?: string,
* EDIT_IN_LIST?: string,
* IS_SEARCHABLE?: string,
* EDIT_FORM_LABEL?: string,
* LIST_COLUMN_LABEL?: string,
* LIST_FILTER_LABEL?: string,
* ERROR_MESSAGE?: string,
* HELP_MESSAGE?: string,
* LIST?: string,
* SETTINGS?: string,
* } $filter
*
* @return \Bitrix24\SDK\Services\CRM\Deal\Result\DealUserfieldsResult
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException
* @link https://training.bitrix24.com/rest_help/crm/deals/crm_deal_userfield_list.php
*/
public function list(array $order, array $filter): DealUserfieldsResult
{
return new DealUserfieldsResult(
$this->core->call(
'crm.deal.userfield.list',
[
'order' => $order,
'filter' => $filter,
]
)
);
}

/**
* Created new user field for deals.
*
* System limitation for field name - 20 characters.
* Prefix UF_CRM_is always added to the user field name.
* As a result, the actual name length - 13 characters.
*
* @param array{
* FIELD_NAME?: string,
* USER_TYPE_ID?: string,
* XML_ID?: string,
* SORT?: string,
* MULTIPLE?: string,
* MANDATORY?: string,
* SHOW_FILTER?: string,
* SHOW_IN_LIST?: string,
* EDIT_IN_LIST?: string,
* IS_SEARCHABLE?: string,
* EDIT_FORM_LABEL?: string,
* LIST_COLUMN_LABEL?: string,
* LIST_FILTER_LABEL?: string,
* ERROR_MESSAGE?: string,
* HELP_MESSAGE?: string,
* LIST?: string,
* SETTINGS?: string,
* } $userfieldItemFields
*
* @return \Bitrix24\SDK\Core\Result\AddedItemResult
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException
* @throws UserfieldNameIsTooLongException
* @link https://training.bitrix24.com/rest_help/crm/deals/crm_deal_userfield_add.php
*
*/
public function add(array $userfieldItemFields): AddedItemResult
{
if (strlen($userfieldItemFields['FIELD_NAME']) > 13) {
throw new UserfieldNameIsTooLongException(
sprintf(
'userfield name %s is too long %s, maximum length - 13 characters',
$userfieldItemFields['FIELD_NAME'],
strlen($userfieldItemFields['FIELD_NAME'])
)
);
}

return new AddedItemResult(
$this->core->call(
'crm.deal.userfield.add',
[
'fields' => $userfieldItemFields,
]
)
);
}

/**
* Deleted userfield for deals
*
* @param int $userfieldId
*
* @return \Bitrix24\SDK\Core\Result\DeletedItemResult
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException
* @link https://training.bitrix24.com/rest_help/crm/deals/crm_deal_userfield_delete.php
*
*/
public function delete(int $userfieldId): DeletedItemResult
{
return new DeletedItemResult(
$this->core->call(
'crm.deal.userfield.delete',
[
'id' => $userfieldId,
]
)
);
}

/**
* Returns a userfield for deal by ID.
*
* @param int $userfieldItemId
*
* @return \Bitrix24\SDK\Services\CRM\Deal\Result\DealUserfieldResult
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException
* @link https://training.bitrix24.com/rest_help/crm/deals/crm_deal_userfield_get.php
*/
public function get(int $userfieldItemId): DealUserfieldResult
{
return new DealUserfieldResult(
$this->core->call(
'crm.deal.userfield.get',
[
'id' => $userfieldItemId,
]
)
);
}

/**
* Updates an existing user field for deals.
*
* @param int $userfieldItemId
* @param array $userfieldFieldsToUpdate
*
* @return \Bitrix24\SDK\Core\Result\UpdatedItemResult
* @throws \Bitrix24\SDK\Core\Exceptions\BaseException
* @throws \Bitrix24\SDK\Core\Exceptions\TransportException
* @link https://training.bitrix24.com/rest_help/crm/deals/crm_deal_userfield_update.php
*/
public function update(int $userfieldItemId, array $userfieldFieldsToUpdate): UpdatedItemResult
{
return new UpdatedItemResult(
$this->core->call(
'crm.deal.userfield.update',
[
'id' => $userfieldItemId,
'fields' => $userfieldFieldsToUpdate,
]
)
);
}
}
Loading