-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #519 from Ilyumzhinov/feature/INT-2524
Добавил CustomFieldsFilter для фильтрации полей по типам.
- Loading branch information
Showing
3 changed files
with
71 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace AmoCRM\Filters; | ||
|
||
use AmoCRM\Filters\Interfaces\HasPagesInterface; | ||
use AmoCRM\Filters\Traits\ArrayOrStringFilterTrait; | ||
use AmoCRM\Filters\Traits\PagesFilterTrait; | ||
|
||
/** | ||
* Supports pagination and filtering custom_fields by types. | ||
*/ | ||
class CustomFieldsFilter extends BaseEntityFilter implements HasPagesInterface | ||
{ | ||
use PagesFilterTrait; | ||
use ArrayOrStringFilterTrait; | ||
|
||
/** | ||
* @var null|string[] An array of custom_field types. | ||
*/ | ||
private ?array $types = null; | ||
|
||
/** | ||
* @return string[]|null | ||
*/ | ||
public function getTypes(): ?array | ||
{ | ||
return $this->types; | ||
} | ||
|
||
/** | ||
* Filters custom_fields by types. | ||
* | ||
* @param string[]|null $types Type are defined in `CustomFieldModel`. | ||
*/ | ||
public function setTypes(?array $types): self | ||
{ | ||
$this->types = $this->parseArrayOrStringFilter($types); | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function buildFilter(): array | ||
{ | ||
$filter = []; | ||
|
||
if (!empty($this->types)) { | ||
$filter['filter']['type'] = $this->types; | ||
} | ||
|
||
$filter = $this->buildPagesFilter($filter); | ||
|
||
return $filter; | ||
} | ||
} |