mirror of
https://github.com/standardebooks/web.git
synced 2025-07-13 18:11:52 -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{
|
private function InsertTagStrings(): void{
|
||||||
$tags = [];
|
$tags = [];
|
||||||
foreach($this->Tags as $ebookTag){
|
foreach($this->Tags as $ebookTag){
|
||||||
$tags[] = EbookTag::GetOrCreate($ebookTag);
|
$tags[] = $ebookTag->GetByNameOrCreate($ebookTag->Name);
|
||||||
}
|
}
|
||||||
$this->Tags = $tags;
|
$this->Tags = $tags;
|
||||||
}
|
}
|
||||||
|
@ -629,7 +629,7 @@ class Ebook{
|
||||||
private function InsertLocSubjectStrings(): void{
|
private function InsertLocSubjectStrings(): void{
|
||||||
$subjects = [];
|
$subjects = [];
|
||||||
foreach($this->LocSubjects as $locSubject){
|
foreach($this->LocSubjects as $locSubject){
|
||||||
$subjects[] = LocSubject::GetOrCreate($locSubject);
|
$subjects[] = $locSubject->GetByNameOrCreate($locSubject->Name);
|
||||||
}
|
}
|
||||||
$this->LocSubjects = $subjects;
|
$this->LocSubjects = $subjects;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,19 +44,19 @@ class EbookTag extends Tag{
|
||||||
$this->TagId = Db::GetLastInsertedId();
|
$this->TagId = Db::GetLastInsertedId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetOrCreate(EbookTag $ebookTag): EbookTag{
|
public function GetByNameOrCreate(string $name): EbookTag{
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
SELECT *
|
SELECT *
|
||||||
from Tags
|
from Tags
|
||||||
where Name = ?
|
where Name = ?
|
||||||
', [$ebookTag->Name], 'EbookTag');
|
', [$name], 'EbookTag');
|
||||||
|
|
||||||
if(isset($result[0])){
|
if(isset($result[0])){
|
||||||
return $result[0];
|
return $result[0];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$ebookTag->Create();
|
$this->Create();
|
||||||
return $ebookTag;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,19 +24,19 @@ class LocSubject extends Tag{
|
||||||
$this->LocSubjectId = Db::GetLastInsertedId();
|
$this->LocSubjectId = Db::GetLastInsertedId();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function GetOrCreate(LocSubject $locSubject): LocSubject{
|
public function GetByNameOrCreate(string $name): LocSubject{
|
||||||
$result = Db::Query('
|
$result = Db::Query('
|
||||||
SELECT *
|
SELECT *
|
||||||
from LocSubjects
|
from LocSubjects
|
||||||
where Name = ?
|
where Name = ?
|
||||||
', [$locSubject->Name], 'LocSubject');
|
', [$name], 'LocSubject');
|
||||||
|
|
||||||
if(isset($result[0])){
|
if(isset($result[0])){
|
||||||
return $result[0];
|
return $result[0];
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
$locSubject->Create();
|
$this->Create();
|
||||||
return $locSubject;
|
return $this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue