From b10b031c49c5355d7e8bc375a7dd9bb38d4d3547 Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Sat, 19 Dec 2020 20:26:28 +0100 Subject: [PATCH] Add tag icons --- Admin/Install/db.json | 6 +++++ Controller/ApiController.php | 7 +++--- Models/Tag.php | 36 ++++++++---------------------- Models/TagMapper.php | 1 + Theme/Backend/Lang/de.lang.php | 1 + Theme/Backend/Lang/en.lang.php | 1 + Theme/Backend/tag-create.tpl.php | 2 ++ Theme/Backend/tag-list.tpl.php | 5 +++-- Theme/Backend/tag-single.tpl.php | 4 +++- tests/Models/TagL11nMapperTest.php | 2 +- tests/Models/TagMapperTest.php | 4 ++-- tests/Models/TagTest.php | 8 +++---- 12 files changed, 37 insertions(+), 40 deletions(-) diff --git a/Admin/Install/db.json b/Admin/Install/db.json index e7ef5f6..2538b84 100755 --- a/Admin/Install/db.json +++ b/Admin/Install/db.json @@ -14,6 +14,12 @@ "type": "VARCHAR(9)", "null": false }, + "tag_icon": { + "name": "tag_icon", + "type": "VARCHAR(255)", + "null": true, + "default": null + }, "tag_type": { "name": "tag_type", "type": "TINYINT(1)", diff --git a/Controller/ApiController.php b/Controller/ApiController.php index 1b5119c..007c6db 100755 --- a/Controller/ApiController.php +++ b/Controller/ApiController.php @@ -95,7 +95,7 @@ final class ApiController extends Controller /** @var Tag $tag */ $tag = TagMapper::get((int) $request->getData('id')); $tag->setTitle((string) ($request->getData('title') ?? $tag->getTitle())); - $tag->setColor(\str_pad($request->getData('color') ?? $tag->getColor(), 9, 'ff', \STR_PAD_RIGHT)); + $tag->color = \str_pad($request->getData('color') ?? $tag->color, 9, 'ff', \STR_PAD_RIGHT); return $tag; } @@ -198,8 +198,9 @@ final class ApiController extends Controller */ private function createTagFromRequest(RequestAbstract $request) : Tag { - $tag = new Tag(); - $tag->setColor(\str_pad($request->getData('color') ?? '#000000ff', 9, 'f')); + $tag = new Tag(); + $tag->color = \str_pad($request->getData('color') ?? '#000000ff', 9, 'f'); + $tag->icon = $request->getData('icon'); return $tag; } diff --git a/Models/Tag.php b/Models/Tag.php index 802ea91..cf6d072 100755 --- a/Models/Tag.php +++ b/Models/Tag.php @@ -51,7 +51,15 @@ class Tag implements \JsonSerializable, ArrayableInterface * @var string * @since 1.0.0 */ - private string $color = '00000000'; + public string $color = '00000000'; + + /** + * Icon. + * + * @var null|string + * @since 1.0.0 + */ + public ?string $icon = null; /** * Creator. @@ -121,32 +129,6 @@ class Tag implements \JsonSerializable, ArrayableInterface $this->type = $type; } - /** - * Get color - * - * @return string - * - * @since 1.0.0 - */ - public function getColor() : string - { - return $this->color; - } - - /** - * Set color - * - * @param string $color Tag article color - * - * @return void - * - * @since 1.0.0 - */ - public function setColor(string $color) : void - { - $this->color = $color; - } - /** * Get id * diff --git a/Models/TagMapper.php b/Models/TagMapper.php index 63f9bb7..2e9c130 100755 --- a/Models/TagMapper.php +++ b/Models/TagMapper.php @@ -40,6 +40,7 @@ final class TagMapper extends DataMapperAbstract protected static array $columns = [ 'tag_id' => ['name' => 'tag_id', 'type' => 'int', 'internal' => 'id'], 'tag_color' => ['name' => 'tag_color', 'type' => 'string', 'internal' => 'color'], + 'tag_icon' => ['name' => 'tag_icon', 'type' => 'string', 'internal' => 'icon'], 'tag_type' => ['name' => 'tag_type', 'type' => 'int', 'internal' => 'type'], 'tag_owner' => ['name' => 'tag_owner', 'type' => 'int', 'internal' => 'owner'], ]; diff --git a/Theme/Backend/Lang/de.lang.php b/Theme/Backend/Lang/de.lang.php index 3afed51..f0197c8 100755 --- a/Theme/Backend/Lang/de.lang.php +++ b/Theme/Backend/Lang/de.lang.php @@ -15,6 +15,7 @@ declare(strict_types=1); return ['Tag' => [ 'Color' => 'Farbe', 'Create' => 'Erstellen', + 'Icon' => 'Icon', 'Language' => 'Sprache', 'List' => 'Liste', 'Tag' => 'Tag', diff --git a/Theme/Backend/Lang/en.lang.php b/Theme/Backend/Lang/en.lang.php index 270759b..1966911 100755 --- a/Theme/Backend/Lang/en.lang.php +++ b/Theme/Backend/Lang/en.lang.php @@ -15,6 +15,7 @@ declare(strict_types=1); return ['Tag' => [ 'Color' => 'Color', 'Create' => 'Create', + 'Icon' => 'Icon', 'Language' => 'Language', 'List' => 'List', 'Tag' => 'Tag', diff --git a/Theme/Backend/tag-create.tpl.php b/Theme/Backend/tag-create.tpl.php index a1a4c35..2b63679 100755 --- a/Theme/Backend/tag-create.tpl.php +++ b/Theme/Backend/tag-create.tpl.php @@ -27,6 +27,8 @@ echo $this->getData('nav')->render(); ?> + +
diff --git a/Theme/Backend/tag-list.tpl.php b/Theme/Backend/tag-list.tpl.php index 1f86e00..01aa96b 100755 --- a/Theme/Backend/tag-list.tpl.php +++ b/Theme/Backend/tag-list.tpl.php @@ -31,14 +31,15 @@ echo $this->getData('nav')->render(); ?> + $value) : ++$count; $url = UriFactory::build('{/prefix}tag/single?{?}&id=' . $value->getId()); ?> +
getHtml('Color'); ?> getHtml('Title'); ?> - getHtml('Color'); ?>
   icon !== null ? '' : '      '; ?>  printHtml($value->getTitle()); ?> -            +
getHtml('Empty', '0', '0'); ?> diff --git a/Theme/Backend/tag-single.tpl.php b/Theme/Backend/tag-single.tpl.php index 36512bc..e8d682d 100755 --- a/Theme/Backend/tag-single.tpl.php +++ b/Theme/Backend/tag-single.tpl.php @@ -31,7 +31,9 @@ echo $this->getData('nav')->render(); ?>
-
+
+
+
diff --git a/tests/Models/TagL11nMapperTest.php b/tests/Models/TagL11nMapperTest.php index 25b2442..a01e387 100644 --- a/tests/Models/TagL11nMapperTest.php +++ b/tests/Models/TagL11nMapperTest.php @@ -33,7 +33,7 @@ class TagL11nMapperTest extends \PHPUnit\Framework\TestCase public function testCR() : void { $tag = new Tag(); - $tag->setColor('#ffffffff'); + $tag->color = '#ffffffff'; $tag->setType(TagType::SINGLE); $id = TagMapper::create($tag); diff --git a/tests/Models/TagMapperTest.php b/tests/Models/TagMapperTest.php index 115939f..db87174 100644 --- a/tests/Models/TagMapperTest.php +++ b/tests/Models/TagMapperTest.php @@ -31,7 +31,7 @@ class TagMapperTest extends \PHPUnit\Framework\TestCase { $tag = new Tag(); $tag->setTitle('TestTag'); - $tag->setColor('#ff0000ff'); + $tag->color = '#ff0000ff'; $tag->setType(TagType::SINGLE); $id = TagMapper::create($tag); @@ -40,7 +40,7 @@ class TagMapperTest extends \PHPUnit\Framework\TestCase $tagR = TagMapper::get($tag->getId()); self::assertEquals($tag->getTitle(), $tagR->getTitle()); - self::assertEquals($tag->getColor(), $tagR->getColor()); + self::assertEquals($tag->color, $tagR->color); self::assertEquals($tag->getType(), $tagR->getType()); } } diff --git a/tests/Models/TagTest.php b/tests/Models/TagTest.php index b98b033..63ddbd7 100644 --- a/tests/Models/TagTest.php +++ b/tests/Models/TagTest.php @@ -40,7 +40,7 @@ class TagTest extends \PHPUnit\Framework\TestCase self::assertEquals(0, $this->tag->getId()); self::assertInstanceOf(NullAccount::class, $this->tag->getOwner()); self::assertEquals(TagType::SINGLE, $this->tag->getType()); - self::assertEquals('00000000', $this->tag->getColor()); + self::assertEquals('00000000', $this->tag->color); self::assertEquals('', $this->tag->getTitle()); } @@ -76,8 +76,8 @@ class TagTest extends \PHPUnit\Framework\TestCase */ public function testColorInputOutput() : void { - $this->tag->setColor('ffffffff'); - self::assertEquals('ffffffff', $this->tag->getColor()); + $this->tag->color = 'ffffffff'; + self::assertEquals('ffffffff', $this->tag->color); } /** @@ -98,7 +98,7 @@ class TagTest extends \PHPUnit\Framework\TestCase { $this->tag->setTitle($t = new TagL11n('Test')); $this->tag->setOwner($a = new NullAccount(2)); - $this->tag->setColor('ffffffff'); + $this->tag->color = 'ffffffff'; $this->tag->setType(TagType::SHARED); self::assertEquals(