mirror of
https://github.com/standardebooks/web.git
synced 2025-07-16 03:16:36 -04:00
Add status and user filtering to GetArtworksByArtist
This commit is contained in:
parent
770c010025
commit
91ac96d784
2 changed files with 44 additions and 5 deletions
|
@ -182,7 +182,7 @@ class Library{
|
|||
$statusCondition = 'true';
|
||||
}
|
||||
elseif($status == 'all-submitter' && $submitterUserId !== null){
|
||||
$statusCondition = 'Status = ? or (Status = ? and SubmitterUserId = ?)';
|
||||
$statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))';
|
||||
$params[] = ArtworkStatus::Approved->value;
|
||||
$params[] = ArtworkStatus::Unverified->value;
|
||||
$params[] = $submitterUserId;
|
||||
|
@ -250,17 +250,42 @@ class Library{
|
|||
/**
|
||||
* @return array<Artwork>
|
||||
*/
|
||||
public static function GetArtworksByArtist(?string $artistUrlName): array{
|
||||
public static function GetArtworksByArtist(?string $artistUrlName, ?string $status, ?int $submitterUserId): array{
|
||||
if($artistUrlName === null){
|
||||
throw new Exceptions\ArtistNotFoundException();
|
||||
}
|
||||
|
||||
// $status is only one of three special statuses, which are a subset of FilterArtwork() above:
|
||||
// null: same as "all"
|
||||
// "all": Show all approved and in use artwork
|
||||
// "all-admin": Show all artwork regardless of status
|
||||
// "all-submitter": Show all approved and in use artwork, plus unverified artwork from the submitter
|
||||
$statusCondition = '';
|
||||
$params = [];
|
||||
|
||||
if($status == 'all-admin'){
|
||||
$statusCondition = 'true';
|
||||
}
|
||||
elseif($status == 'all-submitter' && $submitterUserId !== null){
|
||||
$statusCondition = '(Status = ? or (Status = ? and SubmitterUserId = ?))';
|
||||
$params[] = ArtworkStatus::Approved->value;
|
||||
$params[] = ArtworkStatus::Unverified->value;
|
||||
$params[] = $submitterUserId;
|
||||
}
|
||||
else{
|
||||
$statusCondition = 'Status = ?';
|
||||
$params[] = ArtworkStatus::Approved->value;
|
||||
}
|
||||
|
||||
$params[] = $artistUrlName; // a.UrlName
|
||||
|
||||
$artworks = Db::Query('
|
||||
SELECT art.*
|
||||
from Artworks art
|
||||
inner join Artists a using (ArtistId)
|
||||
where a.UrlName = ?
|
||||
order by art.Created desc', [$artistUrlName], 'Artwork');
|
||||
where ' . $statusCondition . '
|
||||
and a.UrlName = ?
|
||||
order by art.Created desc', $params, 'Artwork');
|
||||
|
||||
return $artworks;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,20 @@
|
|||
<?
|
||||
$isReviewerView = $GLOBALS['User']?->Benefits?->CanReviewArtwork ?? false;
|
||||
$submitterUserId = $GLOBALS['User']?->Benefits?->CanUploadArtwork ? $GLOBALS['User']->UserId : null;
|
||||
$isSubmitterView = !$isReviewerView && $submitterUserId !== null;
|
||||
|
||||
$filterArtworkStatus = 'all';
|
||||
|
||||
if($isReviewerView){
|
||||
$filterArtworkStatus = 'all-admin';
|
||||
}
|
||||
|
||||
if($isSubmitterView){
|
||||
$filterArtworkStatus = 'all-submitter';
|
||||
}
|
||||
|
||||
try{
|
||||
$artworks = Library::GetArtworksByArtist(HttpInput::Str(GET, 'artist-url-name'));
|
||||
$artworks = Library::GetArtworksByArtist(HttpInput::Str(GET, 'artist-url-name'), $filterArtworkStatus, $submitterUserId);
|
||||
|
||||
if(sizeof($artworks) == 0){
|
||||
throw new Exceptions\ArtistNotFoundException();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue