Convert SORT_COVER_ constants to an enum

This commit is contained in:
Mike Colagrosso 2024-01-29 23:20:29 -07:00 committed by Alex Cabal
parent 09b4385100
commit 004a4a27c3
4 changed files with 11 additions and 8 deletions

6
lib/ArtworkSort.php Normal file
View file

@ -0,0 +1,6 @@
<?
enum ArtworkSort: string{
case CreatedNewest = 'created-newest';
case ArtistAlpha = 'artist-alpha';
case CompletedNewest = 'completed-newest';
}

View file

@ -44,9 +44,6 @@ const ARTWORK_MAX_STRING_LENGTH = 250;
const ARTWORK_MAX_TAGS = 15;
const ARTWORK_IMAGE_MINIMUM_WIDTH = 300;
const ARTWORK_IMAGE_MINIMUM_HEIGHT = 300;
const SORT_COVER_ARTWORK_CREATED_NEWEST = 'created-newest';
const SORT_COVER_ARTIST_ALPHA = 'artist-alpha';
const SORT_COVER_ARTWORK_COMPLETED_NEWEST = 'completed-newest';
const CAPTCHA_IMAGE_HEIGHT = 72;
const CAPTCHA_IMAGE_WIDTH = 230;

View file

@ -210,10 +210,10 @@ class Library{
}
$orderBy = 'art.Created desc';
if($sort == SORT_COVER_ARTIST_ALPHA){
if($sort == ArtworkSort::ArtistAlpha->value){
$orderBy = 'a.Name';
}
elseif($sort == SORT_COVER_ARTWORK_COMPLETED_NEWEST){
elseif($sort == ArtworkSort::CompletedNewest->value){
$orderBy = 'art.CompletedYear desc';
}

View file

@ -142,9 +142,9 @@ catch(Exceptions\PageOutOfBoundsException){
<span>Sort</span>
<span>
<select name="sort">
<option value="<?= SORT_COVER_ARTWORK_CREATED_NEWEST ?>"<? if($sort == SORT_COVER_ARTWORK_CREATED_NEWEST){ ?> selected="selected"<? } ?>>Date added (new &#x2192; old)</option>
<option value="<?= SORT_COVER_ARTIST_ALPHA ?>"<? if($sort == SORT_COVER_ARTIST_ALPHA){ ?> selected="selected"<? } ?>>Artist name (a &#x2192; z)</option>
<option value="<?= SORT_COVER_ARTWORK_COMPLETED_NEWEST ?>"<? if($sort == SORT_COVER_ARTWORK_COMPLETED_NEWEST){ ?> selected="selected"<? } ?>>Date of artwork completion (new &#x2192; old)</option>
<option value="<?= ArtworkSort::CreatedNewest->value ?>"<? if($sort == ArtworkSort::CreatedNewest->value){ ?> selected="selected"<? } ?>>Date added (new &#x2192; old)</option>
<option value="<?= ArtworkSort::ArtistAlpha->value ?>"<? if($sort == ArtworkSort::ArtistAlpha->value){ ?> selected="selected"<? } ?>>Artist name (a &#x2192; z)</option>
<option value="<?= ArtworkSort::CompletedNewest->value ?>"<? if($sort == ArtworkSort::CompletedNewest->value){ ?> selected="selected"<? } ?>>Date of artwork completion (new &#x2192; old)</option>
</select>
</span>
</label>