diff --git a/app/Book.php b/app/Book.php index e823360..cc6bec0 100644 --- a/app/Book.php +++ b/app/Book.php @@ -6,7 +6,14 @@ use Illuminate\Database\Eloquent\Model; class Book extends Model { + public $incrementing = false; + + + + protected $keyType = 'string'; + public $fillable = [ + 'id', 'name' ]; diff --git a/app/Chapter.php b/app/Chapter.php index 54d9829..d536291 100644 --- a/app/Chapter.php +++ b/app/Chapter.php @@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\Model; class Chapter extends Model { + public $incrementing = false; + public $fillable = [ + 'id', 'name' ]; diff --git a/app/Handlers/UlbXmlImportHandler.php b/app/Handlers/UlbXmlImportHandler.php index 785a972..c61bbc7 100644 --- a/app/Handlers/UlbXmlImportHandler.php +++ b/app/Handlers/UlbXmlImportHandler.php @@ -58,13 +58,14 @@ class UlbXmlImportHandler $document = $this->openBook($filepath); $book = Book::create([ - 'name' => $bookTitle, + 'id' => strtolower($bookTitle), + 'name' => ucfirst($bookTitle), ]); $chapterCollection = $document->getElementsByTagName('chapter'); foreach ($chapterCollection as $chapterElem) { - $chapter = $this->importChapter($chapterElem); + $chapter = $this->importChapter($chapterElem, $book->id); $book->chapters()->save($chapter); } @@ -75,16 +76,19 @@ class UlbXmlImportHandler * @param DOMElement $chapterElem * @return Chapter */ - public function importChapter(DOMElement $chapterElem) : Chapter + public function importChapter(DOMElement $chapterElem, string $book_id) : Chapter { + $chapterName = $this->parseChapterName($chapterElem); + $chapter = Chapter::create([ - 'name' => $this->parseChapterName($chapterElem), + 'id' => implode('-', [$book_id, $chapterName]), + 'name' => $chapterName, ]); $verseCollection = $chapterElem->getElementsByTagName('verse'); foreach ($verseCollection as $verseElem) { - $verse = $this->importVerse($verseElem); + $verse = $this->importVerse($verseElem, $chapter->id); $chapter->verses()->save($verse); } @@ -95,10 +99,13 @@ class UlbXmlImportHandler * @param DOMElement $verseElem * @return Verse */ - public function importVerse(DOMElement $verseElem) : Verse + public function importVerse(DOMElement $verseElem, string $chapter_id) : Verse { + $verseNumber = $this->parseVerseNumber($verseElem); + $verse = Verse::create([ - 'name' => $this->parseVerseNumber($verseElem), + 'id' => implode('-', [$chapter_id, $verseNumber]), + 'name' => $verseNumber, 'greek_text' => $verseElem->getElementsByTagName('Greek')[0]->nodeValue, 'ulb_text' => $verseElem->getElementsByTagName('ULB')[0]->nodeValue, ]); @@ -106,7 +113,7 @@ class UlbXmlImportHandler $wordCollection = $verseElem->getElementsByTagName('w'); foreach ($wordCollection as $wordElem) { - $word = $this->importWord($wordElem); + $word = $this->importWord($wordElem, $verse->id); $verse->words()->save($word); } @@ -117,17 +124,19 @@ class UlbXmlImportHandler * @param DOMElement $wordElem * @return Word */ - public function importWord(DOMElement $wordElem) : Word + public function importWord(DOMElement $wordElem, string $verse_id) : Word { - // NOTE: We have to switch thins around a bit as the incoming XML file - // use lexeme for lemma and lemma for the strongs number + $ognt_sort = $wordElem->getAttribute('OGNTsort'); + // NOTE: We have to switch things around a bit as the incoming XML file + // uses lexeme for lemma and lemma for the strongs number $word = Word::create([ + 'id' => implode('-', [$verse_id, $ognt_sort]), 'ulb' => $wordElem->nodeValue, 'greek' => $wordElem->getAttribute('text'), 'lemma' => $wordElem->getAttribute('lexeme'), 'morph' => $wordElem->getAttribute('morph'), - 'ognt_sort' => $wordElem->getAttribute('OGNTsort'), + 'ognt_sort' => $ognt_sort, 'strongs_number' => $wordElem->getAttribute('lemma'), ]); diff --git a/app/Verse.php b/app/Verse.php index 999ac25..3d3005e 100644 --- a/app/Verse.php +++ b/app/Verse.php @@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\Model; class Verse extends Model { + public $incrementing = false; + public $fillable = [ + 'id', 'name', 'ulb_text', 'greek_text', diff --git a/app/Word.php b/app/Word.php index 7f71a10..24da51d 100644 --- a/app/Word.php +++ b/app/Word.php @@ -6,7 +6,10 @@ use Illuminate\Database\Eloquent\Model; class Word extends Model { + public $incrementing = false; + public $fillable = [ + 'id', 'ulb', 'greek', 'lemma', diff --git a/database/migrations/2020_10_01_231143_create_books_table.php b/database/migrations/2020_10_01_231143_create_books_table.php index a5a7750..8a8c02e 100644 --- a/database/migrations/2020_10_01_231143_create_books_table.php +++ b/database/migrations/2020_10_01_231143_create_books_table.php @@ -14,7 +14,7 @@ class CreateBooksTable extends Migration public function up() { Schema::create('books', function (Blueprint $table) { - $table->bigIncrements('id'); + $table->string('id')->primary(); $table->string('name'); $table->timestamps(); }); diff --git a/database/migrations/2020_10_01_231230_create_chapters_table.php b/database/migrations/2020_10_01_231230_create_chapters_table.php index f2d09c0..1141f4c 100644 --- a/database/migrations/2020_10_01_231230_create_chapters_table.php +++ b/database/migrations/2020_10_01_231230_create_chapters_table.php @@ -14,9 +14,9 @@ class CreateChaptersTable extends Migration public function up() { Schema::create('chapters', function (Blueprint $table) { - $table->bigIncrements('id'); + $table->string('id')->primary(); $table->string('name'); - $table->bigInteger('book_id')->unsigned()->nullable(); + $table->string('book_id')->nullable(); $table->timestamps(); }); diff --git a/database/migrations/2020_10_01_231308_create_verses_table.php b/database/migrations/2020_10_01_231308_create_verses_table.php index 1e11814..ee89ef5 100644 --- a/database/migrations/2020_10_01_231308_create_verses_table.php +++ b/database/migrations/2020_10_01_231308_create_verses_table.php @@ -14,11 +14,11 @@ class CreateVersesTable extends Migration public function up() { Schema::create('verses', function (Blueprint $table) { - $table->bigIncrements('id'); + $table->string('id')->primary(); $table->string('name'); $table->text('ulb_text'); $table->text('greek_text'); - $table->bigInteger('chapter_id')->unsigned()->nullable(); + $table->string('chapter_id')->nullable(); $table->timestamps(); }); diff --git a/database/migrations/2020_10_01_231338_create_words_table.php b/database/migrations/2020_10_01_231338_create_words_table.php index 536967a..79d7c39 100644 --- a/database/migrations/2020_10_01_231338_create_words_table.php +++ b/database/migrations/2020_10_01_231338_create_words_table.php @@ -14,14 +14,14 @@ class CreateWordsTable extends Migration public function up() { Schema::create('words', function (Blueprint $table) { - $table->bigIncrements('id'); + $table->string('id')->primary(); $table->string('ulb'); $table->string('greek'); $table->string('lemma'); $table->string('morph'); $table->bigInteger('ognt_sort'); $table->string('strongs_number'); - $table->bigInteger('verse_id')->unsigned()->nullable(); + $table->string('verse_id')->nullable(); $table->timestamps(); });