mirror of
https://github.com/standardebooks/web.git
synced 2025-07-08 07:40:39 -04:00
Improve how collections are organized and internally and printed to HTML
This commit is contained in:
parent
c8cacc4ace
commit
aed7db7fc1
4 changed files with 23 additions and 15 deletions
|
@ -7,6 +7,6 @@ class Collection{
|
||||||
|
|
||||||
public function __construct(string $name){
|
public function __construct(string $name){
|
||||||
$this->Name = $name;
|
$this->Name = $name;
|
||||||
$this->Url = '/collections/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText(Formatter::RemoveDiacritics($this->Name))));
|
$this->Url = '/collections/' . Formatter::MakeUrlSafe($this->Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
3
lib/InvalidCollectionException.php
Normal file
3
lib/InvalidCollectionException.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?
|
||||||
|
class InvalidCollectionException extends \Exception{
|
||||||
|
}
|
|
@ -163,16 +163,16 @@ class Library{
|
||||||
|
|
||||||
// Create the collections cache
|
// Create the collections cache
|
||||||
foreach($ebook->Collections as $collection){
|
foreach($ebook->Collections as $collection){
|
||||||
$lcCollection = strtolower(Formatter::RemoveDiacritics($collection->Name));
|
$urlSafeCollection = Formatter::MakeUrlSafe($collection->Name);
|
||||||
if(!array_key_exists($lcCollection, $collections)){
|
if(!array_key_exists($urlSafeCollection, $collections)){
|
||||||
$collections[$lcCollection] = [];
|
$collections[$urlSafeCollection] = [];
|
||||||
}
|
}
|
||||||
|
|
||||||
if($collection->SequenceNumber !== null){
|
if($collection->SequenceNumber !== null){
|
||||||
$collections[$lcCollection][$collection->SequenceNumber] = $ebook;
|
$collections[$urlSafeCollection][$collection->SequenceNumber] = $ebook;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$collections[$lcCollection][] = $ebook;
|
$collections[$urlSafeCollection][] = $ebook;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,21 +40,26 @@ try{
|
||||||
$ebooks = array_slice($ebooks, ($page - 1) * EBOOKS_PER_PAGE, EBOOKS_PER_PAGE);
|
$ebooks = array_slice($ebooks, ($page - 1) * EBOOKS_PER_PAGE, EBOOKS_PER_PAGE);
|
||||||
}
|
}
|
||||||
elseif($collection !== null){
|
elseif($collection !== null){
|
||||||
$collection = strtolower(str_replace('-', ' ', Formatter::RemoveDiacritics($collection)));
|
|
||||||
$ebooks = Library::GetEbooksByCollection($collection);
|
$ebooks = Library::GetEbooksByCollection($collection);
|
||||||
|
$collectionObject = null;
|
||||||
|
// Get the *actual* name of the collection, in case there are accent marks (like "Arsène Lupin")
|
||||||
if(sizeof($ebooks) > 0){
|
if(sizeof($ebooks) > 0){
|
||||||
// Get the *actual* name of the collection, in case there are accent marks (like "Arsène Lupin")
|
|
||||||
foreach($ebooks[0]->Collections as $c){
|
foreach($ebooks[0]->Collections as $c){
|
||||||
if($collection == strtolower(str_replace('-', ' ', Formatter::RemoveDiacritics($c->Name)))){
|
if($collection == Formatter::MakeUrlSafe($c->Name)){
|
||||||
$collection = (string)$c->Name; // Explicit typecast to string to satisfy PHPStan
|
$collectionObject = $c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$collectionName = ucwords(preg_replace('/^The /ius', '', $collection) ?? '');
|
if($collectionObject !== null){
|
||||||
$pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
$collectionName = preg_replace('/^The /ius', '', $collectionObject->Name) ?? '';
|
||||||
$pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
$collectionType = $collectionObject->Type ?? 'collection';
|
||||||
$pageHeader = 'Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' collection';
|
$pageTitle = 'Browse ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
|
||||||
|
$pageDescription = 'A list of ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
|
||||||
|
$pageHeader = 'Ebooks in the ' . Formatter::ToPlainText($collectionName) . ' ' . $collectionType;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
throw new InvalidCollectionException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$pageTitle = 'Browse Standard Ebooks';
|
$pageTitle = 'Browse Standard Ebooks';
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue