mirror of
https://github.com/standardebooks/web.git
synced 2025-07-15 02:46:46 -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
43
lib/LocSubject.php
Normal file
43
lib/LocSubject.php
Normal file
|
@ -0,0 +1,43 @@
|
|||
<?
|
||||
class LocSubject extends Tag{
|
||||
public int $LocSubjectId;
|
||||
public string $Name;
|
||||
|
||||
public function Validate(): void{
|
||||
$error = new Exceptions\ValidationException();
|
||||
|
||||
if(strlen($this->Name) > EBOOKS_MAX_STRING_LENGTH){
|
||||
$error->Add(new Exceptions\StringTooLongException('LoC subject: '. $this->Name));
|
||||
}
|
||||
|
||||
if($error->HasExceptions){
|
||||
throw $error;
|
||||
}
|
||||
}
|
||||
|
||||
public function Create(): void{
|
||||
$this->Validate();
|
||||
|
||||
Db::Query('
|
||||
INSERT into LocSubjects (Name)
|
||||
values (?)
|
||||
', [$this->Name]);
|
||||
$this->LocSubjectId = Db::GetLastInsertedId();
|
||||
}
|
||||
|
||||
public static function GetOrCreate(LocSubject $locSubject): LocSubject{
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from LocSubjects
|
||||
where Name = ?
|
||||
', [$locSubject->Name], 'LocSubject');
|
||||
|
||||
if(isset($result[0])){
|
||||
return $result[0];
|
||||
}
|
||||
else{
|
||||
$locSubject->Create();
|
||||
return $locSubject;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue