mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -04:00
Refactor Library::FilterEbooks and Template::SearchForm to accept EbookSort
This commit is contained in:
parent
980ed8cea9
commit
d95d9b3349
3 changed files with 13 additions and 17 deletions
|
@ -19,12 +19,12 @@ class Library{
|
|||
* @param EbookSort $sort
|
||||
* @return array<Ebook>
|
||||
*/
|
||||
public static function FilterEbooks(string $query = null, array $tags = [], string $sort = null){
|
||||
public static function FilterEbooks(string $query = null, array $tags = [], EbookSort $sort = null){
|
||||
$ebooks = Library::GetEbooks();
|
||||
$matches = $ebooks;
|
||||
|
||||
if($sort === null){
|
||||
$sort = EbookSort::Newest->value;
|
||||
$sort = EbookSort::Newest;
|
||||
}
|
||||
|
||||
if(sizeof($tags) > 0 && !in_array('all', $tags)){ // 0 tags means "all ebooks"
|
||||
|
@ -51,13 +51,13 @@ class Library{
|
|||
}
|
||||
|
||||
switch($sort){
|
||||
case EbookSort::AuthorAlpha->value:
|
||||
case EbookSort::AuthorAlpha:
|
||||
usort($matches, function($a, $b){
|
||||
return strcmp(mb_strtolower($a->Authors[0]->SortName), mb_strtolower($b->Authors[0]->SortName));
|
||||
});
|
||||
break;
|
||||
|
||||
case EbookSort::Newest->value:
|
||||
case EbookSort::Newest:
|
||||
usort($matches, function($a, $b){
|
||||
if($a->Created < $b->Created){
|
||||
return -1;
|
||||
|
@ -73,7 +73,7 @@ class Library{
|
|||
$matches = array_reverse($matches);
|
||||
break;
|
||||
|
||||
case EbookSort::ReadingEase->value:
|
||||
case EbookSort::ReadingEase:
|
||||
usort($matches, function($a, $b){
|
||||
if($a->ReadingEase < $b->ReadingEase){
|
||||
return -1;
|
||||
|
@ -89,7 +89,7 @@ class Library{
|
|||
$matches = array_reverse($matches);
|
||||
break;
|
||||
|
||||
case EbookSort::Length->value:
|
||||
case EbookSort::Length:
|
||||
usort($matches, function($a, $b){
|
||||
if($a->WordCount < $b->WordCount){
|
||||
return -1;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue