Get carousel books from the DB

This commit is contained in:
Mike Colagrosso 2024-06-29 11:41:56 -06:00 committed by Alex Cabal
parent 402dae95ff
commit 2d5e66f2f2
2 changed files with 30 additions and 40 deletions

View file

@ -126,19 +126,6 @@ class Library{
return self::GetFromApcu('author-' . $wwwFilesystemPath);
}
/**
* @return array<Ebook>
*/
public static function GetEbooksByTag(string $tag): array{
try{
/** @var array<Ebook> */
return apcu_fetch('tag-' . $tag) ?? [];
}
catch(Safe\Exceptions\ApcuException){
return [];
}
}
/**
* @return array<Collection>
* @throws Exceptions\AppException
@ -173,6 +160,34 @@ class Library{
return $ebooks;
}
/**
* @return array<Ebook>
*/
public static function GetRelatedEbooks(Ebook $ebook, int $count, ?EbookTag $relatedTag): array{
if($relatedTag !== null){
$relatedEbooks = Db::Query('
SELECT e.*
from Ebooks e
inner join EbookTags et using (EbookId)
where et.TagId = ?
and et.EbookId != ?
order by RAND()
limit ?
', [$relatedTag->TagId, $ebook->EbookId, $count], Ebook::class);
}
else{
$relatedEbooks = Db::Query('
SELECT *
from Ebooks
where EbookId != ?
order by RAND()
limit ?
', [$ebook->EbookId, $count], Ebook::class);
}
return $relatedEbooks;
}
/**
* @return array<EbookTag>
*/