From: Hamatoma Date: Sat, 13 Apr 2024 20:19:47 +0000 (+0200) Subject: V 0.1.7 Übersetzungen in Words X-Git-Url: https://gitweb.hamatoma.de/?a=commitdiff_plain;h=2e1dc67c088c2be4c692723e11db101ef484b262;p=gadeku.git V 0.1.7 Übersetzungen in Words - Phrase: - Setzen/Löschen von verifiedby_id - Word - Behandlung von Übersetzungen - Setzen/Löschen von verifiedby_id - Word: - Attribut word_id --- diff --git a/CHANGELOG.md b/CHANGELOG.md index 0cbfcc3..60d33d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,29 +1,42 @@ +# V 0.1.7 Übersetzungen in Words + +## Added: +- Phrase: + - Setzen/Löschen von verifiedby_id +- Word + - Behandlung von Übersetzungen + - Setzen/Löschen von verifiedby_id + +## Changed +- Word: + - Attribut word_id + # V 0.1.6 Verbesserungen in Phrase -# Added: +## Added: - Phrases: - Anzeige Übersetzung - Combobox "Sprache" in Tabelle integriert. -# Changed +## Changed - Phrases: - Autoupdate von Combobox "Sprache" # V 0.1.5 Phrases: Übersetzung -# Added: +## Added: - Phrases: - neues Attribut phrase_id: zeigt auf deutschen Satz - Übersetzungen in andere Sprachen - Words: Löschen nur wenn Admin -# Changed +## Changed - Falsche Id von "Deutsch (Deutschland)" bei sproperty scope "localization" # V 0.1.4 Korrekturen Verb -# Changed +## Changed - Korrektur Edieren Verb: Anzeige von "Verwendung" - Korrektur Edieren Verb: Behandlung "transitiv" diff --git a/app/Http/Controllers/PhraseController.php b/app/Http/Controllers/PhraseController.php index 3f47a1a..1c31c0a 100644 --- a/app/Http/Controllers/PhraseController.php +++ b/app/Http/Controllers/PhraseController.php @@ -262,10 +262,13 @@ LEFT JOIN users t2 ON t2.id=t0.owner_id // Phrase has been changed? $phraseDb = Phrase::find($id); if ($phrase->phrase !== $phraseDb->phrase) { - // Invalidate all verifications: - DB::update("update phrases set validatedby_id=None where phrase_id=$id;"); + // Invalidate all verifications in all languages:: + DB::update("UPDATE phrases SET verifiedby_id=NULL where phrase_id=$id;"); // Store new phrase: - $phrase->update(['phrase' => $validated['phrase'], 'verifiedby_id' => null]); + $phrase->update(['phrase' => $validated['phrase']]); + } elseif ($phrase->verifiedby_id == null){ + $id2 = auth()->id(); + DB::update("UPDATE phrases SET verifiedby_id=$id2 where phrase_id=$id;"); } // Does translation already exists? $phraseTranslation = Phrase::where(['language_scope' => $fields['language'], 'phrase_id' => $phrase->id])->first(); diff --git a/app/Http/Controllers/WordController.php b/app/Http/Controllers/WordController.php index eb5ccf8..15b5402 100644 --- a/app/Http/Controllers/WordController.php +++ b/app/Http/Controllers/WordController.php @@ -2,17 +2,18 @@ namespace App\Http\Controllers; +use App\Models\Word; +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 App\Helpers\ContextLaraKnife; use Illuminate\Support\Facades\DB; use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Validator; -use App\Models\Word; -use App\Models\SProperty; -use App\Helpers\ContextLaraKnife; -use App\Helpers\ViewHelper; -use App\Helpers\DbHelper; -use App\Helpers\Helper; -use App\Helpers\Pagination; class WordController extends Controller { @@ -35,12 +36,12 @@ class WordController extends Controller } $optionsWordtype = SProperty::optionsByScope('wordtype', $fields['wordtype_scope'], '-'); $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('')); - $context = new ContextLaraKnife($request, $fields); + $context = new ContextLaraKnife($request, $fields); $rc = view('word.create', [ 'context' => $context, 'optionsWordtype' => $optionsWordtype, 'optionsVerifiedby' => $optionsVerifiedby, - ]); + ]); } return $rc; } @@ -53,22 +54,46 @@ class WordController extends Controller $rc = redirect('/word-index'); } else { $fields = $request->all(); - if (count($fields) === 0) { + $phrase = Phrase::where(['word_id' => $word->id, 'language_scope' => 1202])->first(); + if ($phrase == null){ + $phrase = Phrase::create(['word_id' => $word->id, 'phrase' => $word->word, + 'language_scope' => 1202, 'owner_id' => auth()->id()]); + } + if (count($fields) === 1) { $fields = [ - 'word' => '', - 'usage' => '', - 'wordtype_scope' => '', - 'verifiedby_id' => '' - ]; + 'word' => $word->word, + 'usage' => $phrase->phrase, + 'wordtype_scope' => $phrase->wordtype_scope, + 'language' => $request->language, + 'lastLanguage' => '', + 'translation' => '' + ]; + } elseif (count($fields) === 0) { + $fields = [ + 'word' => $word->word, + 'usage' => $phrase->phrase, + 'wordtype_scope' => $phrase->wordtype_scope, + 'language' => $request->language, + 'language' => SProperty::idOfLocalization(), + 'lastLanguage' => '', + 'translation' => '' + ]; } + if ($fields['translation'] === '' || $fields['lastLanguage'] != $fields['language']) { + $phraseTranslation = Word::where(['language_scope' => $fields['language'], 'word_id' => $word->id])->first(); + if ($phraseTranslation != null) { + $fields['translation'] = $phraseTranslation->word; + } + } + $fields['lastLanguage'] = $fields['language']; $optionsWordtype = SProperty::optionsByScope('wordtype', $word->wordtype_scope, ''); - $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('')); - $context = new ContextLaraKnife($request, null, $word); + $optionsLanguage = SProperty::optionsByScope('localization', $fields['language'], ''); + $context = new ContextLaraKnife($request, $fields, $word); $rc = view('word.edit', [ 'context' => $context, 'optionsWordtype' => $optionsWordtype, - 'optionsVerifiedby' => $optionsVerifiedby, - ]); + 'optionsLanguage' => $optionsLanguage, + ]); } return $rc; } @@ -90,44 +115,52 @@ class WordController extends Controller if ($request->btnSubmit === 'btnNew') { return redirect('/word-create'); } else { - $sql = 'SELECT t0.*, t1.name as wordtype, t2.name as verifiedby, t3.name as owner' - . ' FROM words t0' - . ' LEFT JOIN sproperties t1 ON t1.id=t0.wordtype_scope' - . ' LEFT JOIN sproperties t2 ON t2.id=t0.verifiedby_id' - . ' LEFT JOIN sproperties t3 ON t3.id=t0.owner_id' - ; - $parameters = []; $fields = $request->all(); + $lang = count($fields) == 0 ? SProperty::idOfLocalization() : $fields['language']; + $sql = " +SELECT t0.*, t1.name as wordtype, + (select word from words t4 where t4.word_id=t0.id and t4.language_scope=$lang) as translation +FROM words t0 +LEFT JOIN sproperties t1 ON t1.id=t0.wordtype_scope +"; + $parameters = []; + $conditions = []; if (count($fields) == 0) { $fields = [ - 'wordtype' => '', - 'verifiedby' => '', - 'owner' => '', - 'word' => '', - 'usage' => '', - '_sortParams' => 't0.word:asc;id:asc' + 'language' => SProperty::idOfLocalization(), + 'wordtype' => '', + 'verified' => '', + 'owner' => '', + 'word' => '', + 'usage' => '', + '_sortParams' => 't0.word:asc;id:asc' ]; } else { - $conditions = []; ViewHelper::addConditionPattern($conditions, $parameters, 't0.word', 'name'); ViewHelper::addConditionComparism($conditions, $parameters, 'wordtype_scope', 'wordtype'); - ViewHelper::addConditionComparism($conditions, $parameters, 'verifiedby_id', 'verifiedby'); ViewHelper::addConditionComparism($conditions, $parameters, 'owner_id', 'owner'); ViewHelper::addConditionPattern($conditions, $parameters, 'usage'); - $sql = DbHelper::addConditions($sql, $conditions); } + ViewHelper::addConditionConstComparison($conditions, $parameters, 't0.language_scope', 1202); + $sql = DbHelper::addConditions($sql, $conditions); $sql = DbHelper::addOrderBy($sql, $fields['_sortParams']); $pagination = new Pagination($sql, $parameters, $fields); $records = $pagination->records; $optionsWordtype = SProperty::optionsByScope('wordtype', $fields['wordtype'], 'all'); - $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby'], __('')); + $optionsLanguage = SProperty::optionsByScope('localization', $fields['language']); $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner'], __('')); + $optionsVerified = [ + ['text' => __(''), 'value' => '', 'active' => $fields['verified'] == ''], + ['text' => __('Not verified'), 'value' => 1, 'active' => $fields['verified'] == 1], + ['text' => __('Verified'), 'value' => 2, 'active' => $fields['verified'] == 2] + ]; $context = new ContextLaraKnife($request, $fields); + $context->setCombobox('language', 'Language', $optionsLanguage, '', 'lkn-autoupdate'); return view('word.index', [ 'context' => $context, 'records' => $records, 'optionsWordtype' => $optionsWordtype, - 'optionsVerifiedby' => $optionsVerifiedby, + 'optionsVerified' => $optionsVerified, 'optionsOwner' => $optionsOwner, 'pagination' => $pagination ]); @@ -137,7 +170,7 @@ class WordController extends Controller * Returns the validation rules. * @return array The validation rules. */ - private function rules(bool $isCreate=false): array + private function rules(bool $isCreate = false): array { $rc = [ 'name' => 'required', @@ -175,7 +208,7 @@ class WordController extends Controller 'optionsWordtype' => $optionsWordtype, 'optionsVerifiedby' => $optionsVerifiedby, 'mode' => 'delete' - ]); + ]); } return $rc; } @@ -193,11 +226,11 @@ class WordController extends Controller $rc = back()->withErrors($validator)->withInput(); } else { $validated = $validator->validated(); - $validated['usage'] = strip_tags($validated['usage']); + $validated['usage'] = strip_tags($validated['usage']); Word::create($validated); } } - if ($rc == null){ + if ($rc == null) { $rc = redirect('/word-index'); } return $rc; @@ -209,7 +242,12 @@ class WordController extends Controller { $rc = null; $session = $request->session(); - if ($request->btnSubmit === 'btnStore') { + if ($request->btnSubmit === 'btnInternal') { + // Language combobox has been changed: + $url = "/word-edit/$word->id?language=" . $request->language; + $rc = redirect($url); + } elseif ($request->btnSubmit === 'btnStore') { + $id = $word->id; $fields = $request->all(); $validator = Validator::make($fields, $this->rules(false)); if ($validator->fails()) { @@ -218,10 +256,38 @@ class WordController extends Controller } else { $validated = $validator->validated(); $validated['usage'] = strip_tags($validated['usage']); - $word->update($validated); + // Word has been changed? + $wordDb = Word::find($id); + if ($word->word !== $wordDb->word) { + // Invalidate all verifications in all languages: + DB::update("UPDATE phrases SET verifiedby_id=NULL WHERE word_id=$id;"); + // Store new phrase: + $word->update(['phrase' => $validated['phrase']]); + } + // Does translation already exists? + $wordTranslation = word::where(['language_scope' => $fields['language'], 'word_id' => $word->id])->first(); + if ($wordTranslation == null) { + // Store the new record: + word::create([ + 'word_id' => $id, + 'word' => $fields['translation'], + 'wordtype_scope' => $word->wordtype_scope, + 'owner_id' => auth()->id(), + 'language_scope' => $fields['language'] + ]); + } else { + // Update only if changed: + if ($wordTranslation->word !== $fields['translation']) { + $wordTranslation->update(['word' => $validated['translation'], 'verifiedby_id' => null]); + } else if ($word->verifiedby_id == null){ + $wordTranslation->update(['verifiedby_id' => auth()->id()]); + } + } + } + $lang = $fields['language']; + $rc = redirect("/word-edit/$id?language=$lang"); } - } - if ($rc == null){ + if ($rc == null) { $rc = redirect('/word-index'); } return $rc; diff --git a/app/Models/Word.php b/app/Models/Word.php index bbcd1d5..a66217e 100644 --- a/app/Models/Word.php +++ b/app/Models/Word.php @@ -17,7 +17,7 @@ class Word extends Model 'usage', 'wordtype_scope', 'language_scope', - 'baselanguage_id', + 'word_id', 'verifiedby_id', 'owner_id' ]; diff --git a/composer.lock b/composer.lock index e336d50..6c22dbf 100644 --- a/composer.lock +++ b/composer.lock @@ -1051,7 +1051,7 @@ "dist": { "type": "path", "url": "../laraknife", - "reference": "47a41b7a9e0479870ed354c33653009296af812d" + "reference": "0578f3c7527bb061c7671f3d9f9ffe2db04688f9" }, "require-dev": { "phpunit/phpunit": "11.0.x-dev" @@ -1926,16 +1926,16 @@ }, { "name": "monolog/monolog", - "version": "3.5.0", + "version": "3.6.0", "source": { "type": "git", "url": "https://github.com/Seldaek/monolog.git", - "reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448" + "reference": "4b18b21a5527a3d5ffdac2fd35d3ab25a9597654" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/Seldaek/monolog/zipball/c915e2634718dbc8a4a15c61b0e62e7a44e14448", - "reference": "c915e2634718dbc8a4a15c61b0e62e7a44e14448", + "url": "https://api.github.com/repos/Seldaek/monolog/zipball/4b18b21a5527a3d5ffdac2fd35d3ab25a9597654", + "reference": "4b18b21a5527a3d5ffdac2fd35d3ab25a9597654", "shasum": "" }, "require": { @@ -1958,7 +1958,7 @@ "phpstan/phpstan": "^1.9", "phpstan/phpstan-deprecation-rules": "^1.0", "phpstan/phpstan-strict-rules": "^1.4", - "phpunit/phpunit": "^10.1", + "phpunit/phpunit": "^10.5.17", "predis/predis": "^1.1 || ^2", "ruflin/elastica": "^7", "symfony/mailer": "^5.4 || ^6", @@ -2011,7 +2011,7 @@ ], "support": { "issues": "https://github.com/Seldaek/monolog/issues", - "source": "https://github.com/Seldaek/monolog/tree/3.5.0" + "source": "https://github.com/Seldaek/monolog/tree/3.6.0" }, "funding": [ { @@ -2023,7 +2023,7 @@ "type": "tidelift" } ], - "time": "2023-10-27T15:32:31+00:00" + "time": "2024-04-12T21:02:21+00:00" }, { "name": "nesbot/carbon", diff --git a/database/migrations/2024_04_13_131901_change_words_word_id.php b/database/migrations/2024_04_13_131901_change_words_word_id.php new file mode 100644 index 0000000..8d93f93 --- /dev/null +++ b/database/migrations/2024_04_13_131901_change_words_word_id.php @@ -0,0 +1,26 @@ +renameColumn('baselanguage_id', 'word_id'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + // + } +}; diff --git a/resources/views/phrase/index.blade.php b/resources/views/phrase/index.blade.php index 06bf963..43d1ff3 100644 --- a/resources/views/phrase/index.blade.php +++ b/resources/views/phrase/index.blade.php @@ -23,7 +23,7 @@ {{$phrase->phrase}} - {{ __($phrase->translation) }} + {{ $phrase->translation }} @endforeach diff --git a/resources/views/word/edit.blade.php b/resources/views/word/edit.blade.php index 692866a..1b61756 100644 --- a/resources/views/word/edit.blade.php +++ b/resources/views/word/edit.blade.php @@ -4,14 +4,16 @@
@csrf - - + + + + -
@endsection diff --git a/resources/views/word/index.blade.php b/resources/views/word/index.blade.php index e8b01a4..75cdf49 100644 --- a/resources/views/word/index.blade.php +++ b/resources/views/word/index.blade.php @@ -7,7 +7,7 @@ - @@ -19,9 +19,8 @@ {{ __('Name') }} + {{__('Translation')}} {{ __('Wordtype') }} - {{ __('Verifiedby') }} - {{ __('Owner') }} @if ($context->isAdmin()) @endif @@ -32,9 +31,8 @@ {{ $word->word }} + {{ $word->translation }} {{ __($word->wordtype) }} - {{ $word->verifiedby }} - {{ $word->owner }} @if ($context->isAdmin()) @endif