From cc8de11ca4121a4da2a10c2b668f69844df0590d Mon Sep 17 00:00:00 2001 From: Mike Colagrosso Date: Sun, 21 Apr 2024 22:55:01 -0600 Subject: [PATCH] Replace static GetOrCreate with GetByNameOrCreate --- lib/Ebook.php | 4 ++-- lib/EbookTag.php | 8 ++++---- lib/LocSubject.php | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/Ebook.php b/lib/Ebook.php index 84184ca1..50208fd3 100644 --- a/lib/Ebook.php +++ b/lib/Ebook.php @@ -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; } diff --git a/lib/EbookTag.php b/lib/EbookTag.php index 3b372083..1c6f1aa0 100644 --- a/lib/EbookTag.php +++ b/lib/EbookTag.php @@ -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; } } } diff --git a/lib/LocSubject.php b/lib/LocSubject.php index f9602603..e0ca42a1 100644 --- a/lib/LocSubject.php +++ b/lib/LocSubject.php @@ -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; } } }