mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 10:31:59 -04:00
Refactor Library::FilterArtwork and artworks/index.php to accept ArtworkSort
This commit is contained in:
parent
004a4a27c3
commit
94dce1009a
2 changed files with 10 additions and 14 deletions
|
@ -159,10 +159,10 @@ class Library{
|
|||
/**
|
||||
* @param string $query
|
||||
* @param string $status
|
||||
* @param string $sort
|
||||
* @param ArtworkSort $sort
|
||||
* @return Array<mixed>
|
||||
*/
|
||||
public static function FilterArtwork(string $query = null, string $status = null, string $sort = null, int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{
|
||||
public static function FilterArtwork(string $query = null, string $status = null, ArtworkSort $sort = null, int $submitterUserId = null, int $page = 1, int $perPage = ARTWORK_PER_PAGE): array{
|
||||
// Returns an array of:
|
||||
// ['artworks'] => Array<Artwork>,
|
||||
// ['artworksCount'] => int
|
||||
|
@ -210,10 +210,10 @@ class Library{
|
|||
}
|
||||
|
||||
$orderBy = 'art.Created desc';
|
||||
if($sort == ArtworkSort::ArtistAlpha->value){
|
||||
if($sort == ArtworkSort::ArtistAlpha){
|
||||
$orderBy = 'a.Name';
|
||||
}
|
||||
elseif($sort == ArtworkSort::CompletedNewest->value){
|
||||
elseif($sort == ArtworkSort::CompletedNewest){
|
||||
$orderBy = 'art.CompletedYear desc';
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ $query = HttpInput::Str(GET, 'query');
|
|||
$queryEbookUrl = HttpInput::Str(GET, 'query-ebook-url');
|
||||
$status = HttpInput::Str(GET, 'status');
|
||||
$filterArtworkStatus = $status;
|
||||
$sort = HttpInput::Str(GET, 'sort');
|
||||
$sort = ArtworkSort::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
|
||||
$pages = 0;
|
||||
$totalArtworkCount = 0;
|
||||
$pageDescription = '';
|
||||
|
@ -26,11 +26,7 @@ try{
|
|||
|
||||
// If we're passed string values that are the same as the defaults,
|
||||
// set them to null so that we can have cleaner query strings in the navigation footer
|
||||
if($sort !== null){
|
||||
$sort = mb_strtolower($sort);
|
||||
}
|
||||
|
||||
if($sort == 'created-newest'){
|
||||
if($sort == ArtworkSort::CreatedNewest){
|
||||
$sort = null;
|
||||
}
|
||||
|
||||
|
@ -94,7 +90,7 @@ try{
|
|||
}
|
||||
|
||||
if($sort !== null){
|
||||
$queryStringParams['sort'] = $sort;
|
||||
$queryStringParams['sort'] = $sort->value;
|
||||
}
|
||||
|
||||
if($perPage !== ARTWORK_PER_PAGE){
|
||||
|
@ -142,9 +138,9 @@ catch(Exceptions\PageOutOfBoundsException){
|
|||
<span>Sort</span>
|
||||
<span>
|
||||
<select name="sort">
|
||||
<option value="<?= ArtworkSort::CreatedNewest->value ?>"<? if($sort == ArtworkSort::CreatedNewest->value){ ?> selected="selected"<? } ?>>Date added (new → old)</option>
|
||||
<option value="<?= ArtworkSort::ArtistAlpha->value ?>"<? if($sort == ArtworkSort::ArtistAlpha->value){ ?> selected="selected"<? } ?>>Artist name (a → z)</option>
|
||||
<option value="<?= ArtworkSort::CompletedNewest->value ?>"<? if($sort == ArtworkSort::CompletedNewest->value){ ?> selected="selected"<? } ?>>Date of artwork completion (new → old)</option>
|
||||
<option value="<?= ArtworkSort::CreatedNewest->value ?>"<? if($sort == ArtworkSort::CreatedNewest){ ?> selected="selected"<? } ?>>Date added (new → old)</option>
|
||||
<option value="<?= ArtworkSort::ArtistAlpha->value ?>"<? if($sort == ArtworkSort::ArtistAlpha){ ?> selected="selected"<? } ?>>Artist name (a → z)</option>
|
||||
<option value="<?= ArtworkSort::CompletedNewest->value ?>"<? if($sort == ArtworkSort::CompletedNewest){ ?> selected="selected"<? } ?>>Date of artwork completion (new → old)</option>
|
||||
</select>
|
||||
</span>
|
||||
</label>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue