Sort collections by their sequence number

This commit is contained in:
Alex Cabal 2020-05-21 15:49:48 -05:00
parent f7e3a5c39f
commit 8efec57abd
3 changed files with 15 additions and 3 deletions

View file

@ -2,6 +2,7 @@
class Collection{ class Collection{
public $Name; public $Name;
public $Url; public $Url;
public $SequenceNumber = null;
public function __construct(string $name){ public function __construct(string $name){
$this->Name = $name; $this->Name = $name;

View file

@ -166,7 +166,11 @@ class Ebook{
// Get SE collections // Get SE collections
foreach($xml->xpath('/package/metadata/meta[@property="belongs-to-collection"]') ?: [] as $collection){ foreach($xml->xpath('/package/metadata/meta[@property="belongs-to-collection"]') ?: [] as $collection){
$this->Collections[] = new Collection($collection); $c = new Collection($collection);
foreach($xml->xpath('/package/metadata/meta[@refines="#' . $collection->attributes()->id . '"][@property="group-position"]') ?: [] as $s){
$c->SequenceNumber = (int)$s;
}
$this->Collections[] = $c;
} }
// Get LoC tags // Get LoC tags

View file

@ -168,8 +168,13 @@ class Library{
$collections[$lcCollection] = []; $collections[$lcCollection] = [];
} }
if($collection->SequenceNumber !== null){
$collections[$lcCollection][$collection->SequenceNumber] = $ebook;
}
else{
$collections[$lcCollection][] = $ebook; $collections[$lcCollection][] = $ebook;
} }
}
// Create the tags cache // Create the tags cache
foreach($ebook->Tags as $tag){ foreach($ebook->Tags as $tag){
@ -266,7 +271,9 @@ class Library{
// Now store various collections // Now store various collections
apcu_delete(new APCUIterator('/^collection-/')); apcu_delete(new APCUIterator('/^collection-/'));
foreach($collections as $collection => $ebooks){ foreach($collections as $collection => $ebooks){
apcu_store('collection-' . $collection, $ebooks); // Sort the array by key, then reindex to 0 with array_values
ksort($ebooks);
apcu_store('collection-' . $collection, array_values($ebooks));
} }
apcu_delete(new APCUIterator('/^tag-/')); apcu_delete(new APCUIterator('/^tag-/'));