From 6f6a6abe3c9971b60aad585a198ced6c51329ef5 Mon Sep 17 00:00:00 2001
From: Camil Staps
Date: Tue, 6 Sep 2016 00:23:26 +0200
Subject: Different root kinds instead of only strong/weak
---
app/Http/Controllers/RootController.php | 24 +++++++-
app/Root.php | 4 +-
app/RootKind.php | 29 ++++++++++
.../2016_09_05_215803_create_root_kinds.php | 45 +++++++++++++++
database/seeds/BasisTableSeeder.php | 64 +++++++++++++---------
database/seeds/RootTableSeeder.php | 37 +++++++++----
resources/views/add_root.blade.php | 34 ++++++++++++
resources/views/add_root.php | 21 -------
resources/views/suggest.blade.php | 2 +-
9 files changed, 197 insertions(+), 63 deletions(-)
create mode 100644 app/RootKind.php
create mode 100644 database/migrations/2016_09_05_215803_create_root_kinds.php
create mode 100644 resources/views/add_root.blade.php
delete mode 100644 resources/views/add_root.php
diff --git a/app/Http/Controllers/RootController.php b/app/Http/Controllers/RootController.php
index e3cf3e1..3899754 100644
--- a/app/Http/Controllers/RootController.php
+++ b/app/Http/Controllers/RootController.php
@@ -18,19 +18,37 @@
*/
namespace App\Http\Controllers;
-use HebrewParseTrainer\Root;
-
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Validator;
use Laravel\Lumen\Routing\Controller as BaseController;
+use HebrewParseTrainer\Root;
+use HebrewParseTrainer\RootKind;
+
class RootController extends BaseController {
public function create(Request $request) {
+ $_kinds = RootKind::all();
+ $kinds = [];
+ foreach ($_kinds as $kind)
+ $kinds[] = $kind->id;
+
+ $validator = Validator::make($request->input(), [
+ 'root' => 'required',
+ 'root_kind_id' => 'in:' . implode(',', $kinds),
+ ]);
+
+ if ($validator->fails()) {
+ return [
+ 'success' => false,
+ 'message' => $validator->errors()->first()
+ ];
+ }
+
$root = new Root;
$root->root = $request->input('root');
- $root->strong = 1;
+ $root->root_kind_id = $request->input('root_kind_id');
$root->save();
return [
diff --git a/app/Root.php b/app/Root.php
index a481dab..6c0f033 100644
--- a/app/Root.php
+++ b/app/Root.php
@@ -24,6 +24,6 @@ class Root extends Model {
protected $table = 'roots';
public $timestamps = false;
- protected $fillable = ['root', 'strong'];
+ protected $fillable = ['root', 'root_kind_id'];
-}
\ No newline at end of file
+}
diff --git a/app/RootKind.php b/app/RootKind.php
new file mode 100644
index 0000000..6c68465
--- /dev/null
+++ b/app/RootKind.php
@@ -0,0 +1,29 @@
+
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+namespace HebrewParseTrainer;
+
+use Illuminate\Database\Eloquent\Model;
+
+class RootKind extends Model {
+
+ protected $table = 'root_kinds';
+ public $timestamps = false;
+ protected $fillable = ['strong', 'name'];
+
+}
diff --git a/database/migrations/2016_09_05_215803_create_root_kinds.php b/database/migrations/2016_09_05_215803_create_root_kinds.php
new file mode 100644
index 0000000..2ab1a42
--- /dev/null
+++ b/database/migrations/2016_09_05_215803_create_root_kinds.php
@@ -0,0 +1,45 @@
+increments('id');
+ $table->boolean('strong');
+ $table->string('name')->unique();
+ });
+
+ Schema::table('roots', function (Blueprint $table) {
+ $table->dropColumn('strong');
+
+ $table->integer('root_kind_id')->unsigned()->nullable();
+ $table->foreign('root_kind_id')->references('id')->on('root_kinds');
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('roots', function (Blueprint $table) {
+ $table->dropForeign(['root_kind_id']);
+ $table->dropColumn('root_kind_id');
+
+ $table->boolean('strong')->default(1);
+ });
+
+ Schema::drop('root_kinds');
+ }
+}
diff --git a/database/seeds/BasisTableSeeder.php b/database/seeds/BasisTableSeeder.php
index bf33d75..d02dfe8 100644
--- a/database/seeds/BasisTableSeeder.php
+++ b/database/seeds/BasisTableSeeder.php
@@ -18,35 +18,49 @@
*/
use Illuminate\Database\Seeder;
+
+use HebrewParseTrainer\RootKind;
use HebrewParseTrainer\Stem;
use HebrewParseTrainer\Tense;
class BasisTableSeeder extends Seeder {
- /**
- * Run the database seeds.
- *
- * @return void
- */
- public function run()
- {
- Stem::create(['name' => 'Qal']);
- Stem::create(['name' => 'Niphal']);
- Stem::create(['name' => 'Piel']);
- Stem::create(['name' => 'Pual']);
- Stem::create(['name' => 'Hiphil']);
- Stem::create(['name' => 'Hophal']);
- Stem::create(['name' => 'Hitpael']);
+ /**
+ * Run the database seeds.
+ *
+ * @return void
+ */
+ public function run()
+ {
+ Stem::create(['name' => 'Qal']);
+ Stem::create(['name' => 'Niphal']);
+ Stem::create(['name' => 'Piel']);
+ Stem::create(['name' => 'Pual']);
+ Stem::create(['name' => 'Hiphil']);
+ Stem::create(['name' => 'Hophal']);
+ Stem::create(['name' => 'Hitpael']);
+
+ Tense::create(['name' => 'perfect', 'abbreviation' => 'pf']);
+ Tense::create(['name' => 'imperfect', 'abbreviation' => 'ipf']);
+ Tense::create(['name' => 'cohortative', 'abbreviation' => 'coh']);
+ Tense::create(['name' => 'imperative', 'abbreviation' => 'imp']);
+ Tense::create(['name' => 'jussive', 'abbreviation' => 'ius']);
+ Tense::create(['name' => 'infinitive construct', 'abbreviation' => 'infcs']);
+ Tense::create(['name' => 'infinitive absolute', 'abbreviation' => 'infabs']);
+ Tense::create(['name' => 'participle active', 'abbreviation' => 'pta']);
+ Tense::create(['name' => 'participle passive', 'abbreviation' => 'ptp']);
- Tense::create(['name' => 'perfect', 'abbreviation' => 'pf']);
- Tense::create(['name' => 'imperfect', 'abbreviation' => 'ipf']);
- Tense::create(['name' => 'cohortative', 'abbreviation' => 'coh']);
- Tense::create(['name' => 'imperative', 'abbreviation' => 'imp']);
- Tense::create(['name' => 'jussive', 'abbreviation' => 'ius']);
- Tense::create(['name' => 'infinitive construct', 'abbreviation' => 'infcs']);
- Tense::create(['name' => 'infinitive absolute', 'abbreviation' => 'infabs']);
- Tense::create(['name' => 'participle active', 'abbreviation' => 'pta']);
- Tense::create(['name' => 'participle passive', 'abbreviation' => 'ptp']);
- }
+ RootKind::create(['strong' => true, 'name' => 'Strong']);
+ RootKind::create(['strong' => false, 'name' => 'I-Guttural']);
+ RootKind::create(['strong' => false, 'name' => 'I-Aleph']);
+ RootKind::create(['strong' => false, 'name' => 'I-Nun']);
+ RootKind::create(['strong' => false, 'name' => 'I-Waw']);
+ RootKind::create(['strong' => false, 'name' => 'I-Yod']);
+ RootKind::create(['strong' => false, 'name' => 'II-Guttural']);
+ RootKind::create(['strong' => false, 'name' => 'III-He']);
+ RootKind::create(['strong' => false, 'name' => 'Biconsonantal']);
+ RootKind::create(['strong' => false, 'name' => 'Geminate']);
+ RootKind::create(['strong' => false, 'name' => 'Double weak']);
+ }
-}
\ No newline at end of file
+}
diff --git a/database/seeds/RootTableSeeder.php b/database/seeds/RootTableSeeder.php
index abda56e..7c3b0ea 100644
--- a/database/seeds/RootTableSeeder.php
+++ b/database/seeds/RootTableSeeder.php
@@ -19,20 +19,35 @@
use Illuminate\Database\Seeder;
use HebrewParseTrainer\Root;
+use HebrewParseTrainer\RootKind;
use HebrewParseTrainer\RootTranslation;
class RootTableSeeder extends Seeder {
- /**
- * Run the database seeds.
- *
- * @return void
- */
- public function run()
- {
- Root::create(['root' => 'קטל', 'strong' => true]);
+ protected function add($root, $kind) {
+ $kind_id = null;
+ foreach (RootKind::where('name', $kind)->get() as $rootkind)
+ $kind_id = $rootkind->id;
- RootTranslation::create(['root' => 'קטל', 'translation' => 'kill']);
- }
+ if (is_null($kind_id))
+ die('Unknown root kind ' . $kind . "\n");
-}
\ No newline at end of file
+ Root::create([
+ 'root' => $root,
+ 'root_kind_id' => $kind_id
+ ]);
+ }
+
+ /**
+ * Run the database seeds.
+ *
+ * @return void
+ */
+ public function run()
+ {
+ $this->add('קטל', 'Strong');
+
+ RootTranslation::create(['root' => 'קטל', 'translation' => 'kill']);
+ }
+
+}
diff --git a/resources/views/add_root.blade.php b/resources/views/add_root.blade.php
new file mode 100644
index 0000000..7da4955
--- /dev/null
+++ b/resources/views/add_root.blade.php
@@ -0,0 +1,34 @@
+
+
diff --git a/resources/views/add_root.php b/resources/views/add_root.php
deleted file mode 100644
index da5cb1c..0000000
--- a/resources/views/add_root.php
+++ /dev/null
@@ -1,21 +0,0 @@
-
diff --git a/resources/views/suggest.blade.php b/resources/views/suggest.blade.php
index 1bc50f7..b297060 100644
--- a/resources/views/suggest.blade.php
+++ b/resources/views/suggest.blade.php
@@ -31,7 +31,7 @@ use HebrewParseTrainer\Verb;
--
cgit v1.2.3