mirror of
https://github.com/standardebooks/web.git
synced 2025-07-18 04:16:38 -04:00
Sort collections by their sequence number
This commit is contained in:
parent
f7e3a5c39f
commit
8efec57abd
3 changed files with 15 additions and 3 deletions
|
@ -2,6 +2,7 @@
|
|||
class Collection{
|
||||
public $Name;
|
||||
public $Url;
|
||||
public $SequenceNumber = null;
|
||||
|
||||
public function __construct(string $name){
|
||||
$this->Name = $name;
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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-/'));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue