mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 10:02:02 -04:00
Replace static GetOrCreate with GetByNameOrCreate
This commit is contained in:
parent
4a1a4efb24
commit
cc8de11ca4
3 changed files with 10 additions and 10 deletions
|
@ -621,7 +621,7 @@ class Ebook{
|
|||
private function InsertTagStrings(): void{
|
||||
$tags = [];
|
||||
foreach($this->Tags as $ebookTag){
|
||||
$tags[] = EbookTag::GetOrCreate($ebookTag);
|
||||
$tags[] = $ebookTag->GetByNameOrCreate($ebookTag->Name);
|
||||
}
|
||||
$this->Tags = $tags;
|
||||
}
|
||||
|
@ -629,7 +629,7 @@ class Ebook{
|
|||
private function InsertLocSubjectStrings(): void{
|
||||
$subjects = [];
|
||||
foreach($this->LocSubjects as $locSubject){
|
||||
$subjects[] = LocSubject::GetOrCreate($locSubject);
|
||||
$subjects[] = $locSubject->GetByNameOrCreate($locSubject->Name);
|
||||
}
|
||||
$this->LocSubjects = $subjects;
|
||||
}
|
||||
|
|
|
@ -44,19 +44,19 @@ class EbookTag extends Tag{
|
|||
$this->TagId = Db::GetLastInsertedId();
|
||||
}
|
||||
|
||||
public static function GetOrCreate(EbookTag $ebookTag): EbookTag{
|
||||
public function GetByNameOrCreate(string $name): EbookTag{
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from Tags
|
||||
where Name = ?
|
||||
', [$ebookTag->Name], 'EbookTag');
|
||||
', [$name], 'EbookTag');
|
||||
|
||||
if(isset($result[0])){
|
||||
return $result[0];
|
||||
}
|
||||
else{
|
||||
$ebookTag->Create();
|
||||
return $ebookTag;
|
||||
$this->Create();
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,19 +24,19 @@ class LocSubject extends Tag{
|
|||
$this->LocSubjectId = Db::GetLastInsertedId();
|
||||
}
|
||||
|
||||
public static function GetOrCreate(LocSubject $locSubject): LocSubject{
|
||||
public function GetByNameOrCreate(string $name): LocSubject{
|
||||
$result = Db::Query('
|
||||
SELECT *
|
||||
from LocSubjects
|
||||
where Name = ?
|
||||
', [$locSubject->Name], 'LocSubject');
|
||||
', [$name], 'LocSubject');
|
||||
|
||||
if(isset($result[0])){
|
||||
return $result[0];
|
||||
}
|
||||
else{
|
||||
$locSubject->Create();
|
||||
return $locSubject;
|
||||
$this->Create();
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue