mirror of
https://github.com/standardebooks/web.git
synced 2025-07-14 10:31:59 -04:00
Initial code changes to insert/update Ebook records
This commit is contained in:
parent
073f138c47
commit
63d411a2e6
10 changed files with 531 additions and 28 deletions
|
@ -1,14 +1,15 @@
|
|||
<?
|
||||
class EbookTag extends Tag{
|
||||
public function __construct(string $name){
|
||||
$this->Name = $name;
|
||||
$this->UrlName = Formatter::MakeUrlSafe($this->Name);
|
||||
$this->_Url = '/subjects/' . $this->UrlName;
|
||||
}
|
||||
|
||||
// *******
|
||||
// GETTERS
|
||||
// *******
|
||||
protected function GetUrlName(): string{
|
||||
if($this->_UrlName === null){
|
||||
$this->_UrlName = Formatter::MakeUrlSafe($this->Name);
|
||||
}
|
||||
|
||||
return $this->_UrlName;
|
||||
}
|
||||
|
||||
protected function GetUrl(): string{
|
||||
if($this->_Url === null){
|
||||
|
@ -17,4 +18,45 @@ class EbookTag extends Tag{
|
|||
|
||||
return $this->_Url;
|
||||
}
|
||||
|
||||
// *******
|
||||
// METHODS
|
||||
// *******
|
||||
public function Validate(): void{
|
||||
$error = new Exceptions\ValidationException();
|
||||
|
||||
if(strlen($this->Name) > EBOOKS_MAX_STRING_LENGTH){
|
||||
$error->Add(new Exceptions\StringTooLongException('Ebook tag: '. $this->Name));
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
public function Create(): void{
|
||||
$this->Validate();
|
||||
|
||||
Db::Query('
|
||||
INSERT into Tags (Name)
|
||||
values (?)
|
||||
', [$this->Name]);
|
||||
$this->TagId = Db::GetLastInsertedId();
|
||||
}
|
||||
|
||||
public static function GetOrCreate(EbookTag $ebookTag): EbookTag{
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from Tags
|
||||
where Name = ?
|
||||
', [$ebookTag->Name], 'EbookTag');
|
||||
|
||||
if(isset($result[0])){
|
||||
return $result[0];
|
||||
}
|
||||
else{
|
||||
$ebookTag->Create();
|
||||
return $ebookTag;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue