mirror of
https://github.com/standardebooks/web.git
synced 2025-07-21 06:45:14 -04:00
Add enum for view type and fix some type hints
This commit is contained in:
parent
7c8463d297
commit
8cc661015c
10 changed files with 20 additions and 30 deletions
|
@ -6,9 +6,12 @@ use Safe\DateTimeImmutable;
|
||||||
* @property ?string $UrlName
|
* @property ?string $UrlName
|
||||||
* @property ?string $Url
|
* @property ?string $Url
|
||||||
* @property ?array<string> $AlternateNames
|
* @property ?array<string> $AlternateNames
|
||||||
* @property ?array<string> $_AlternateNames
|
|
||||||
*/
|
*/
|
||||||
class Artist{
|
class Artist{
|
||||||
|
/**
|
||||||
|
* @var array<string> $_AlternateNames
|
||||||
|
*/
|
||||||
|
|
||||||
use Traits\Accessor;
|
use Traits\Accessor;
|
||||||
|
|
||||||
public ?int $ArtistId = null;
|
public ?int $ArtistId = null;
|
||||||
|
@ -18,7 +21,7 @@ class Artist{
|
||||||
protected ?int $_DeathYear = null;
|
protected ?int $_DeathYear = null;
|
||||||
protected ?string $_UrlName = null;
|
protected ?string $_UrlName = null;
|
||||||
protected ?string $_Url = null;
|
protected ?string $_Url = null;
|
||||||
protected ?array $_AlternateNames = null;
|
protected $_AlternateNames = null; // Don't type hint this here, otherwise PHPStan will complain
|
||||||
|
|
||||||
// *******
|
// *******
|
||||||
// SETTERS
|
// SETTERS
|
||||||
|
|
|
@ -3,14 +3,6 @@ use function Safe\preg_match;
|
||||||
use function Safe\preg_replace;
|
use function Safe\preg_replace;
|
||||||
|
|
||||||
class ArtworkTag extends Tag{
|
class ArtworkTag extends Tag{
|
||||||
// *******
|
|
||||||
// SETTERS
|
|
||||||
// *******
|
|
||||||
|
|
||||||
// protected function SetName($name): void{
|
|
||||||
// $this->_Name =
|
|
||||||
// }
|
|
||||||
|
|
||||||
// *******
|
// *******
|
||||||
// GETTERS
|
// GETTERS
|
||||||
// *******
|
// *******
|
||||||
|
|
|
@ -72,9 +72,6 @@ const HTTP_PUT = 3;
|
||||||
const HTTP_DELETE = 4;
|
const HTTP_DELETE = 4;
|
||||||
const HTTP_HEAD = 5;
|
const HTTP_HEAD = 5;
|
||||||
|
|
||||||
const VIEW_GRID = 'grid';
|
|
||||||
const VIEW_LIST = 'list';
|
|
||||||
|
|
||||||
const AVERAGE_READING_WORDS_PER_MINUTE = 275;
|
const AVERAGE_READING_WORDS_PER_MINUTE = 275;
|
||||||
|
|
||||||
const PAYMENT_CHANNEL_FA = 0;
|
const PAYMENT_CHANNEL_FA = 0;
|
||||||
|
|
5
lib/ViewType.php
Normal file
5
lib/ViewType.php
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
<?
|
||||||
|
enum ViewType: string{
|
||||||
|
case Grid = 'grid';
|
||||||
|
case List = 'list';
|
||||||
|
}
|
|
@ -1,13 +1,13 @@
|
||||||
<?
|
<?
|
||||||
|
|
||||||
if($view == ''){
|
if($view == ''){
|
||||||
$view = VIEW_GRID;
|
$view = ViewType::Grid;
|
||||||
}
|
}
|
||||||
|
|
||||||
$collection = $collection ?? null;
|
$collection = $collection ?? null;
|
||||||
$ebooks = $ebooks ?? [];
|
$ebooks = $ebooks ?? [];
|
||||||
?>
|
?>
|
||||||
<ol class="ebooks-list<? if($view == VIEW_LIST){ ?> list<? }else{ ?> grid<? } ?>"<? if($collection !== null){ ?> typeof="schema:BookSeries" about="<?= $collection->Url ?>"<? } ?>>
|
<ol class="ebooks-list<? if($view == ViewType::List){ ?> list<? }else{ ?> grid<? } ?>"<? if($collection !== null){ ?> typeof="schema:BookSeries" about="<?= $collection->Url ?>"<? } ?>>
|
||||||
<? if($collection !== null){ ?>
|
<? if($collection !== null){ ?>
|
||||||
<meta property="schema:name" content="<?= Formatter::EscapeHtml($collection->Name) ?>"/>
|
<meta property="schema:name" content="<?= Formatter::EscapeHtml($collection->Name) ?>"/>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
@ -26,7 +26,7 @@ $ebooks = $ebooks ?? [];
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
<p><a href="<?= $ebook->Url ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($ebook->Title) ?></span></a></p>
|
<p><a href="<?= $ebook->Url ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($ebook->Title) ?></span></a></p>
|
||||||
<? if($view == VIEW_GRID){ ?>
|
<? if($view == ViewType::Grid){ ?>
|
||||||
<? foreach($ebook->Authors as $author){ ?>
|
<? foreach($ebook->Authors as $author){ ?>
|
||||||
<p class="author" typeof="schema:Person" property="schema:author" resource="<?= $ebook->AuthorsUrl ?>"><? if($author->Name != 'Anonymous'){ ?><a href="<?= Formatter::EscapeHtml(SITE_URL . $ebook->AuthorsUrl) ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($author->Name) ?></span></a><? } ?></p>
|
<p class="author" typeof="schema:Person" property="schema:author" resource="<?= $ebook->AuthorsUrl ?>"><? if($author->Name != 'Anonymous'){ ?><a href="<?= Formatter::EscapeHtml(SITE_URL . $ebook->AuthorsUrl) ?>" property="schema:url"><span property="schema:name"><?= Formatter::EscapeHtml($author->Name) ?></span></a><? } ?></p>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
|
|
@ -28,8 +28,8 @@ $allSelected = sizeof($tags) == 0 || in_array('all', $tags);
|
||||||
<span>View</span>
|
<span>View</span>
|
||||||
<span>
|
<span>
|
||||||
<select name="view">
|
<select name="view">
|
||||||
<option value="<?= VIEW_GRID ?>"<? if($view == VIEW_GRID){ ?> selected="selected"<? } ?>>Grid</option>
|
<option value="<?= ViewType::Grid->value ?>"<? if($view == ViewType::Grid){ ?> selected="selected"<? } ?>>Grid</option>
|
||||||
<option value="<?= VIEW_LIST ?>"<? if($view == VIEW_LIST){ ?> selected="selected"<? } ?>>List</option>
|
<option value="<?= ViewType::List->value ?>"<? if($view == ViewType::List){ ?> selected="selected"<? } ?>>List</option>
|
||||||
</select>
|
</select>
|
||||||
</span>
|
</span>
|
||||||
</label>
|
</label>
|
||||||
|
|
|
@ -155,8 +155,6 @@ catch(Exceptions\ArtworkNotFoundException){
|
||||||
Template::Emit404();
|
Template::Emit404();
|
||||||
}
|
}
|
||||||
catch(Exceptions\AppException $exception){
|
catch(Exceptions\AppException $exception){
|
||||||
$artwork = $artwork ?? null;
|
|
||||||
|
|
||||||
$_SESSION['artwork'] = $artwork;
|
$_SESSION['artwork'] = $artwork;
|
||||||
$_SESSION['exception'] = $exception;
|
$_SESSION['exception'] = $exception;
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ catch(Exceptions\CollectionNotFoundException){
|
||||||
<? if(sizeof($ebooks) == 0){ ?>
|
<? if(sizeof($ebooks) == 0){ ?>
|
||||||
<p class="no-results">No ebooks matched your filters. You can try different filters, or <a href="/ebooks">browse all of our ebooks</a>.</p>
|
<p class="no-results">No ebooks matched your filters. You can try different filters, or <a href="/ebooks">browse all of our ebooks</a>.</p>
|
||||||
<? }else{ ?>
|
<? }else{ ?>
|
||||||
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => VIEW_GRID, 'collection' => $collectionObject]) ?>
|
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => ViewType::Grid, 'collection' => $collectionObject]) ?>
|
||||||
<? } ?>
|
<? } ?>
|
||||||
|
|
||||||
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
|
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
|
||||||
|
|
|
@ -31,7 +31,7 @@ catch(Exceptions\AuthorNotFoundException){
|
||||||
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/downloads">Download collection</a>
|
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/downloads">Download collection</a>
|
||||||
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/feeds">Feeds for this author</a>
|
<a class="button" href="<?= Formatter::EscapeHtml($authorUrl) ?>/feeds">Feeds for this author</a>
|
||||||
</p>
|
</p>
|
||||||
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => VIEW_GRID]) ?>
|
<?= Template::EbookGrid(['ebooks' => $ebooks, 'view' => ViewType::Grid]) ?>
|
||||||
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
|
<p class="feeds-alert">We also have <a href="/bulk-downloads">bulk ebook downloads</a> and a <a href="/collections">list of collections</a> available, as well as <a href="/feeds">ebook catalog feeds</a> for use directly in your ereader app or RSS reader.</p>
|
||||||
<?= Template::ContributeAlert() ?>
|
<?= Template::ContributeAlert() ?>
|
||||||
</main>
|
</main>
|
||||||
|
|
|
@ -5,7 +5,7 @@ $page = HttpInput::Int(GET, 'page') ?? 1;
|
||||||
$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
|
$perPage = HttpInput::Int(GET, 'per-page') ?? EBOOKS_PER_PAGE;
|
||||||
$query = HttpInput::Str(GET, 'query') ?? '';
|
$query = HttpInput::Str(GET, 'query') ?? '';
|
||||||
$tags = HttpInput::GetArray('tags') ?? [];
|
$tags = HttpInput::GetArray('tags') ?? [];
|
||||||
$view = HttpInput::Str(GET, 'view');
|
$view = ViewType::tryFrom(HttpInput::Str(GET, 'view') ?? '');
|
||||||
$sort = EbookSort::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
|
$sort = EbookSort::tryFrom(HttpInput::Str(GET, 'sort') ?? '');
|
||||||
$queryString = '';
|
$queryString = '';
|
||||||
$queryStringParams = [];
|
$queryStringParams = [];
|
||||||
|
@ -21,11 +21,7 @@ try{
|
||||||
|
|
||||||
// If we're passed string values that are the same as the defaults,
|
// 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
|
// set them to null so that we can have cleaner query strings in the navigation footer
|
||||||
if($view !== null){
|
if($view === ViewType::Grid){
|
||||||
$view = mb_strtolower($view);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($view === 'grid'){
|
|
||||||
$view = null;
|
$view = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,7 +40,6 @@ try{
|
||||||
$totalEbooks = sizeof($ebooks);
|
$totalEbooks = sizeof($ebooks);
|
||||||
$ebooks = array_slice($ebooks, ($page - 1) * $perPage, $perPage);
|
$ebooks = array_slice($ebooks, ($page - 1) * $perPage, $perPage);
|
||||||
|
|
||||||
|
|
||||||
if($page > 1){
|
if($page > 1){
|
||||||
$pageTitle .= ', page ' . $page;
|
$pageTitle .= ', page ' . $page;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +55,7 @@ try{
|
||||||
}
|
}
|
||||||
|
|
||||||
if($view !== null){
|
if($view !== null){
|
||||||
$queryStringParams['view'] = $view;
|
$queryStringParams['view'] = $view->value;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($sort !== null){
|
if($sort !== null){
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue