Skip to content
Open
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
43 changes: 42 additions & 1 deletion src/AmoCRM/EntitiesServices/EntityNotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

use AmoCRM\EntitiesServices\Interfaces\HasParentEntity;
use AmoCRM\EntitiesServices\Traits\WithParentEntityMethodsTrait;
use AmoCRM\Exceptions\AmoCRMApiConnectExceptionException;
use AmoCRM\Exceptions\AmoCRMApiException;
use AmoCRM\Exceptions\AmoCRMApiHttpClientException;
use AmoCRM\Exceptions\AmoCRMApiNoContentException;
use AmoCRM\Exceptions\AmoCRMApiTooManyRedirectsException;
use AmoCRM\Exceptions\AmoCRMoAuthApiException;
use AmoCRM\Exceptions\InvalidArgumentException;
use AmoCRM\Filters\BaseEntityFilter;
Expand All @@ -16,7 +20,6 @@
use AmoCRM\EntitiesServices\Interfaces\HasPageMethodsInterface;
use AmoCRM\EntitiesServices\Traits\PageMethodsTrait;
use AmoCRM\Models\BaseApiModel;
use AmoCRM\Models\CustomFields\CustomFieldModel;
use AmoCRM\Models\NoteModel;

/**
Expand Down Expand Up @@ -198,4 +201,42 @@ public function getOne($id, array $with = []): ?BaseApiModel

return !empty($response) ? $collection->first() : null;
}

/**
* Закрепляет примечание.
* @param NoteModel $model
*
* @return void
* @throws AmoCRMApiException
* @throws AmoCRMoAuthApiException
* @throws AmoCRMApiConnectExceptionException
* @throws AmoCRMApiHttpClientException
* @throws AmoCRMApiTooManyRedirectsException
*/
public function pin(NoteModel $model): void
{
try {
$this->request->post(sprintf('%s/%d/pin', $this->getMethod(), $model->getId()));
} catch (AmoCRMApiNoContentException $exception) {
}
}

/**
* Открепляет примечание.
* @param NoteModel $model
*
* @return void
* @throws AmoCRMApiException
* @throws AmoCRMoAuthApiException
* @throws AmoCRMApiConnectExceptionException
* @throws AmoCRMApiHttpClientException
* @throws AmoCRMApiTooManyRedirectsException
*/
public function unpin(NoteModel $model): void
{
try {
$this->request->post(sprintf('%s/%d/unpin', $this->getMethod(), $model->getId()));
} catch (AmoCRMApiNoContentException $exception) {
}
}
}
36 changes: 35 additions & 1 deletion src/AmoCRM/Models/NoteModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ class NoteModel extends BaseApiModel implements Arrayable, HasIdInterface
{
use RequestIdTrait;

/** @var string Закреплено ли примечание */
public const IS_PINNED = 'is_pinned';

protected $modelClass = NoteModel::class;

/**
Expand Down Expand Up @@ -63,6 +66,11 @@ class NoteModel extends BaseApiModel implements Arrayable, HasIdInterface
*/
protected $accountId;

/**
* @var null|bool
*/
protected $isPinned = null;

/**
* @var null|bool
*/
Expand Down Expand Up @@ -109,6 +117,10 @@ public function fromArray(array $note): self
$model->setAccountId((int)$note['account_id']);
}

if (isset($note['is_pinned'])) {
$model->setIsPinned((bool)$note['is_pinned']);
}

if (!empty($note['is_need_to_trigger_digital_pipeline'])) {
$model->setIsNeedToTriggerDigitalPipeline((bool)$note['is_need_to_trigger_digital_pipeline']);
}
Expand Down Expand Up @@ -318,6 +330,26 @@ public function setAccountId(?int $accountId): NoteModel
return $this;
}

/**
* Возвращает закреплено ли примечание
* @return bool|null
*/
public function getIsPinned(): ?bool
{
return $this->isPinned;
}

/**
* @param bool|null $isPinned
* @return NoteModel
*/
public function setIsPinned(?bool $isPinned): NoteModel
{
$this->isPinned = $isPinned;

return $this;
}

/**
* @return bool|null
*/
Expand Down Expand Up @@ -393,6 +425,8 @@ public function toApi(?string $requestId = "0"): array
*/
public static function getAvailableWith(): array
{
return [];
return [
self::IS_PINNED,
];
}
}