mirror of
https://github.com/standardebooks/web.git
synced 2025-07-06 06:40:33 -04:00
Add type hints to Artwork class members
This commit is contained in:
parent
5b6a334dd0
commit
8e37543fa3
5 changed files with 64 additions and 47 deletions
|
@ -23,38 +23,39 @@ use function Safe\sprintf;
|
|||
* @property User $Submitter
|
||||
* @property User $Reviewer
|
||||
* @property ?ImageMimeType $MimeType
|
||||
* @property array<ArtworkTag> $_Tags
|
||||
*/
|
||||
class Artwork extends PropertiesBase{
|
||||
public $Name;
|
||||
public $ArtworkId;
|
||||
public $ArtistId;
|
||||
public $CompletedYear;
|
||||
public $CompletedYearIsCirca;
|
||||
public $Created;
|
||||
public $Updated;
|
||||
public $Status;
|
||||
public $EbookWwwFilesystemPath;
|
||||
public $SubmitterUserId;
|
||||
public $ReviewerUserId;
|
||||
public $MuseumUrl;
|
||||
public $PublicationYear;
|
||||
public $PublicationYearPageUrl;
|
||||
public $CopyrightPageUrl;
|
||||
public $ArtworkPageUrl;
|
||||
public $IsPublishedInUs;
|
||||
public $Exception;
|
||||
protected $_UrlName;
|
||||
protected $_Url;
|
||||
protected $_AdminUrl;
|
||||
public ?string $Name;
|
||||
public ?int $ArtworkId;
|
||||
public ?int $ArtistId;
|
||||
public ?int $CompletedYear;
|
||||
public ?bool $CompletedYearIsCirca;
|
||||
public ?DateTime $Created;
|
||||
public ?DateTime $Updated;
|
||||
public ?string $Status;
|
||||
public ?string $EbookWwwFilesystemPath;
|
||||
public ?int $SubmitterUserId;
|
||||
public ?int $ReviewerUserId;
|
||||
public ?string $MuseumUrl;
|
||||
public ?int $PublicationYear;
|
||||
public ?string $PublicationYearPageUrl;
|
||||
public ?string $CopyrightPageUrl;
|
||||
public ?string $ArtworkPageUrl;
|
||||
public ?bool $IsPublishedInUs;
|
||||
public ?string $Exception;
|
||||
protected ?string $_UrlName = null;
|
||||
protected ?string $_Url = null;
|
||||
protected $_Tags = null;
|
||||
protected $_Artist = null;
|
||||
protected $_ImageUrl = null;
|
||||
protected $_ThumbUrl = null;
|
||||
protected $_Thumb2xUrl = null;
|
||||
protected $_Dimensions = null;
|
||||
protected $_Ebook = null;
|
||||
protected $_Museum = null;
|
||||
protected $_Submitter = null;
|
||||
protected ?Artist $_Artist = null;
|
||||
protected ?string $_ImageUrl = null;
|
||||
protected ?string $_ThumbUrl = null;
|
||||
protected ?string $_Thumb2xUrl = null;
|
||||
protected ?string $_Dimensions = null;
|
||||
protected ?Ebook $_Ebook = null;
|
||||
protected ?Museum $_Museum = null;
|
||||
protected ?User $_Submitter = null;
|
||||
protected ?User $_Reviewer = null;
|
||||
protected ?ImageMimeType $_MimeType = null;
|
||||
|
||||
// *******
|
||||
|
@ -97,14 +98,6 @@ class Artwork extends PropertiesBase{
|
|||
return $this->_Url;
|
||||
}
|
||||
|
||||
protected function GetAdminUrl(): string{
|
||||
if($this->_AdminUrl === null){
|
||||
$this->_AdminUrl = '/admin/artworks/' . $this->ArtworkId;
|
||||
}
|
||||
|
||||
return $this->_AdminUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<ArtworkTag>
|
||||
*/
|
||||
|
@ -123,8 +116,13 @@ class Artwork extends PropertiesBase{
|
|||
|
||||
public function GetMuseum(): ?Museum{
|
||||
if($this->_Museum === null){
|
||||
try{
|
||||
$this->_Museum = Museum::GetByUrl($this->MuseumUrl);
|
||||
}
|
||||
catch(Exceptions\MuseumNotFoundException){
|
||||
// Pass
|
||||
}
|
||||
}
|
||||
|
||||
return $this->_Museum;
|
||||
}
|
||||
|
@ -178,16 +176,15 @@ class Artwork extends PropertiesBase{
|
|||
}
|
||||
|
||||
protected function GetDimensions(): string{
|
||||
$this->_Dimensions = '';
|
||||
try{
|
||||
|
||||
list($imageWidth, $imageHeight) = getimagesize(WEB_ROOT . $this->ImageUrl);
|
||||
if($imageWidth && $imageHeight){
|
||||
$this->_Dimensions .= $imageWidth . ' × ' . $imageHeight;
|
||||
$this->_Dimensions = $imageWidth . ' × ' . $imageHeight;
|
||||
}
|
||||
}
|
||||
catch(Exception){
|
||||
// Image doesn't exist
|
||||
$this->_Dimensions = '';
|
||||
// Image doesn't exist, return blank strin
|
||||
}
|
||||
|
||||
return $this->_Dimensions;
|
||||
|
@ -580,7 +577,11 @@ class Artwork extends PropertiesBase{
|
|||
/**
|
||||
* @throws \Exceptions\InvalidArtworkException
|
||||
*/
|
||||
public static function GetByUrl(string $artistUrlName, string $artworkUrlName): Artwork{
|
||||
public static function GetByUrl(?string $artistUrlName, ?string $artworkUrlName): Artwork{
|
||||
if($artistUrlName === null || $artworkUrlName === null){
|
||||
throw new Exceptions\ArtworkNotFoundException();
|
||||
}
|
||||
|
||||
$result = Db::Query('
|
||||
SELECT Artworks.*
|
||||
from Artworks
|
||||
|
|
6
lib/Exceptions/MuseumNotFoundException.php
Normal file
6
lib/Exceptions/MuseumNotFoundException.php
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?
|
||||
namespace Exceptions;
|
||||
|
||||
class MuseumNotFoundException extends AppException{
|
||||
protected $message = 'We couldn’t locate that museum.';
|
||||
}
|
|
@ -5,7 +5,11 @@ class Museum extends PropertiesBase{
|
|||
public $Name;
|
||||
public $Domain;
|
||||
|
||||
public static function GetByUrl(string $url): ?Museum{
|
||||
public static function GetByUrl(?string $url): Museum{
|
||||
if($url === null){
|
||||
throw new Exceptions\MuseumNotFoundException();
|
||||
}
|
||||
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from Museums
|
||||
|
@ -13,6 +17,10 @@ class Museum extends PropertiesBase{
|
|||
limit 1;
|
||||
', [$url], 'Museum');
|
||||
|
||||
return $result[0] ?? null;
|
||||
if($result[0] === null){
|
||||
throw new Exceptions\MuseumNotFoundException();
|
||||
}
|
||||
|
||||
return $result[0];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -88,7 +88,7 @@ if($perPage !== COVER_ARTWORK_PER_PAGE){
|
|||
</span>
|
||||
</label>
|
||||
<label class="search">Keywords
|
||||
<input type="search" name="query" value="<?= Formatter::ToPlainText($query ?? '') ?>"/>
|
||||
<input type="search" name="query" value="<?= Formatter::ToPlainText($query) ?>"/>
|
||||
</label>
|
||||
<label>
|
||||
<span>Sort</span>
|
||||
|
|
|
@ -115,7 +115,9 @@ catch(Exceptions\ArtworkNotFoundException){
|
|||
Template::Emit404();
|
||||
}
|
||||
catch(Exceptions\AppException $exception){
|
||||
$_SESSION['artwork'] = $artwork ?? null;
|
||||
$artwork = $artwork ?? null;
|
||||
|
||||
$_SESSION['artwork'] = $artwork;
|
||||
$_SESSION['exception'] = $exception;
|
||||
|
||||
http_response_code(303);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue