mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 19:06:49 -04:00
Get carousel books from the DB
This commit is contained in:
parent
402dae95ff
commit
2d5e66f2f2
2 changed files with 30 additions and 40 deletions
|
@ -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>
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue