From 6a9358178c354dd22c1b7cea488f342209ffb838 Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Sat, 11 May 2024 09:01:32 +0200 Subject: [PATCH] V 0.3.2 Phrase Word MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - index.blade: "Neu"-Button in Übersicht - Word: - Unique-Regel for "word" - Phrase: - Unique-Regel für "phrase" - Phrase: Anlegen: Voreinstellung deutsch, OwnerId - Imperfekt -> Präteritum --- CHANGELOG.md | 13 ++++++ app/Http/Controllers/PhraseController.php | 52 ++++++++++++----------- app/Http/Controllers/WordController.php | 20 ++++++--- composer.lock | 18 ++++---- resources/lang/sources/gadeku.de.json | 2 +- resources/views/phrase/create.blade.php | 4 +- resources/views/phrase/edit.blade.php | 11 +++-- resources/views/phrase/index.blade.php | 1 + resources/views/word/edit-verb.blade.php | 4 +- 9 files changed, 76 insertions(+), 49 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba1ebd7..230badf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,16 @@ +# V 0.3.2 Phrase Word + +## Added +- index.blade: "Neu"-Button in Übersicht +- Word: + - Unique-Regel for "word" +- Phrase: + - Unique-Regel für "phrase" + +## Changes +- Phrase: Anlegen: Voreinstellung deutsch, OwnerId +- Imperfekt -> Präteritum + # V 0.3.1 Note ## Added diff --git a/app/Http/Controllers/PhraseController.php b/app/Http/Controllers/PhraseController.php index f178c2f..3d80f35 100644 --- a/app/Http/Controllers/PhraseController.php +++ b/app/Http/Controllers/PhraseController.php @@ -2,17 +2,20 @@ namespace App\Http\Controllers; +use App\Models\Phrase; +use App\Helpers\Helper; +use App\Helpers\DbHelper; +use App\Models\SProperty; +use App\Helpers\Pagination; +use App\Helpers\ViewHelper; use Illuminate\Http\Request; +use Illuminate\Validation\Rule; +use App\Helpers\ContextLaraKnife; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Validator; -use App\Models\Phrase; -use App\Models\SProperty; -use App\Helpers\ContextLaraKnife; -use App\Helpers\ViewHelper; -use App\Helpers\DbHelper; -use App\Helpers\Helper; -use App\Helpers\Pagination; + +define('GERMAN', 1202); class PhraseController extends Controller { @@ -28,22 +31,18 @@ class PhraseController extends Controller if (count($fields) === 0) { $fields = [ 'phrase' => '', - 'language_scope' => '', + 'language_scope' => GERMAN, 'word_id' => '', 'german_id' => '', - 'owner_id' => '', + 'owner_id' => auth()->id(), 'verifiedby_id' => '' ]; } - $optionsLanguage = SProperty::optionsByScope('language', $fields['language_scope'], '-'); - $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner_id'], __('')); - $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('')); + $optionsLanguage = SProperty::optionsByScope('localization', $fields['language_scope'], '-'); $context = new ContextLaraKnife($request, $fields); $rc = view('phrase.create', [ 'context' => $context, 'optionsLanguage' => $optionsLanguage, - 'optionsOwner' => $optionsOwner, - 'optionsVerifiedby' => $optionsVerifiedby, ]); } return $rc; @@ -164,14 +163,15 @@ LEFT JOIN users t2 ON t2.id=t0.owner_id * Returns the validation rules. * @return array The validation rules. */ - private function rules(bool $isCreate = false): array + private function rules(bool $isCreate = false, int $id=null): array { $rc = [ - 'phrase' => 'required', - 'translation' => 'required', ]; if ($isCreate) { - $rc['language'] = 'required'; + $rc['language_scope'] = 'required'; + $rc['phrase'] = 'required|unique:phrases'; + } else { + $rc['phrase'] = ['required', Rule::unique('phrases')->ignore($id)]; } return $rc; } @@ -179,8 +179,8 @@ LEFT JOIN users t2 ON t2.id=t0.owner_id { Route::get('/phrase-index', [PhraseController::class, 'index'])->middleware('auth'); Route::post('/phrase-index', [PhraseController::class, 'index'])->middleware('auth'); - //Route::get('/phrase-create', [PhraseController::class, 'create'])->middleware('auth'); - //Route::put('/phrase-store', [PhraseController::class, 'store'])->middleware('auth'); + Route::get('/phrase-create', [PhraseController::class, 'create'])->middleware('auth'); + Route::put('/phrase-store', [PhraseController::class, 'store'])->middleware('auth'); Route::post('/phrase-edit/{phrase}', [PhraseController::class, 'edit'])->middleware('auth'); Route::get('/phrase-edit/{phrase}', [PhraseController::class, 'edit'])->middleware('auth'); Route::post('/phrase-update/{phrase}', [PhraseController::class, 'update'])->middleware('auth'); @@ -219,14 +219,16 @@ LEFT JOIN users t2 ON t2.id=t0.owner_id $rc = null; if ($request->btnSubmit === 'btnStore') { $fields = $request->all(); - $validator = Validator::make($fields, $this->rules(true)); + $rules = $this->rules(true); + $validator = Validator::make($fields, $rules); if ($validator->fails()) { + $errors = $validator->errors(); $rc = back()->withErrors($validator)->withInput(); } else { $validated = $validator->validated(); $validated['phrase'] = strip_tags($validated['phrase']); - $validated['translation'] = strip_tags($validated['translation']); - Phrase::create($validated); + $phrase = Phrase::create($validated); + $rc = redirect("/phrase-edit/$phrase->id"); } } if ($rc == null) { @@ -247,14 +249,14 @@ LEFT JOIN users t2 ON t2.id=t0.owner_id } elseif ($request->btnSubmit === 'btnStore') { $id = $phrase->id; $fields = $request->all(); - $validator = Validator::make($fields, $this->rules(false)); + $validator = Validator::make($fields, $this->rules(false, $id)); if ($validator->fails()) { $errors = $validator->errors(); $rc = back()->withErrors($validator)->withInput(); } else { $validated = $validator->validated(); $validated['phrase'] = strip_tags($validated['phrase']); - $validated['translation'] = strip_tags($validated['translation']); + $validated['translation'] = strip_tags($fields['translation']); // Phrase has been changed? $phraseDb = Phrase::find($id); if ($phrase->phrase !== $phraseDb->phrase) { diff --git a/app/Http/Controllers/WordController.php b/app/Http/Controllers/WordController.php index d357b98..9b34171 100644 --- a/app/Http/Controllers/WordController.php +++ b/app/Http/Controllers/WordController.php @@ -12,6 +12,7 @@ use App\Helpers\ViewHelper; use Illuminate\Http\Request; use App\Helpers\StringHelper; use App\Helpers\GermanGrammar; +use Illuminate\Validation\Rule; use App\Helpers\KeyValueStorage; use App\Helpers\ViewHelperLocal; use App\Helpers\ContextLaraKnife; @@ -362,15 +363,23 @@ LEFT JOIN sproperties t1 ON t1.id=t0.wordtype_scope * Returns the validation rules. * @return array The validation rules. */ - private function rules(string $variant): array + private function rules(string $variant, ?Word $word = null): array { switch ($variant) { + case 'store': + $rc = ['word' => 'required|unique:words', 'wordtype_scope' => 'required']; + break; case 'trans': $rc = [ - 'word' => 'required', + 'word' => 'required|unique:words', 'usage' => 'required', 'verifiedby_id' => '' ]; + if ($word == null) { + $rc['word'] = 'required|unique:words'; + } else { + $rc['word'] = ['required', Rule::unique('words')->ignore($word->id)]; + } break; case 'noun': $rc = [ @@ -401,7 +410,7 @@ LEFT JOIN sproperties t1 ON t1.id=t0.wordtype_scope 'c12' => 'required', ]; break; - case 'adjective': + case 'adjective': $rc = [ ]; break; @@ -456,7 +465,8 @@ LEFT JOIN sproperties t1 ON t1.id=t0.wordtype_scope $word = null; if ($request->btnSubmit === 'btnStore') { $fields = $request->all(); - $validator = Validator::make($fields, ['word' => 'required', 'wordtype_scope' => 'required']); + $rules = $this->rules('store'); + $validator = Validator::make($fields, $rules); if ($validator->fails()) { $rc = $validator->errors(); $rc = back()->withErrors($validator)->withInput(); @@ -482,7 +492,7 @@ LEFT JOIN sproperties t1 ON t1.id=t0.wordtype_scope $rc = null; $session = $request->session(); $id = $word->id; - $validator = Validator::make($fields, $this->rules('trans')); + $validator = Validator::make($fields, $this->rules('trans', $word)); if ($validator->fails()) { $errors = $validator->errors(); $rc = back()->withErrors($validator)->withInput(); diff --git a/composer.lock b/composer.lock index eece460..ec2ed47 100644 --- a/composer.lock +++ b/composer.lock @@ -1056,7 +1056,7 @@ "dist": { "type": "path", "url": "../laraknife", - "reference": "542a161082cb090cb635241880b7fd56267d66d1" + "reference": "51702fba5a786ac71dd1628e7aee3aae747d6003" }, "require-dev": { "phpunit/phpunit": "11.0.x-dev" @@ -2711,20 +2711,20 @@ }, { "name": "psr/http-factory", - "version": "1.0.2", + "version": "1.1.0", "source": { "type": "git", "url": "https://github.com/php-fig/http-factory.git", - "reference": "e616d01114759c4c489f93b099585439f795fe35" + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-fig/http-factory/zipball/e616d01114759c4c489f93b099585439f795fe35", - "reference": "e616d01114759c4c489f93b099585439f795fe35", + "url": "https://api.github.com/repos/php-fig/http-factory/zipball/2b4765fddfe3b508ac62f829e852b1501d3f6e8a", + "reference": "2b4765fddfe3b508ac62f829e852b1501d3f6e8a", "shasum": "" }, "require": { - "php": ">=7.0.0", + "php": ">=7.1", "psr/http-message": "^1.0 || ^2.0" }, "type": "library", @@ -2748,7 +2748,7 @@ "homepage": "https://www.php-fig.org/" } ], - "description": "Common interfaces for PSR-7 HTTP message factories", + "description": "PSR-17: Common interfaces for PSR-7 HTTP message factories", "keywords": [ "factory", "http", @@ -2760,9 +2760,9 @@ "response" ], "support": { - "source": "https://github.com/php-fig/http-factory/tree/1.0.2" + "source": "https://github.com/php-fig/http-factory" }, - "time": "2023-04-10T20:10:41+00:00" + "time": "2024-04-15T12:06:14+00:00" }, { "name": "psr/http-message", diff --git a/resources/lang/sources/gadeku.de.json b/resources/lang/sources/gadeku.de.json index 806f65a..80cbedd 100644 --- a/resources/lang/sources/gadeku.de.json +++ b/resources/lang/sources/gadeku.de.json @@ -19,13 +19,13 @@ "free text": "Freier Text", "Genus": "Geschlecht", "grammar rules": "Grammatikregeln", -"Imperfect": "Imperfekt", "masculine": "Maskulinum", "neuter": "Neutrum", "Not verified": "Nicht überprüft", "Noun": "Nomen", "Nouns": "Nomen", "Participle": "Partizip", +"Past tense": "Präteritum", "Phrase": "Satz", "Phrases": "Sätze", "Preposition": "Präposition", diff --git a/resources/views/phrase/create.blade.php b/resources/views/phrase/create.blade.php index 2112871..de600b3 100644 --- a/resources/views/phrase/create.blade.php +++ b/resources/views/phrase/create.blade.php @@ -6,9 +6,7 @@ @method('PUT') - - - + diff --git a/resources/views/phrase/edit.blade.php b/resources/views/phrase/edit.blade.php index 12698f2..3795610 100644 --- a/resources/views/phrase/edit.blade.php +++ b/resources/views/phrase/edit.blade.php @@ -1,13 +1,16 @@ @extends('layouts.backend') @section('content') -
+ @csrf - - - + + +
@endsection diff --git a/resources/views/phrase/index.blade.php b/resources/views/phrase/index.blade.php index 43d1ff3..47d64e8 100644 --- a/resources/views/phrase/index.blade.php +++ b/resources/views/phrase/index.blade.php @@ -9,6 +9,7 @@ + diff --git a/resources/views/word/edit-verb.blade.php b/resources/views/word/edit-verb.blade.php index 83457a6..254335b 100644 --- a/resources/views/word/edit-verb.blade.php +++ b/resources/views/word/edit-verb.blade.php @@ -26,13 +26,13 @@ value="{{ $context->valueOf('c5') }}" width1="1" width2="2" /> - - -- 2.39.5