mirror of
https://github.com/standardebooks/web.git
synced 2025-07-19 12:54:48 -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
|
@ -12,6 +12,7 @@ $scanSources = [];
|
|||
$otherSources = [];
|
||||
$carousel = [];
|
||||
$carouselTag = null;
|
||||
$targetCarouselSize = 5;
|
||||
|
||||
try{
|
||||
$urlPath = trim(str_replace('.', '', HttpInput::Str(GET, 'url-path') ?? ''), '/'); // Contains the portion of the URL (without query string) that comes after https://standardebooks.org/ebooks/
|
||||
|
@ -64,36 +65,10 @@ try{
|
|||
}
|
||||
}
|
||||
|
||||
// Generate the bottom carousel.
|
||||
// Pick a random tag from this ebook, and get ebooks in the same tag
|
||||
$ebooks = [];
|
||||
if(sizeof($ebook->Tags) > 0){
|
||||
$carouselTag = $ebook->Tags[rand(0, sizeof($ebook->Tags) - 1)];
|
||||
$ebooks = Library::GetEbooksByTag(strtolower($carouselTag->Name));
|
||||
}
|
||||
else{
|
||||
$ebooks = Library::GetEbooks();
|
||||
}
|
||||
|
||||
shuffle($ebooks);
|
||||
|
||||
$targetCarouselSize = 5;
|
||||
// Use <= here because we want to exclude the ebook we're looking at from the carousel.
|
||||
// One of the matching ebooks will always be the current ebook.
|
||||
if(sizeof($ebooks) <= $targetCarouselSize){
|
||||
$targetCarouselSize = sizeof($ebooks) - 1;
|
||||
}
|
||||
|
||||
if($targetCarouselSize > 0){
|
||||
$i = 0;
|
||||
while(sizeof($carousel) < $targetCarouselSize){
|
||||
if(isset($ebooks[$i]) && $ebooks[$i]->Url !== $ebook->Url){
|
||||
$carousel[] = $ebooks[$i];
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
}
|
||||
$carousel = Library::GetRelatedEbooks($ebook, $targetCarouselSize, $carouselTag);
|
||||
}
|
||||
catch(Exceptions\SeeOtherEbookException $ex){
|
||||
http_response_code(301);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue