Add cover art database

Co-authored-by: Job Curtis <job.curtis@gmail.com>
Co-authored-by: Alex Cabal <alex@standardebooks.org>
This commit is contained in:
Mike Colagrosso 2023-12-28 16:38:39 -06:00 committed by Alex Cabal
parent 74f747df76
commit 6a5c05511a
92 changed files with 3174 additions and 146 deletions

View file

@ -0,0 +1,48 @@
<?
use function Safe\session_unset;
session_start();
$exception = $_SESSION['exception'] ?? null;
try{
$artwork = Artwork::Get(HttpInput::Int(GET, 'artworkid'));
// The artwork is already approved or in use, so redirect to its public page
if($artwork->Status == COVER_ARTWORK_STATUS_APPROVED || $artwork->Status == COVER_ARTWORK_STATUS_IN_USE){
http_response_code(302);
header('Location: ' . $artwork->Url);
exit();
}
// We got here because an artwork submission had errors and the user has to try again
if($exception){
http_response_code(422);
session_unset();
}
}
catch(Exceptions\AppException){
Template::Emit404();
}
?><?= Template::Header(['title' => 'Review Artwork', 'artwork' => true, 'highlight' => '', 'description' => 'Unverified artwork.']) ?>
<main class="artworks">
<?= Template::Error(['exception' => $exception]) ?>
<section class="narrow">
<?= Template::ArtworkDetail(['artwork' => $artwork]) ?>
<? if($artwork->Status == COVER_ARTWORK_STATUS_DECLINED){ ?>
<h2>Status</h2>
<p>This artwork has been declined by a reviewer.</p>
<? } ?>
<? if($artwork->Status == COVER_ARTWORK_STATUS_UNVERIFIED){ ?>
<h2>Review</h2>
<p>Review the metadata and PD proof for this artwork submission. Approve to make it available for future producers.</p>
<form method="post" action="/admin/artworks/<?= $artwork->ArtworkId ?>">
<input type="hidden" name="_method" value="PATCH" />
<button name="status" value="<?= COVER_ARTWORK_STATUS_APPROVED ?>">Approve</button>
<button name="status" value="<?= COVER_ARTWORK_STATUS_DECLINED ?>" class="decline-button">Decline</button>
</form>
<? } ?>
</section>
</main>
<?= Template::Footer() ?>

View file

@ -0,0 +1,88 @@
<?
use function Safe\session_unset;
session_start();
$artwork = null;
$status = HttpInput::Str(SESSION, 'status', false);
$page = HttpInput::Int(GET, 'page') ?? 1;
$perPage = 10;
$hasNextPage = false;
$unverifiedArtworks = [];
try{
if($GLOBALS['User'] === null){
throw new Exceptions\LoginRequiredException();
}
if(!$GLOBALS['User']->Benefits->CanReviewArtwork){
throw new Exceptions\InvalidPermissionsException();
}
if($status !== null){
$artwork = Artwork::Get(HttpInput::Int(SESSION, 'artwork-id'));
http_response_code(201);
session_unset();
}
if($page <= 0){
$page = 1;
}
$unverifiedArtworks = Db::Query('
SELECT *
from Artworks
where Status = "unverified"
order by Created asc
limit ?, ?
', [($page - 1) * $perPage, $perPage + 1], 'Artwork');
if(sizeof($unverifiedArtworks) > $perPage){
array_pop($unverifiedArtworks);
$hasNextPage = true;
}
}
catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin();
}
catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); // No permissions to submit artwork
}
?><?= Template::Header(['title' => 'Artwork Review Queue', 'artwork' => true, 'highlight' => '', 'description' => 'The queue of unverified artwork.']) ?>
<main class="artworks">
<section class="narrow">
<h1>Artwork Review Queue</h1>
<? if($status == COVER_ARTWORK_STATUS_APPROVED){ ?>
<p class="message success">
<? if($artwork !== null){ ?>
<i><a href="<?= $artwork->Url ?>" property="schema:name"><?= Formatter::ToPlainText($artwork->Name) ?></a></i> approved.
<? }else{ ?>
Artwork approved.
<? } ?>
</p>
<? } ?>
<? if($status == COVER_ARTWORK_STATUS_DECLINED){ ?>
<p class="message">
<? if($artwork !== null){ ?>
<i><?= Formatter::ToPlainText($artwork->Name) ?></i> declined.
<? }else{ ?>
Artwork declined.
<? } ?>
</p>
<? } ?>
<? if(sizeof($unverifiedArtworks) == 0){ ?>
<p>No artwork to review.</p>
<? }else{ ?>
<?= Template::ArtworkList(['artworks' => $unverifiedArtworks, 'useAdminUrl' => true]) ?>
<? } ?>
</section>
<nav>
<a<? if($page > 1){ ?> href="/admin/artworks/?page=<?= $page - 1 ?>" rel="prev"<? }else{ ?> aria-disabled="true"<? } ?>>Back</a>
<a<? if($hasNextPage){ ?> href="/admin/artworks/?page=<?= $page + 1 ?>" rel="next"<? }else{ ?> aria-disabled="true"<? } ?>>Next</a>
</nav>
</main>
<?= Template::Footer() ?>

View file

@ -0,0 +1,45 @@
<?
try{
session_start();
if(HttpInput::RequestMethod() != HTTP_PATCH){
throw new Exceptions\InvalidRequestException();
}
if($GLOBALS['User'] === null){
throw new Exceptions\LoginRequiredException();
}
if(!$GLOBALS['User']->Benefits->CanReviewArtwork){
throw new Exceptions\InvalidPermissionsException();
}
$artwork = Artwork::Get(HttpInput::Int(GET, 'artworkid'));
$artwork->Status = HttpInput::Str(POST, 'status', false);
$artwork->ReviewerUserId = $GLOBALS['User']->UserId;
$artwork->Save();
$_SESSION['artwork-id'] = $artwork->ArtworkId;
$_SESSION['status'] = $artwork->Status;
http_response_code(303);
header('Location: /admin/artworks');
}
catch(Exceptions\InvalidRequestException){
http_response_code(405);
}
catch(Exceptions\LoginRequiredException){
Template::RedirectToLogin();
}
catch(Exceptions\InvalidPermissionsException){
Template::Emit403(); // No permissions to submit artwork
}
catch(Exceptions\ArtworkNotFoundException){
Template::Emit404();
}
catch(Exceptions\AppException $exception){
$_SESSION['exception'] = $exception;
http_response_code(303);
header('Location: /admin/artworks/' . $artwork->ArtworkId);
}