Ebook tags: Store UrlName so it can be queried

This commit is contained in:
Mike Colagrosso 2024-09-09 22:34:36 -06:00 committed by Alex Cabal
parent 7339255d5f
commit 7d8cfd351e
3 changed files with 7 additions and 4 deletions

View file

@ -1,8 +1,10 @@
CREATE TABLE IF NOT EXISTS `Tags` ( CREATE TABLE IF NOT EXISTS `Tags` (
`TagId` int(10) unsigned NOT NULL AUTO_INCREMENT, `TagId` int(10) unsigned NOT NULL AUTO_INCREMENT,
`Name` varchar(255) NOT NULL, `Name` varchar(255) NOT NULL,
`UrlName` varchar(255) NULL,
`Type` enum('artwork', 'ebook') DEFAULT 'artwork', `Type` enum('artwork', 'ebook') DEFAULT 'artwork',
PRIMARY KEY (`TagId`), PRIMARY KEY (`TagId`),
KEY `index1` (`Name`), KEY `index1` (`Name`),
KEY `index2` (`Type`) KEY `index2` (`Type`),
KEY `index3` (`UrlName`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

View file

@ -53,10 +53,11 @@ class EbookTag extends Tag{
$this->Validate(); $this->Validate();
Db::Query(' Db::Query('
INSERT into Tags (Name, Type) INSERT into Tags (Name, UrlName, Type)
values (?, values (?,
?,
?) ?)
', [$this->Name, $this->Type]); ', [$this->Name, $this->UrlName, $this->Type]);
$this->TagId = Db::GetLastInsertedId(); $this->TagId = Db::GetLastInsertedId();
} }

View file

@ -40,7 +40,7 @@ class Library{
if(sizeof($tags) > 0 && !in_array('all', $tags)){ // 0 tags means "all ebooks" if(sizeof($tags) > 0 && !in_array('all', $tags)){ // 0 tags means "all ebooks"
$joinTags = 'inner join EbookTags et using (EbookId) $joinTags = 'inner join EbookTags et using (EbookId)
inner join Tags t using (TagId)'; inner join Tags t using (TagId)';
$whereCondition .= ' AND t.Name in ' . Db::CreateSetSql($tags) . ' '; $whereCondition .= ' AND t.UrlName in ' . Db::CreateSetSql($tags) . ' ';
$params = $tags; $params = $tags;
} }