mirror of
https://github.com/Karaka-Management/oms-Tag.git
synced 2026-01-11 15:48:42 +00:00
Started implementing Orange-Management/Orange-Management#222 read is already working
This commit is contained in:
parent
dbb8aa2585
commit
4d5bdbd5b8
|
|
@ -9,11 +9,6 @@
|
|||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"tag_title": {
|
||||
"name": "tag_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"tag_color": {
|
||||
"name": "tag_color",
|
||||
"type": "VARCHAR(9)",
|
||||
|
|
@ -33,5 +28,37 @@
|
|||
"foreignKey": "account_id"
|
||||
}
|
||||
}
|
||||
},
|
||||
"tag_l11n": {
|
||||
"name": "tag_l11n",
|
||||
"fields": {
|
||||
"tag_l11n_id": {
|
||||
"name": "tag_l11n_id",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"primary": true,
|
||||
"autoincrement": true
|
||||
},
|
||||
"tag_l11n_title": {
|
||||
"name": "tag_l11n_title",
|
||||
"type": "VARCHAR(255)",
|
||||
"null": false
|
||||
},
|
||||
"tag_l11n_tag": {
|
||||
"name": "tag_l11n_tag",
|
||||
"type": "INT",
|
||||
"null": false,
|
||||
"foreignTable": "tag",
|
||||
"foreignKey": "tag_id"
|
||||
},
|
||||
"tag_l11n_language": {
|
||||
"name": "tag_l11n_language",
|
||||
"type": "VARCHAR(2)",
|
||||
"default": null,
|
||||
"null": true,
|
||||
"foreignTable": "language",
|
||||
"foreignKey": "language_639_1"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -14,6 +14,7 @@ declare(strict_types=1);
|
|||
|
||||
namespace Modules\Tag\Controller;
|
||||
|
||||
use Modules\Tag\Models\L11nTag;
|
||||
use Modules\Tag\Models\Tag;
|
||||
|
||||
use Modules\Tag\Models\TagMapper;
|
||||
|
|
@ -22,6 +23,8 @@ use phpOMS\Message\RequestAbstract;
|
|||
use phpOMS\Message\ResponseAbstract;
|
||||
use phpOMS\Model\Message\FormValidation;
|
||||
use phpOMS\System\MimeType;
|
||||
use Modules\Tag\Models\L11nTagMapper;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Tag controller class.
|
||||
|
|
@ -120,6 +123,11 @@ final class ApiController extends Controller
|
|||
|
||||
$tag = $this->createTagFromRequest($request);
|
||||
$this->createModel($request->getHeader()->getAccount(), $tag, TagMapper::class, 'tag');
|
||||
|
||||
$request->setData('tag', $tag->getId(), true);
|
||||
$l11nTag = $this->createL11nTagFromRequest($request);
|
||||
$this->createModel($request->getHeader()->getAccount(), $l11nTag, L11nTagMapper::class, 'tag_l11n');
|
||||
|
||||
$this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Tag', 'Tag successfully created', $tag);
|
||||
}
|
||||
|
||||
|
|
@ -135,12 +143,30 @@ final class ApiController extends Controller
|
|||
private function createTagFromRequest(RequestAbstract $request) : Tag
|
||||
{
|
||||
$tag = new Tag();
|
||||
$tag->setTitle((string) ($request->getData('title') ?? ''));
|
||||
$tag->setColor($request->getData('color') ?? '#00000000');
|
||||
|
||||
return $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to create tag localization from request.
|
||||
*
|
||||
* @param RequestAbstract $request Request
|
||||
*
|
||||
* @return L11nTag
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private function createL11nTagFromRequest(RequestAbstract $request) : L11nTag
|
||||
{
|
||||
$l11nTag = new L11nTag();
|
||||
$l11nTag->setTag((int) ($request->getData('tag') ?? 0));
|
||||
$l11nTag->setLanguage((string) ($request->getData('language') ?? ISO639x1Enum::_EN));
|
||||
$l11nTag->setTitle((string) ($request->getData('title') ?? ''));
|
||||
|
||||
return $l11nTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Api method to get a tag
|
||||
*
|
||||
|
|
|
|||
172
Models/L11nTag.php
Normal file
172
Models/L11nTag.php
Normal file
|
|
@ -0,0 +1,172 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package Modules\Tag\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Tag\Models;
|
||||
|
||||
use phpOMS\Contract\ArrayableInterface;
|
||||
use phpOMS\Localization\ISO639x1Enum;
|
||||
|
||||
/**
|
||||
* Tag class.
|
||||
*
|
||||
* @package Modules\Tag\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
class L11nTag implements ArrayableInterface, \JsonSerializable
|
||||
{
|
||||
/**
|
||||
* Article ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $id = 0;
|
||||
|
||||
/**
|
||||
* Tag ID.
|
||||
*
|
||||
* @var int
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected int $tag = 0;
|
||||
|
||||
/**
|
||||
* Language.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected string $language = ISO639x1Enum::_EN;
|
||||
|
||||
/**
|
||||
* Title.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
private string $title = '';
|
||||
|
||||
/**
|
||||
* Get id
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getId() : int
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set tag.
|
||||
*
|
||||
* @param int $tag Tag id
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setTag(int $tag) : void
|
||||
{
|
||||
$this->tag = $tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag
|
||||
*
|
||||
* @return int
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTag() : int
|
||||
{
|
||||
return $this->tag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get language
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getLanguage() : string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set language
|
||||
*
|
||||
* @param string $language Language
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setLanguage(string $language) : void
|
||||
{
|
||||
$this->language = $language;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get tag title.
|
||||
*
|
||||
* @return string
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function getTitle() : string
|
||||
{
|
||||
return $this->title;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set title
|
||||
*
|
||||
* @param string $title Title
|
||||
*
|
||||
* @return void
|
||||
*
|
||||
* @since 1.0.0
|
||||
*/
|
||||
public function setTitle(string $title) : void
|
||||
{
|
||||
$this->title = $title;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function toArray() : array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'title' => $this->title,
|
||||
'tag' => $this->tag,
|
||||
'language' => $this->language,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function jsonSerialize()
|
||||
{
|
||||
return $this->toArray();
|
||||
}
|
||||
}
|
||||
73
Models/L11nTagMapper.php
Normal file
73
Models/L11nTagMapper.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
/**
|
||||
* Orange Management
|
||||
*
|
||||
* PHP Version 7.4
|
||||
*
|
||||
* @package Modules\Tag\Models
|
||||
* @copyright Dennis Eichhorn
|
||||
* @license OMS License 1.0
|
||||
* @version 1.0.0
|
||||
* @link https://orange-management.org
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Modules\Tag\Models;
|
||||
|
||||
use phpOMS\DataStorage\Database\DataMapperAbstract;
|
||||
use phpOMS\Localization\Defaults\LanguageMapper;
|
||||
|
||||
/**
|
||||
* Tag mapper class.
|
||||
*
|
||||
* @package Modules\Tag\Models
|
||||
* @license OMS License 1.0
|
||||
* @link https://orange-management.org
|
||||
* @since 1.0.0
|
||||
*/
|
||||
final class L11nTagMapper extends DataMapperAbstract
|
||||
{
|
||||
/**
|
||||
* Columns.
|
||||
*
|
||||
* @var array<string, array{name:string, type:string, internal:string, autocomplete?:bool, readonly?:bool, writeonly?:bool, annotations?:array}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $columns = [
|
||||
'tag_l11n_id' => ['name' => 'tag_l11n_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'tag_l11n_title' => ['name' => 'tag_l11n_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
||||
'tag_l11n_tag' => ['name' => 'tag_l11n_tag', 'type' => 'int', 'internal' => 'tag'],
|
||||
'tag_l11n_language' => ['name' => 'tag_l11n_language', 'type' => 'string', 'internal' => 'language'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has one relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, self:string, by?:string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $ownsOne = [
|
||||
'language' => [
|
||||
'mapper' => LanguageMapper::class,
|
||||
'self' => 'tag_l11n_language',
|
||||
'by' => 'code2',
|
||||
'column' => 'code2',
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Primary table.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $table = 'tag_l11n';
|
||||
|
||||
/**
|
||||
* Primary field name.
|
||||
*
|
||||
* @var string
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static string $primaryField = 'tag_l11n_id';
|
||||
}
|
||||
|
|
@ -35,12 +35,27 @@ final class TagMapper extends DataMapperAbstract
|
|||
*/
|
||||
protected static array $columns = [
|
||||
'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'],
|
||||
'tag_title' => ['name' => 'tag_title', 'type' => 'string', 'internal' => 'title', 'autocomplete' => true],
|
||||
'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'],
|
||||
'tag_type' => ['name' => 'tag_type', 'type' => 'int', 'internal' => 'type'],
|
||||
'tag_owner' => ['name' => 'tag_owner', 'type' => 'int', 'internal' => 'owner'],
|
||||
];
|
||||
|
||||
/**
|
||||
* Has many relation.
|
||||
*
|
||||
* @var array<string, array{mapper:string, table:string, self?:?string, external?:?string}>
|
||||
* @since 1.0.0
|
||||
*/
|
||||
protected static array $hasMany = [
|
||||
'title' => [
|
||||
'mapper' => L11nTagMapper::class,
|
||||
'table' => 'tag_l11n',
|
||||
'external' => 'tag_l11n_tag',
|
||||
'column' => 'title',
|
||||
'self' => null,
|
||||
],
|
||||
];
|
||||
|
||||
/**
|
||||
* Belongs to.
|
||||
*
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user