diff --git a/config/sql/se/Tags.sql b/config/sql/se/Tags.sql index 863c7f1e..b817640d 100644 --- a/config/sql/se/Tags.sql +++ b/config/sql/se/Tags.sql @@ -1,6 +1,8 @@ CREATE TABLE IF NOT EXISTS `Tags` ( `TagId` int(10) unsigned NOT NULL AUTO_INCREMENT, `Name` varchar(255) NOT NULL, + `Type` enum('artwork', 'ebook') DEFAULT 'artwork', PRIMARY KEY (`TagId`), - UNIQUE KEY `idxUnique` (`Name`) + KEY `index1` (`Name`), + KEY `index2` (`Type`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; diff --git a/lib/ArtworkTag.php b/lib/ArtworkTag.php index d756b671..7c44121b 100644 --- a/lib/ArtworkTag.php +++ b/lib/ArtworkTag.php @@ -3,6 +3,10 @@ use function Safe\preg_match; use function Safe\preg_replace; class ArtworkTag extends Tag{ + public function __construct(){ + $this->Type = 'artwork'; + } + // ******* // GETTERS // ******* @@ -41,6 +45,10 @@ class ArtworkTag extends Tag{ $error->Add(new Exceptions\InvalidArtworkTagNameException()); } + if($this->Type != 'artwork'){ + $error->Add(new Exceptions\InvalidArtworkTagTypeException($this->Type)); + } + if($error->HasExceptions){ throw $error; } @@ -53,9 +61,10 @@ class ArtworkTag extends Tag{ $this->Validate(); Db::Query(' - INSERT into Tags (Name) - values (?) - ', [$this->Name]); + INSERT into Tags (Name, Type) + values (?, + ?) + ', [$this->Name, $this->Type]); $this->TagId = Db::GetLastInsertedId(); } @@ -67,6 +76,7 @@ class ArtworkTag extends Tag{ SELECT * from Tags where Name = ? + and Type = "artwork" ', [$artworkTag->Name], ArtworkTag::class); if(isset($result[0])){ diff --git a/lib/EbookTag.php b/lib/EbookTag.php index fd334bfa..e091a0ad 100644 --- a/lib/EbookTag.php +++ b/lib/EbookTag.php @@ -1,5 +1,9 @@ Type = 'ebook'; + } + // ******* // GETTERS // ******* @@ -33,6 +37,10 @@ class EbookTag extends Tag{ $error->Add(new Exceptions\StringTooLongException('Ebook tag: '. $this->Name)); } + if($this->Type != 'ebook'){ + $error->Add(new Exceptions\InvalidEbookTagTypeException($this->Type)); + } + if($error->HasExceptions){ throw $error; } @@ -45,9 +53,10 @@ class EbookTag extends Tag{ $this->Validate(); Db::Query(' - INSERT into Tags (Name) - values (?) - ', [$this->Name]); + INSERT into Tags (Name, Type) + values (?, + ?) + ', [$this->Name, $this->Type]); $this->TagId = Db::GetLastInsertedId(); } diff --git a/lib/Exceptions/InvalidArtworkTagTypeException.php b/lib/Exceptions/InvalidArtworkTagTypeException.php new file mode 100644 index 00000000..4a9ecd93 --- /dev/null +++ b/lib/Exceptions/InvalidArtworkTagTypeException.php @@ -0,0 +1,15 @@ +message .= ' Type provided: ' . $tagType; + } + + parent::__construct($this->message); + } +} diff --git a/lib/Exceptions/InvalidEbookTagTypeException.php b/lib/Exceptions/InvalidEbookTagTypeException.php new file mode 100644 index 00000000..922467b8 --- /dev/null +++ b/lib/Exceptions/InvalidEbookTagTypeException.php @@ -0,0 +1,15 @@ +message .= ' Type provided: ' . $tagType; + } + + parent::__construct($this->message); + } +} diff --git a/lib/Library.php b/lib/Library.php index a8193204..bfbbcafd 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -178,10 +178,10 @@ class Library{ */ public static function GetTags(): array{ $tags = Db::Query(' - SELECT distinct t.* + SELECT * from Tags t - inner join EbookTags et using (TagId) - order by t.Name + where Type = "ebook" + order by Name ', [], EbookTag::class); return $tags; diff --git a/lib/Tag.php b/lib/Tag.php index 61a3a04d..e81f3286 100644 --- a/lib/Tag.php +++ b/lib/Tag.php @@ -8,6 +8,7 @@ class Tag{ public int $TagId; public string $Name; + public string $Type; protected ?string $_UrlName = null; protected ?string $_Url = null; }