Initial code changes to insert/update Ebook records

This commit is contained in:
Mike Colagrosso 2024-04-20 23:21:48 -06:00 committed by Alex Cabal
parent 073f138c47
commit 63d411a2e6
10 changed files with 531 additions and 28 deletions

43
lib/LocSubject.php Normal file
View 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;
}
}
}