diff options
-rw-r--r-- | app/Http/Controllers/RootController.php | 24 | ||||
-rw-r--r-- | app/Root.php | 4 | ||||
-rw-r--r-- | app/RootKind.php | 29 | ||||
-rw-r--r-- | database/migrations/2016_09_05_215803_create_root_kinds.php | 45 | ||||
-rw-r--r-- | database/seeds/BasisTableSeeder.php | 64 | ||||
-rw-r--r-- | database/seeds/RootTableSeeder.php | 37 | ||||
-rw-r--r-- | resources/views/add_root.blade.php (renamed from resources/views/add_root.php) | 13 | ||||
-rw-r--r-- | resources/views/suggest.blade.php | 2 |
8 files changed, 176 insertions, 42 deletions
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 @@ +<?php +/** + * HebrewParseTrainer - practice Hebrew verbs + * Copyright (C) 2015 Camil Staps <info@camilstaps.nl> + * + * 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 <http://www.gnu.org/licenses/>. + */ +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 @@ +<?php + +use Illuminate\Database\Schema\Blueprint; +use Illuminate\Database\Migrations\Migration; + +class CreateRootKinds extends Migration +{ + /** + * Run the migrations. + * + * @return void + */ + public function up() + { + Schema::create('root_kinds', function (Blueprint $table) { + $table->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.php b/resources/views/add_root.blade.php index da5cb1c..7da4955 100644 --- a/resources/views/add_root.php +++ b/resources/views/add_root.blade.php @@ -1,3 +1,6 @@ +<?php +use HebrewParseTrainer\RootKind; +?> <div class="panel panel-default"> <div class="panel-heading"> <h3 class="panel-title">Add a new root</h3> @@ -12,6 +15,16 @@ </div> </div> <div class="form-group"> + <label for="add-root-kind" class="col-sm-2 control-label">Kind</label> + <div class="col-sm-10"> + <select id="add-root-kind" class="form-control" name="root_kind_id"> + @foreach(RootKind::all() as $kind) + <option value="{{ $kind->id }}">{{{ $kind->name }}}</option> + @endforeach + </select> + </div> + </div> + <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-primary">Add</button> </div> 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; <label for="suggest-stem" class="col-sm-2 control-label">Stem</label> <div class="col-sm-10"> <select id="suggest-stem" class="form-control" name="stem"> - @foreach(Stem::all() as $stem) + @foreach(Stem::orderBy('id')->get() as $stem) <option value="{{ $stem->name }}">{{{ $stem->name }}}</option> @endforeach </select> |