Create method for getting sets of ebooks

This commit is contained in:
Alex Cabal 2025-06-03 10:31:26 -05:00
parent cd4be0a3e3
commit 8a1a64629d
7 changed files with 22 additions and 16 deletions

View file

@ -2280,9 +2280,9 @@ final class Ebook{
} }
/** /**
* Queries for books in a collection. * Get `Ebook`s in a collection.
* *
* Puts ebooks without a `SequenceNumber` at the end of the list, which is more common in a collection with both published and placeholder ebooks. * Puts `Ebook`s without a `SequenceNumber` at the end of the list, which is more common in a collection with both published and placeholder ebooks.
* *
* @return array<Ebook> * @return array<Ebook>
*/ */
@ -2299,9 +2299,10 @@ final class Ebook{
} }
/** /**
* Queries for related to books to be shown, e.g., in a carousel. * Get related `Ebook`s, e.g., in a carousel.
*
* Does not include `EbookPlaceholder`s, because they're not useful for browsing.
* *
* Filters out placeholder books because they are not useful for browsing.
* @return array<Ebook> * @return array<Ebook>
*/ */
public static function GetAllByRelated(Ebook $ebook, int $count, ?EbookTag $relatedTag): array{ public static function GetAllByRelated(Ebook $ebook, int $count, ?EbookTag $relatedTag): array{
@ -2331,6 +2332,17 @@ final class Ebook{
return $relatedEbooks; return $relatedEbooks;
} }
/**
* Get all `Ebook`s in a set of `EbookId`s.
*
* @param array<int> $ebookIds
*
* @return array<Ebook>
*/
public static function GetAllBySet(array $ebookIds): array{
return Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
}
/** /**
* @param array<string> $tags * @param array<string> $tags
* *

View file

@ -1,6 +1,5 @@
<? <?
$ebookIds = [2321, 1080, 185, 1090, 431]; $carousel = Ebook::GetAllBySet([2321, 1080, 185, 1090, 431]);
$carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
?> ?>
<?= Template::Header(title: 'A Kind of Bolshevism in an Uncanny Bookshop', css: ['/css/blog.css']) ?> <?= Template::Header(title: 'A Kind of Bolshevism in an Uncanny Bookshop', css: ['/css/blog.css']) ?>
<main> <main>

View file

@ -1,6 +1,5 @@
<? <?
$ebookIds = [1085, 1052]; $carousel = Ebook::GetAllBySet([1085, 1052]);
$carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
?> ?>
<?= Template::Header(title: 'Death and Beauty in the Alps', css: ['/css/blog.css']) ?> <?= Template::Header(title: 'Death and Beauty in the Alps', css: ['/css/blog.css']) ?>
<main> <main>

View file

@ -1,6 +1,5 @@
<? <?
$ebookIds = [288, 485, 289, 908, 565, 2114]; $carousel = Ebook::GetAllBySet([288, 485, 289, 908, 565, 2114]);
$carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
?> ?>
<?= Template::Header(title: 'Edith Whartons Vision of Literary Art', css: ['/css/blog.css']) ?> <?= Template::Header(title: 'Edith Whartons Vision of Literary Art', css: ['/css/blog.css']) ?>
<main> <main>

View file

@ -1,6 +1,5 @@
<? <?
$ebookIds = [565, 778, 561, 1059]; $carousel = Ebook::GetAllBySet([565, 778, 561, 1059]);
$carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
?> ?>
<?= Template::Header(title: 'Joyces Ulysses, the Rubáiyát, and “Yes”', css: ['/css/blog.css']) ?> <?= Template::Header(title: 'Joyces Ulysses, the Rubáiyát, and “Yes”', css: ['/css/blog.css']) ?>
<main> <main>

View file

@ -1,6 +1,5 @@
<? <?
$ebookIds = [981, 561, 833]; $carousel = Ebook::GetAllBySet([981, 561, 833]);
$carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
?> ?>
<?= Template::Header(title: 'Of Human Bondage, Spinoza, and the Meaning of Life', css: ['/css/blog.css']) ?> <?= Template::Header(title: 'Of Human Bondage, Spinoza, and the Meaning of Life', css: ['/css/blog.css']) ?>
<main> <main>

View file

@ -1,6 +1,5 @@
<? <?
$ebookIds = [415, 607]; $carousel = Ebook::GetAllBySet([415, 607]);
$carousel = Db::Query('SELECT * from Ebooks where EbookId in ' . Db::CreateSetSql($ebookIds), $ebookIds, Ebook::class);
?> ?>
<?= Template::Header(title: 'The Ugly Duckling and the Carmelite in Middlemarch', css: ['/css/blog.css']) ?> <?= Template::Header(title: 'The Ugly Duckling and the Carmelite in Middlemarch', css: ['/css/blog.css']) ?>
<main> <main>