mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -04:00
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:
parent
74f747df76
commit
6a5c05511a
92 changed files with 3174 additions and 146 deletions
66
lib/ArtworkTag.php
Normal file
66
lib/ArtworkTag.php
Normal file
|
@ -0,0 +1,66 @@
|
|||
<?
|
||||
|
||||
class ArtworkTag extends Tag{
|
||||
// *******
|
||||
// GETTERS
|
||||
// *******
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
protected function GetUrl(): string{
|
||||
if($this->_Url === null){
|
||||
$this->_Url = '/artworks?query=' . Formatter::MakeUrlSafe($this->Name);
|
||||
}
|
||||
|
||||
return $this->_Url;
|
||||
}
|
||||
|
||||
// *******
|
||||
// METHODS
|
||||
// *******
|
||||
protected function Validate(): void{
|
||||
$error = new Exceptions\ValidationException();
|
||||
|
||||
if($this->Name === null || strlen($this->Name) === 0){
|
||||
$error->Add(new Exceptions\InvalidArtworkTagException());
|
||||
}
|
||||
|
||||
if($this->Url === null || strlen($this->Url) === 0){
|
||||
$error->Add(new Exceptions\InvalidArtworkTagException());
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
public function Create(): void{
|
||||
$this->Validate();
|
||||
|
||||
Db::Query('
|
||||
INSERT into Tags (Name)
|
||||
values (?)
|
||||
', [$this->Name]);
|
||||
$this->TagId = Db::GetLastInsertedId();
|
||||
}
|
||||
|
||||
/**
|
||||
* @throws \Exceptions\ValidationException
|
||||
*/
|
||||
public static function GetOrCreate(ArtworkTag $artworkTag): ArtworkTag{
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from Tags
|
||||
where Name = ?
|
||||
', [$artworkTag->Name], 'ArtworkTag');
|
||||
|
||||
if(isset($result[0])){
|
||||
return $result[0];
|
||||
}
|
||||
else{
|
||||
$artworkTag->Create();
|
||||
return $artworkTag;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue