From 94dce1009a78da2e3b4086830ba12a53b733cc6d Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Tue, 30 Jan 2024 00:17:00 -0700 Subject: [PATCH] Refactor Library::FilterArtwork and artworks/index.php to accept ArtworkSort --- lib/Library.php | 8 ++++---- www/artworks/index.php | 16 ++++++---------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/lib/Library.php b/lib/Library.php index 6b0f464c..b26bc47a 100644 --- a/lib/Library.php +++ b/lib/Library.php @@ -159,10 +159,10 @@ class Library{ /** * @param string $query * @param string $status - * @param string $sort + * @param ArtworkSort $sort * @return Array */ - 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, // ['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'; } diff --git a/www/artworks/index.php b/www/artworks/index.php index ac99256c..05c195dc 100644 --- a/www/artworks/index.php +++ b/www/artworks/index.php @@ -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){ Sort