From 8cc661015c42ee8807f66b4f551efa1adf5723ef Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Wed, 8 May 2024 11:17:53 -0500 Subject: [PATCH] Add enum for view type and fix some type hints --- lib/Artist.php | 7 +++++-- lib/ArtworkTag.php | 8 -------- lib/Constants.php | 3 --- lib/ViewType.php | 5 +++++ templates/EbookGrid.php | 6 +++--- templates/SearchForm.php | 4 ++-- www/artworks/post.php | 2 -- www/collections/get.php | 2 +- www/ebooks/author.php | 2 +- www/ebooks/index.php | 11 +++-------- 10 files changed, 20 insertions(+), 30 deletions(-) create mode 100644 lib/ViewType.php diff --git a/lib/Artist.php b/lib/Artist.php index ed6d165a..93fadcf6 100644 --- a/lib/Artist.php +++ b/lib/Artist.php @@ -6,9 +6,12 @@ use Safe\DateTimeImmutable; * @property ?string $UrlName * @property ?string $Url * @property ?array $AlternateNames - * @property ?array $_AlternateNames */ class Artist{ + /** + * @var array $_AlternateNames + */ + use Traits\Accessor; public ?int $ArtistId = null; @@ -18,7 +21,7 @@ class Artist{ protected ?int $_DeathYear = null; protected ?string $_UrlName = null; protected ?string $_Url = null; - protected ?array $_AlternateNames = null; + protected $_AlternateNames = null; // Don't type hint this here, otherwise PHPStan will complain // ******* // SETTERS diff --git a/lib/ArtworkTag.php b/lib/ArtworkTag.php index 6294a667..b74cdffd 100644 --- a/lib/ArtworkTag.php +++ b/lib/ArtworkTag.php @@ -3,14 +3,6 @@ use function Safe\preg_match; use function Safe\preg_replace; class ArtworkTag extends Tag{ - // ******* - // SETTERS - // ******* - - // protected function SetName($name): void{ - // $this->_Name = - // } - // ******* // GETTERS // ******* diff --git a/lib/Constants.php b/lib/Constants.php index c2575377..0e395c49 100644 --- a/lib/Constants.php +++ b/lib/Constants.php @@ -72,9 +72,6 @@ const HTTP_PUT = 3; const HTTP_DELETE = 4; const HTTP_HEAD = 5; -const VIEW_GRID = 'grid'; -const VIEW_LIST = 'list'; - const AVERAGE_READING_WORDS_PER_MINUTE = 275; const PAYMENT_CHANNEL_FA = 0; diff --git a/lib/ViewType.php b/lib/ViewType.php new file mode 100644 index 00000000..e0d66d74 --- /dev/null +++ b/lib/ViewType.php @@ -0,0 +1,5 @@ + -
    typeof="schema:BookSeries" about="Url ?>"> +
      typeof="schema:BookSeries" about="Url ?>"> @@ -26,7 +26,7 @@ $ebooks = $ebooks ?? [];

      Title) ?>

      - + Authors as $author){ ?>

      Name != 'Anonymous'){ ?>Name) ?>

      diff --git a/templates/SearchForm.php b/templates/SearchForm.php index a4ca171d..46f6a639 100644 --- a/templates/SearchForm.php +++ b/templates/SearchForm.php @@ -28,8 +28,8 @@ $allSelected = sizeof($tags) == 0 || in_array('all', $tags); View diff --git a/www/artworks/post.php b/www/artworks/post.php index 0060601e..720a5376 100644 --- a/www/artworks/post.php +++ b/www/artworks/post.php @@ -155,8 +155,6 @@ catch(Exceptions\ArtworkNotFoundException){ Template::Emit404(); } catch(Exceptions\AppException $exception){ - $artwork = $artwork ?? null; - $_SESSION['artwork'] = $artwork; $_SESSION['exception'] = $exception; diff --git a/www/collections/get.php b/www/collections/get.php index ecee2588..449a1a8b 100644 --- a/www/collections/get.php +++ b/www/collections/get.php @@ -49,7 +49,7 @@ catch(Exceptions\CollectionNotFoundException){

      No ebooks matched your filters. You can try different filters, or browse all of our ebooks.

      - $ebooks, 'view' => VIEW_GRID, 'collection' => $collectionObject]) ?> + $ebooks, 'view' => ViewType::Grid, 'collection' => $collectionObject]) ?>

      We also have bulk ebook downloads and a list of collections available, as well as ebook catalog feeds for use directly in your ereader app or RSS reader.

      diff --git a/www/ebooks/author.php b/www/ebooks/author.php index b7401244..c3ac4fdb 100644 --- a/www/ebooks/author.php +++ b/www/ebooks/author.php @@ -31,7 +31,7 @@ catch(Exceptions\AuthorNotFoundException){ Download collection Feeds for this author

      - $ebooks, 'view' => VIEW_GRID]) ?> + $ebooks, 'view' => ViewType::Grid]) ?>

      We also have bulk ebook downloads and a list of collections available, as well as ebook catalog feeds for use directly in your ereader app or RSS reader.

      diff --git a/www/ebooks/index.php b/www/ebooks/index.php index 6ce9f8cf..5cda083b 100644 --- a/www/ebooks/index.php +++ b/www/ebooks/index.php @@ -5,7 +5,7 @@ $page = HttpInput::Int(GET, 'page') ?? 1; $perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE; $query = HttpInput::Str(GET, 'query') ?? ''; $tags = HttpInput::GetArray('tags') ?? []; -$view = HttpInput::Str(GET, 'view'); +$view = ViewType::tryFrom(HttpInput::Str(GET, 'view') ?? ''); $sort = EbookSort::tryFrom(HttpInput::Str(GET, 'sort') ?? ''); $queryString = ''; $queryStringParams = []; @@ -21,11 +21,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($view !== null){ - $view = mb_strtolower($view); - } - - if($view === 'grid'){ + if($view === ViewType::Grid){ $view = null; } @@ -44,7 +40,6 @@ try{ $totalEbooks = sizeof($ebooks); $ebooks = array_slice($ebooks, ($page - 1) * $perPage, $perPage); - if($page > 1){ $pageTitle .= ', page ' . $page; } @@ -60,7 +55,7 @@ try{ } if($view !== null){ - $queryStringParams['view'] = $view; + $queryStringParams['view'] = $view->value; } if($sort !== null){