diff --git a/src/AmoCRM/Collections/Talks/TalksCollection.php b/src/AmoCRM/Collections/Talks/TalksCollection.php new file mode 100644 index 00000000..1781962e --- /dev/null +++ b/src/AmoCRM/Collections/Talks/TalksCollection.php @@ -0,0 +1,27 @@ +|null */ + private $talkIds = null; + + /** @var array|null */ + private $entityIds = null; + + /** @var string|null */ + private $entityType = null; + + /** @var array|null */ + private $contactIds = null; + + /** @var bool */ + private $onlyInWork = false; + + /** + * @return array|null + */ + public function getTalkIds(): ?array + { + return $this->talkIds; + } + + /** + * @param array|int $talkIds + * + * @return self + */ + public function setTalkIds($talkIds): self + { + $this->talkIds = $this->parseArrayOrNumberFilter($talkIds); + + return $this; + } + + /** + * @return array|null + */ + public function getEntityIds(): ?array + { + return $this->entityIds; + } + + /** + * @param array|int $entityIds + * + * @return self + */ + public function setEntityIds($entityIds): self + { + $this->entityIds = $this->parseArrayOrNumberFilter($entityIds); + + return $this; + } + + public function getEntityType(): ?string + { + return $this->entityType; + } + + public function setEntityType(string $entityType): self + { + $this->entityType = $entityType; + + return $this; + } + + /** + * @return array|null + */ + public function getContactIds(): ?array + { + return $this->contactIds; + } + + /** + * @param array|int $contactIds + * + * @return self + */ + public function setContactIds($contactIds): self + { + $this->contactIds = $this->parseArrayOrNumberFilter($contactIds); + + return $this; + } + + public function getOnlyInWork(): bool + { + return $this->onlyInWork; + } + + public function setOnlyInWork(bool $onlyInWork): self + { + $this->onlyInWork = $onlyInWork; + + return $this; + } + + public function buildFilter(): array + { + $filter = []; + + if (!is_null($this->getTalkIds())) { + $filter['filter']['talk_id'] = $this->getTalkIds(); + } + + if (!is_null($this->getEntityIds())) { + $filter['filter']['entity_id'] = $this->getEntityIds(); + } + + if (!is_null($this->getEntityType())) { + $filter['filter']['entity_type'] = $this->getEntityType(); + } + + if (!is_null($this->getContactIds())) { + $filter['filter']['contact_id'] = $this->getContactIds(); + } + + if ($this->getOnlyInWork()) { + $filter['filter']['only_in_work'] = true; + } + + return $this->buildPagesFilter($filter); + } +} diff --git a/src/AmoCRM/Models/TalkModel.php b/src/AmoCRM/Models/TalkModel.php index 920edfab..f644abbf 100644 --- a/src/AmoCRM/Models/TalkModel.php +++ b/src/AmoCRM/Models/TalkModel.php @@ -8,6 +8,12 @@ class TalkModel extends BaseApiModel { + public const STATUS_IN_WORK = 'in_work'; + public const STATUS_CLOSED = 'closed'; + public const STATUS_WITH_ERROR = 'with_error'; + public const STATUS_NPS_SCHEDULED = 'nps_scheduled'; + public const STATUS_NPS_IN_PROGRESS = 'nps_in_progress'; + /** @var int */ protected $talkId; /** @var int */ @@ -24,6 +30,8 @@ class TalkModel extends BaseApiModel protected $entityId; /** @var string|null */ protected $entityType; + /** @var string|null */ + protected $status; /** @var bool */ protected $isInWork; /** @var bool */ @@ -31,6 +39,8 @@ class TalkModel extends BaseApiModel /** @var string */ protected $origin; /** @var int|null */ + protected $sourceId; + /** @var int|null */ protected $missedAt; /** @var int */ protected $accountId; @@ -49,11 +59,13 @@ public static function fromArray(array $talk): self ->setRate((int)$talk['rate']) ->setContactId((int)$talk['contact_id']) ->setChatId(empty($talk['chat_id']) ? null : (string)$talk['chat_id']) - ->setEntityId(empty($talk['entity_id']) ?: (int)$talk['entity_id']) - ->setEntityType(empty($talk['entity_type']) ?: (string)$talk['entity_type']) + ->setEntityId(empty($talk['entity_id']) ? null : (int)$talk['entity_id']) + ->setEntityType(empty($talk['entity_type']) ? null : (string)$talk['entity_type']) + ->setStatus($talk['status'] ?? null) ->setIsInWork(!empty($talk['is_in_work'])) ->setIsRead(!empty($talk['is_read'])) ->setOrigin((string)($talk['origin'] ?? '')) + ->setSourceId(($talk['source_id'] ?? null) !== null ? (int)$talk['source_id'] : null) ->setMissedAt(empty($talk['missed_at']) ? null : (int)$talk['missed_at']) ->setAccountId((int)$talk['account_id']); } @@ -154,6 +166,18 @@ public function setEntityType(?string $entityType): self return $this; } + public function getStatus(): ?string + { + return $this->status; + } + + public function setStatus(?string $status): self + { + $this->status = $status; + + return $this; + } + public function isInWork(): bool { return $this->isInWork; @@ -190,6 +214,18 @@ public function setOrigin(string $origin): self return $this; } + public function getSourceId(): ?int + { + return $this->sourceId; + } + + public function setSourceId(?int $sourceId): self + { + $this->sourceId = $sourceId; + + return $this; + } + public function getMissedAt(): ?int { return $this->missedAt; @@ -228,9 +264,11 @@ public function toArray(): array 'chat_id' => $this->getChatId(), 'entity_id' => $this->getEntityId(), 'entity_type' => $this->getEntityType(), + 'status' => $this->getStatus(), 'is_in_work' => $this->isInWork(), 'is_read' => $this->isRead(), 'origin' => $this->getOrigin(), + 'source_id' => $this->getSourceId(), 'missed_at' => $this->getMissedAt(), 'account_id' => $this->getAccountId(), ];