2024-12-20 23:46:30 +01:00
|
|
|
<?php
|
|
|
|
|
2024-12-29 00:47:30 +01:00
|
|
|
/**
|
|
|
|
* Copyright (c) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
*
|
|
|
|
* For the full copyright and license information, please view
|
|
|
|
* the LICENSE file that was distributed with this source code.
|
|
|
|
*
|
|
|
|
* https://www.d3data.de
|
|
|
|
*
|
|
|
|
* @copyright (C) D3 Data Development (Inh. Thomas Dartsch)
|
|
|
|
* @author D3 Data Development - Daniel Seifert <info@shopmodule.com>
|
|
|
|
* @link https://www.oxidmodule.com
|
|
|
|
*/
|
|
|
|
|
2024-12-20 23:46:30 +01:00
|
|
|
namespace D3\KlicktippPhpClient\Resources;
|
|
|
|
|
|
|
|
use D3\KlicktippPhpClient\Entities\Tag as TagEntity;
|
2024-12-22 23:36:29 +01:00
|
|
|
use D3\KlicktippPhpClient\Entities\TagList;
|
2024-12-20 23:46:30 +01:00
|
|
|
use D3\KlicktippPhpClient\Exceptions\BaseException;
|
2024-12-21 19:17:08 +01:00
|
|
|
use GuzzleHttp\RequestOptions;
|
2024-12-20 23:46:30 +01:00
|
|
|
|
|
|
|
class Tag extends Model
|
|
|
|
{
|
2025-01-03 00:05:00 +01:00
|
|
|
public const ID = 'tagid';
|
|
|
|
public const NAME = 'name';
|
|
|
|
public const TEXT = 'text';
|
|
|
|
|
2024-12-20 23:46:30 +01:00
|
|
|
/**
|
2024-12-29 23:33:09 +01:00
|
|
|
* @throws BaseException
|
2024-12-20 23:46:30 +01:00
|
|
|
*/
|
2024-12-22 23:36:29 +01:00
|
|
|
public function index(): TagList
|
2024-12-20 23:46:30 +01:00
|
|
|
{
|
2024-12-22 23:36:29 +01:00
|
|
|
$data = $this->connection->requestAndParse(
|
2024-12-20 23:46:30 +01:00
|
|
|
'GET',
|
2024-12-29 23:33:09 +01:00
|
|
|
'tag.json'
|
2024-12-20 23:46:30 +01:00
|
|
|
);
|
2024-12-22 23:36:29 +01:00
|
|
|
|
|
|
|
return new TagList($data);
|
2024-12-20 23:46:30 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-12-29 23:33:09 +01:00
|
|
|
* @throws BaseException
|
2024-12-20 23:46:30 +01:00
|
|
|
*/
|
2025-01-04 22:37:16 +01:00
|
|
|
public function get(string $tagId): array
|
2024-12-20 23:46:30 +01:00
|
|
|
{
|
2025-01-04 22:37:16 +01:00
|
|
|
return $this->connection->requestAndParse(
|
2024-12-20 23:46:30 +01:00
|
|
|
'GET',
|
2024-12-29 23:33:09 +01:00
|
|
|
'tag/'.urlencode(trim($tagId)).'.json'
|
2024-12-22 13:54:42 +01:00
|
|
|
);
|
2025-01-04 22:37:16 +01:00
|
|
|
}
|
2024-12-22 13:54:42 +01:00
|
|
|
|
2025-01-04 22:37:16 +01:00
|
|
|
/**
|
|
|
|
* @throws BaseException
|
|
|
|
*/
|
|
|
|
public function getEntity(string $tagId): TagEntity
|
|
|
|
{
|
|
|
|
return new TagEntity($this->get($tagId), $this);
|
2024-12-22 13:54:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-12-29 23:33:09 +01:00
|
|
|
* @return string - new tag id
|
|
|
|
* @throws BaseException
|
2024-12-22 13:54:42 +01:00
|
|
|
*/
|
2024-12-29 23:33:09 +01:00
|
|
|
public function create(string $name): string
|
2024-12-22 13:54:42 +01:00
|
|
|
{
|
2024-12-29 23:33:09 +01:00
|
|
|
return current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'POST',
|
|
|
|
'tag.json',
|
|
|
|
[
|
|
|
|
RequestOptions::FORM_PARAMS => [
|
2025-01-03 00:05:00 +01:00
|
|
|
self::NAME => trim($name),
|
2024-12-29 23:33:09 +01:00
|
|
|
],
|
|
|
|
]
|
|
|
|
)
|
2024-12-22 13:54:42 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2024-12-29 23:33:09 +01:00
|
|
|
* @throws BaseException
|
2024-12-22 13:54:42 +01:00
|
|
|
*/
|
2025-01-01 22:27:01 +01:00
|
|
|
public function update(string $tagId, ?string $name = null, ?string $text = null): bool
|
2024-12-22 13:54:42 +01:00
|
|
|
{
|
2024-12-29 23:33:09 +01:00
|
|
|
return (bool) current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'PUT',
|
|
|
|
'tag/'.urlencode(trim($tagId)).'.json',
|
|
|
|
[
|
2025-01-01 22:27:01 +01:00
|
|
|
RequestOptions::FORM_PARAMS => array_filter([
|
2025-01-03 00:05:00 +01:00
|
|
|
self::NAME => trim($name ?? ''),
|
|
|
|
self::TEXT => trim($text ?? ''),
|
2025-01-01 22:27:01 +01:00
|
|
|
]),
|
2024-12-29 23:33:09 +01:00
|
|
|
]
|
|
|
|
)
|
2024-12-20 23:46:30 +01:00
|
|
|
);
|
2024-12-22 13:54:42 +01:00
|
|
|
}
|
2024-12-20 23:46:30 +01:00
|
|
|
|
2024-12-22 13:54:42 +01:00
|
|
|
/**
|
2024-12-29 23:33:09 +01:00
|
|
|
* @throws BaseException
|
2024-12-22 13:54:42 +01:00
|
|
|
*/
|
2024-12-29 23:33:09 +01:00
|
|
|
public function delete(string $tagId): bool
|
2024-12-22 13:54:42 +01:00
|
|
|
{
|
2024-12-29 23:33:09 +01:00
|
|
|
return (bool) current(
|
|
|
|
$this->connection->requestAndParse(
|
|
|
|
'DELETE',
|
|
|
|
'tag/'.urlencode(trim($tagId)).'.json'
|
|
|
|
)
|
2024-12-22 13:54:42 +01:00
|
|
|
);
|
2024-12-20 23:46:30 +01:00
|
|
|
}
|
|
|
|
}
|