From 598bd93f7e8cadc34a07c59c3be01a55ddc3dab8 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Wed, 22 May 2019 07:47:03 +0200 Subject: [PATCH] Improved tag module and media virtual paths --- Admin/Install/db.json | 12 ++++++++ Models/Tag.php | 70 ++++++++++++++++++++++++++++++++++++++++++- Models/TagMapper.php | 30 ++++++++++++------- Models/TagType.php | 31 +++++++++++++++++++ 4 files changed, 131 insertions(+), 12 deletions(-) create mode 100644 Models/TagType.php diff --git a/Admin/Install/db.json b/Admin/Install/db.json index 4a9d949..63ada08 100644 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -18,6 +18,18 @@ "name": "tag_color", "type": "VARCHAR(8)", "null": false + }, + "tag_type": { + "name": "tag_type", + "type": "TINYINT(1)", + "null": false + }, + "tag_created_by": { + "name": "tag_created_by", + "type": "INT", + "null": false, + "foreignTable": "account", + "foreignKey": "account_id" } } } diff --git a/Models/Tag.php b/Models/Tag.php index fb5b8f1..daec16a 100644 --- a/Models/Tag.php +++ b/Models/Tag.php @@ -49,7 +49,75 @@ class Tag implements ArrayableInterface, \JsonSerializable * @var string * @since 1.0.0 */ - private $color = '000000'; + private $color = '00000000'; + + /** + * Creator. + * + * @var int + * @since 1.0.0 + */ + protected $createdBy = 0; + + /** + * Tag type. + * + * @var string + * @since 1.0.0 + */ + private $type = TagType::SINGLE; + + /** + * Get created by + * + * @return int|\phpOMS\Account\Account + * + * @since 1.0.0 + */ + public function getCreatedBy() + { + return $this->createdBy; + } + + /** + * Set created by + * + * @param mixed $id Created by + * + * @return void + * + * @since 1.0.0 + */ + public function setCreatedBy($id) : void + { + $this->createdBy = $id; + } + + /** + * Get type. + * + * @return int + * + * @since 1.0.0 + */ + public function getType() : int + { + return $this->type; + } + + /** + * Set type. + * + * @param int $type Tag type + * + * @return void + * + * @since 1.0.0 + */ + public function setType(int $type = TagType::SINGLE) : void + { + $this->type = $type; + } /** * Get color diff --git a/Models/TagMapper.php b/Models/TagMapper.php index f3f4e33..1cd3217 100644 --- a/Models/TagMapper.php +++ b/Models/TagMapper.php @@ -34,9 +34,25 @@ final class TagMapper extends DataMapperAbstract * @since 1.0.0 */ protected static $columns = [ - 'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'], - 'tag_title' => ['name' => 'tag_title', 'type' => 'string', 'internal' => 'title'], - 'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'], + 'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'], + 'tag_title' => ['name' => 'tag_title', 'type' => 'string', 'internal' => 'title'], + 'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'], + 'tag_type' => ['name' => 'tag_type', 'type' => 'int', 'internal' => 'type'], + 'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'], + 'tag_created_by' => ['name' => 'tag_created_by', 'type' => 'int', 'internal' => 'createdBy'], + ]; + + /** + * Belongs to. + * + * @var array> + * @since 1.0.0 + */ + protected static $belongsTo = [ + 'createdBy' => [ + 'mapper' => AccountMapper::class, + 'src' => 'tag_created_by', + ], ]; /** @@ -54,12 +70,4 @@ final class TagMapper extends DataMapperAbstract * @since 1.0.0 */ protected static $primaryField = 'tag_id'; - - /** - * Created at. - * - * @var string - * @since 1.0.0 - */ - protected static $createdAt = 'tag_created_at'; } diff --git a/Models/TagType.php b/Models/TagType.php new file mode 100644 index 0000000..f5f21c1 --- /dev/null +++ b/Models/TagType.php @@ -0,0 +1,31 @@ +