Skip to content

Commit

Permalink
List artwork by artist via /artworks/<artist-name>
Browse files Browse the repository at this point in the history
  • Loading branch information
colagrosso authored and acabal committed Jan 23, 2024
1 parent 780be15 commit cad2f5f
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 12 deletions.
10 changes: 0 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,6 @@ Before submitting design contributions, please discuss them with the Standard Eb
- 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
- Indent with tabs.
Expand Down
2 changes: 2 additions & 0 deletions config/apache/standardebooks.org.conf
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,8 @@ Define webroot /standardebooks.org/web
RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1

# Rewrite rules for cover art
RewriteRule ^/artworks/([^\./]+?)$ /artworks/artist.php?artist-url-name=$1 [L]

RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/"
RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L]

Expand Down
2 changes: 2 additions & 0 deletions config/apache/standardebooks.test.conf
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,8 @@ Define webroot /standardebooks.org/web
RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1

# Rewrite rules for cover art
RewriteRule ^/artworks/([^\./]+?)$ /artworks/artist.php?artist-url-name=$1 [L]

RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/"
RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L]

Expand Down
3 changes: 2 additions & 1 deletion config/sql/se/Artworks.sql
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@ CREATE TABLE `Artworks` (
`Notes` TEXT NULL DEFAULT NULL
PRIMARY KEY (`ArtworkId`),
KEY `index1` (`Status`),
KEY `index2` (`UrlName`)
KEY `index2` (`UrlName`),
KEY `index3` (`ArtistId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
10 changes: 10 additions & 0 deletions lib/Artist.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

/**
* @property string $UrlName
* @property string $Url
* @property array<string> $AlternateNames
* @property array<string> $_AlternateNames
*/
Expand All @@ -14,6 +15,7 @@ class Artist extends PropertiesBase{
public ?datetime $Created = null;
public ?datetime $Updated = null;
protected ?string $_UrlName = null;
protected ?string $_Url = null;
protected $_AlternateNames;

// *******
Expand All @@ -32,6 +34,14 @@ protected function GetUrlName(): string{
return $this->_UrlName;
}

protected function GetUrl(): string{
if($this->_Url === null){
$this->_Url = '/artworks/' . $this->UrlName;
}

return $this->_Url;
}

/**
* @return array<string>
*/
Expand Down
14 changes: 14 additions & 0 deletions lib/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,20 @@ public static function FilterArtwork(string $query = null, string $status = null
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>
*/
Expand Down
32 changes: 32 additions & 0 deletions www/artworks/artist.php
Original file line number Diff line number Diff line change
@@ -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() ?>
2 changes: 1 addition & 1 deletion www/artworks/get.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
<tr>
<td>Artist</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>
</tr>
<tr>
Expand Down

0 comments on commit cad2f5f

Please sign in to comment.