mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 01:52:02 -04:00
List artwork by artist via /artworks/<artist-name>
This commit is contained in:
parent
780be15ed0
commit
cad2f5f730
8 changed files with 63 additions and 12 deletions
10
README.md
10
README.md
|
@ -136,16 +136,6 @@ Before submitting design contributions, please discuss them with the Standard Eb
|
||||||
|
|
||||||
- Converting some constants to enums, like `SORT_*` or `SOURCE_*`.
|
- Converting some constants to enums, like `SORT_*` or `SOURCE_*`.
|
||||||
|
|
||||||
### Artwork database
|
|
||||||
|
|
||||||
- Tags should be searched as whole words. For example a search for `male` should not return items tagged as `female`.
|
|
||||||
|
|
||||||
- Include in-use ebook slug as a search parameter when searching for artwork by keyword.
|
|
||||||
|
|
||||||
- Artwork searching/filtering should be done in pure SQL, no after-SQL filtering in PHP.
|
|
||||||
|
|
||||||
- Allow listing artwork by artist by visiting `/artworks/<artist-name>`, and link instances of artist name to that URL.
|
|
||||||
|
|
||||||
## PHP code style
|
## PHP code style
|
||||||
|
|
||||||
- Indent with tabs.
|
- Indent with tabs.
|
||||||
|
|
|
@ -296,6 +296,8 @@ Define webroot /standardebooks.org/web
|
||||||
RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1
|
RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1
|
||||||
|
|
||||||
# Rewrite rules for cover art
|
# Rewrite rules for cover art
|
||||||
|
RewriteRule ^/artworks/([^\./]+?)$ /artworks/artist.php?artist-url-name=$1 [L]
|
||||||
|
|
||||||
RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/"
|
RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/"
|
||||||
RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L]
|
RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L]
|
||||||
|
|
||||||
|
|
|
@ -278,6 +278,8 @@ Define webroot /standardebooks.org/web
|
||||||
RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1
|
RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1
|
||||||
|
|
||||||
# Rewrite rules for cover art
|
# Rewrite rules for cover art
|
||||||
|
RewriteRule ^/artworks/([^\./]+?)$ /artworks/artist.php?artist-url-name=$1 [L]
|
||||||
|
|
||||||
RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/"
|
RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/"
|
||||||
RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L]
|
RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L]
|
||||||
|
|
||||||
|
|
|
@ -22,5 +22,6 @@ CREATE TABLE `Artworks` (
|
||||||
`Notes` TEXT NULL DEFAULT NULL
|
`Notes` TEXT NULL DEFAULT NULL
|
||||||
PRIMARY KEY (`ArtworkId`),
|
PRIMARY KEY (`ArtworkId`),
|
||||||
KEY `index1` (`Status`),
|
KEY `index1` (`Status`),
|
||||||
KEY `index2` (`UrlName`)
|
KEY `index2` (`UrlName`),
|
||||||
|
KEY `index3` (`ArtistId`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
|
@ -4,6 +4,7 @@ use function Safe\date;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property string $UrlName
|
* @property string $UrlName
|
||||||
|
* @property string $Url
|
||||||
* @property array<string> $AlternateNames
|
* @property array<string> $AlternateNames
|
||||||
* @property array<string> $_AlternateNames
|
* @property array<string> $_AlternateNames
|
||||||
*/
|
*/
|
||||||
|
@ -14,6 +15,7 @@ class Artist extends PropertiesBase{
|
||||||
public ?datetime $Created = null;
|
public ?datetime $Created = null;
|
||||||
public ?datetime $Updated = null;
|
public ?datetime $Updated = null;
|
||||||
protected ?string $_UrlName = null;
|
protected ?string $_UrlName = null;
|
||||||
|
protected ?string $_Url = null;
|
||||||
protected $_AlternateNames;
|
protected $_AlternateNames;
|
||||||
|
|
||||||
// *******
|
// *******
|
||||||
|
@ -32,6 +34,14 @@ class Artist extends PropertiesBase{
|
||||||
return $this->_UrlName;
|
return $this->_UrlName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function GetUrl(): string{
|
||||||
|
if($this->_Url === null){
|
||||||
|
$this->_Url = '/artworks/' . $this->UrlName;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->_Url;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<string>
|
* @return array<string>
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -247,6 +247,20 @@ class Library{
|
||||||
return $artworks;
|
return $artworks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array<Artwork>
|
||||||
|
*/
|
||||||
|
public static function GetArtworkByArtist(string $artistUrlName): array{
|
||||||
|
$artworks = Db::Query('
|
||||||
|
SELECT art.*
|
||||||
|
from Artworks art
|
||||||
|
inner join Artists a using (ArtistId)
|
||||||
|
where a.UrlName = ?
|
||||||
|
order by art.Created desc', [$artistUrlName], 'Artwork');
|
||||||
|
|
||||||
|
return $artworks;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return array<mixed>
|
* @return array<mixed>
|
||||||
*/
|
*/
|
||||||
|
|
32
www/artworks/artist.php
Normal file
32
www/artworks/artist.php
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
<?
|
||||||
|
$artistUrlName = '';
|
||||||
|
|
||||||
|
try{
|
||||||
|
$artistUrlName = trim(HttpInput::Str(GET, 'artist-url-name') ?? '');
|
||||||
|
|
||||||
|
if($artistUrlName == ''){
|
||||||
|
throw new Exceptions\ArtistNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$artworks = Library::GetArtworkByArtist($artistUrlName);
|
||||||
|
|
||||||
|
if(sizeof($artworks) == 0){
|
||||||
|
throw new Exceptions\ArtistNotFoundException();
|
||||||
|
}
|
||||||
|
|
||||||
|
$artistName = $artworks[0]->Artist->Name;
|
||||||
|
}
|
||||||
|
catch(Exceptions\ArtistNotFoundException){
|
||||||
|
Template::Emit404();
|
||||||
|
}
|
||||||
|
?><?= Template::Header(['title' => 'Artwork by ' . $artistName, 'artwork' => true]) ?>
|
||||||
|
<main class="artworks">
|
||||||
|
<section class="narrow">
|
||||||
|
<h1>Artwork by <?= Formatter::EscapeHtml($artistName) ?></h1>
|
||||||
|
|
||||||
|
<?= Template::ImageCopyrightNotice() ?>
|
||||||
|
|
||||||
|
<?= Template::ArtworkList(['artworks' => $artworks]) ?>
|
||||||
|
</section>
|
||||||
|
</main>
|
||||||
|
<?= Template::Footer() ?>
|
|
@ -75,7 +75,7 @@ catch(Exceptions\InvalidPermissionsException){
|
||||||
<tr>
|
<tr>
|
||||||
<td>Artist</td>
|
<td>Artist</td>
|
||||||
<td>
|
<td>
|
||||||
<?= Formatter::EscapeHtml($artwork->Artist->Name) ?><? if(sizeof($artwork->Artist->AlternateNames) > 0){ ?> (A.K.A. <span class="author" typeof="schema:Person" property="schema:name"><?= implode('</span>, <span class="author" typeof="schema:Person" property="schema:name">', array_map('Formatter::EscapeHtml', $artwork->Artist->AlternateNames)) ?></span>)<? } ?><? if($artwork->Artist->DeathYear !== null){ ?> (<abbr>d.</abbr> <?= $artwork->Artist->DeathYear ?>)<? } ?><? if($isAdminView){ ?> (#<?= $artwork->Artist->ArtistId ?>)<? } ?>
|
<a href="<?= $artwork->Artist->Url ?>"><?= Formatter::EscapeHtml($artwork->Artist->Name) ?></a><? if(sizeof($artwork->Artist->AlternateNames) > 0){ ?> (A.K.A. <span class="author" typeof="schema:Person" property="schema:name"><?= implode('</span>, <span class="author" typeof="schema:Person" property="schema:name">', array_map('Formatter::EscapeHtml', $artwork->Artist->AlternateNames)) ?></span>)<? } ?><? if($artwork->Artist->DeathYear !== null){ ?> (<abbr>d.</abbr> <?= $artwork->Artist->DeathYear ?>)<? } ?><? if($isAdminView){ ?> (#<?= $artwork->Artist->ArtistId ?>)<? } ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue