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{
public $Name;
public $Url;
public $SequenceNumber = null;
public function __construct(string $name){
$this->Name = $name;

View file

@ -166,7 +166,11 @@ class Ebook{
// Get SE collections
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

View file

@ -168,7 +168,12 @@ class Library{
$collections[$lcCollection] = [];
}
$collections[$lcCollection][] = $ebook;
if($collection->SequenceNumber !== null){
$collections[$lcCollection][$collection->SequenceNumber] = $ebook;
}
else{
$collections[$lcCollection][] = $ebook;
}
}
// Create the tags cache
@ -266,7 +271,9 @@ class Library{
// Now store various collections
apcu_delete(new APCUIterator('/^collection-/'));
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-/'));