From c5a9259c0d63cfff7394a8b1774c807c756fe7ab Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Thu, 11 Apr 2024 22:53:08 +0200 Subject: [PATCH] 0.1.6 Verbesserungen in Phrase MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Added: - Phrases: - Anzeige Übersetzung - Combobox "Sprache" in Tabelle integriert. Changed - Phrases: - Autoupdate von Combobox "Sprache" --- CHANGELOG.md | 11 ++++ app/Http/Controllers/PhraseController.php | 67 +++++++++++++---------- composer.lock | 12 ++-- lang/de_DE.json | 3 + resources/lang/sources/gadeku.de.json | 3 + resources/views/phrase/index.blade.php | 13 ++--- 6 files changed, 65 insertions(+), 44 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6bf25ac..0cbfcc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,14 @@ +# V 0.1.6 Verbesserungen in Phrase + +# Added: +- Phrases: + - Anzeige Übersetzung + - Combobox "Sprache" in Tabelle integriert. + +# Changed +- Phrases: + - Autoupdate von Combobox "Sprache" + # V 0.1.5 Phrases: Übersetzung # Added: diff --git a/app/Http/Controllers/PhraseController.php b/app/Http/Controllers/PhraseController.php index 3a01dd0..3f47a1a 100644 --- a/app/Http/Controllers/PhraseController.php +++ b/app/Http/Controllers/PhraseController.php @@ -61,7 +61,7 @@ class PhraseController extends Controller $rc = redirect('/phrase-index'); } else { $fields = $request->all(); - if (count($fields) === 1){ + if (count($fields) === 1) { $fields = [ 'phrase' => '', 'language' => $request->language, @@ -76,9 +76,9 @@ class PhraseController extends Controller 'translation' => '' ]; } - if ($fields['lastLanguage'] != $fields['language']){ + if ($fields['lastLanguage'] != $fields['language']) { $phraseTranslation = Phrase::where(['language_scope' => $fields['language'], 'phrase_id' => $phrase->id])->first(); - if ($phraseTranslation != null){ + if ($phraseTranslation != null) { $fields['translation'] = $phraseTranslation->phrase; } } @@ -110,47 +110,56 @@ class PhraseController extends Controller if ($request->btnSubmit === 'btnNew') { return redirect('/phrase-create'); } else { - $sql = 'SELECT t0.*,' - . 't1.name as language_scope, ' - . 't2.name as owner_id, ' - . 't3.name as verifiedby_id ' - . ' FROM phrases t0' - . ' LEFT JOIN sproperties t1 ON t1.id=t0.language_scope' - . ' LEFT JOIN sproperties t2 ON t2.id=t0.owner_id' - . ' LEFT JOIN sproperties t3 ON t3.id=t0.verifiedby_id' - ; - $parameters = []; $fields = $request->all(); + $lang = count($fields) == 0 ? SProperty::idOfLocalization() : $fields['language']; + $sql = " +SELECT t0.*, + t1.name as language_scope, + (select phrase from phrases t4 where t4.phrase_id=t0.id and t4.language_scope=$lang) as translation +FROM phrases t0 +LEFT JOIN sproperties t1 ON t1.id=t0.language_scope +LEFT JOIN users t2 ON t2.id=t0.owner_id +"; + $parameters = []; + $conditions = []; if (count($fields) == 0) { $fields = [ - 'language' => '', + 'language' => SProperty::idOfLocalization(), 'word' => '', 'phrase' => '', 'owner' => '', - 'verifiedby' => '', + 'verified' => '', '_sortParams' => 't0.phrase:asc;t0.id:desc' ]; } else { - $conditions = []; - ViewHelper::addConditionComparism($conditions, $parameters, 'language_scope', 'language'); - ViewHelper::addConditionComparism($conditions, $parameters, 'owner_id', 'owner'); - ViewHelper::addConditionComparism($conditions, $parameters, 'verifiedby_id', 'verifiedby'); - ViewHelper::addConditionPattern($conditions, $parameters, 'phrase', 'text'); - $sql = DbHelper::addConditions($sql, $conditions); + ViewHelper::addConditionComparism($conditions, $parameters, 't0.owner_id', 'owner'); + $lang = $fields['language']; + if ($fields['verified'] != null) { + // 1: not verified 2: verified + $not = $fields['verified'] == 1 ? '' : ' NOT'; + array_push($conditions, "EXISTS(SELECT id FROM phrases ph WHERE ph.id=t0.phrase_id AND ph.language_scope=$lang AND ph.verifiedby_id IS$not NULL)"); + } + ViewHelper::addConditionPattern($conditions, $parameters, 't0.phrase', 'text'); } + 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; - $optionsLanguage = SProperty::optionsByScope('language', $fields['language'], 'all'); - $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner'], __('')); - $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('phrase.index', [ 'context' => $context, 'records' => $records, - 'optionsLanguage' => $optionsLanguage, 'optionsOwner' => $optionsOwner, - 'optionsVerifiedby' => $optionsVerifiedby, + 'optionsVerified' => $optionsVerified, 'pagination' => $pagination ]); } @@ -165,7 +174,7 @@ class PhraseController extends Controller 'phrase' => 'required', 'translation' => 'required', ]; - if ($isCreate){ + if ($isCreate) { $rc['language'] = 'required'; } return $rc; @@ -235,7 +244,7 @@ class PhraseController extends Controller public function update(Phrase $phrase, Request $request) { $rc = null; - if ($request->btnSubmit === 'btnInternal'){ + if ($request->btnSubmit === 'btnInternal') { // Language combobox has been changed: $url = "/phrase-edit/$phrase->id?language=" . $request->language; $rc = redirect($url); @@ -270,7 +279,7 @@ class PhraseController extends Controller ]); } else { // Update only if changed: - if ($phraseTranslation->phrase !== $validated['translation']){ + if ($phraseTranslation->phrase !== $validated['translation']) { $phraseTranslation->update(['phrase' => $validated['translation'], 'verifiedby_id' => null]); } } diff --git a/composer.lock b/composer.lock index 71b1ec6..e336d50 100644 --- a/composer.lock +++ b/composer.lock @@ -1051,7 +1051,7 @@ "dist": { "type": "path", "url": "../laraknife", - "reference": "75f027bc39816f480246d553ef5b996fed7a775e" + "reference": "47a41b7a9e0479870ed354c33653009296af812d" }, "require-dev": { "phpunit/phpunit": "11.0.x-dev" @@ -1082,16 +1082,16 @@ }, { "name": "laravel/framework", - "version": "v11.3.0", + "version": "v11.3.1", "source": { "type": "git", "url": "https://github.com/laravel/framework.git", - "reference": "cbcb0ee3da8c5f98497d9a282609732251a7dd1e" + "reference": "3b87d0767e9cbddec46480d883010ba720e50dea" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/framework/zipball/cbcb0ee3da8c5f98497d9a282609732251a7dd1e", - "reference": "cbcb0ee3da8c5f98497d9a282609732251a7dd1e", + "url": "https://api.github.com/repos/laravel/framework/zipball/3b87d0767e9cbddec46480d883010ba720e50dea", + "reference": "3b87d0767e9cbddec46480d883010ba720e50dea", "shasum": "" }, "require": { @@ -1283,7 +1283,7 @@ "issues": "https://github.com/laravel/framework/issues", "source": "https://github.com/laravel/framework" }, - "time": "2024-04-09T15:19:11+00:00" + "time": "2024-04-10T15:13:49+00:00" }, { "name": "laravel/prompts", diff --git a/lang/de_DE.json b/lang/de_DE.json index 11e4e36..9ce4bbc 100644 --- a/lang/de_DE.json +++ b/lang/de_DE.json @@ -2,6 +2,7 @@ "!comment": "Bitte alphabetisch sortiert eintragen!", "<All>": "<Alle>", "": "", + "": "", "": "", "A Scoped Property": "Eine bereichsbasierte Eigenschaft", "Action": "Aktion", @@ -78,6 +79,7 @@ "Name": "Name", "New": "Neu", "Not Assigned Menu Items": "Nicht zugeordnete Men\u00fceintr\u00e4ge", + "Not verified": "Nicht \u00fcberpr\u00fcft", "Notes": "Notizen", "Noun": "Nomen", "Nouns": "Nomen", @@ -128,6 +130,7 @@ "Value": "Wert", "Verb": "Verb", "Verbs": "Verben", + "Verified": "\u00dcberpr\u00fcft", "Verified by": "\u00dcberpr\u00fcft von", "Verifiedby": "\u00dcberpr\u00fcft von", "Visibility": "Sicherbarkeit", diff --git a/resources/lang/sources/gadeku.de.json b/resources/lang/sources/gadeku.de.json index 2a3f002..eee27ca 100644 --- a/resources/lang/sources/gadeku.de.json +++ b/resources/lang/sources/gadeku.de.json @@ -1,5 +1,6 @@ { "!comment": "Bitte alphabetisch sortiert eintragen!", +"": "", "Adjective": "Adjektiv", "Change of a Noun": "Änderung eines Nomens", "Change of a Phrase": "Änderung eines Satzes", @@ -14,6 +15,7 @@ "Imperfect": "Imperfekt", "masculine": "Maskulinum", "neuter": "Neutrum", +"Not verified": "Nicht überprüft", "Noun": "Nomen", "Nouns": "Nomen", "Participle": "Partizip", @@ -27,6 +29,7 @@ "Words": "Wörter", "Wordtype": "Wortart", "Usage": "Verwendung", +"Verified": "Überprüft", "Verifiedby": "Überprüft von", "Verified by": "Überprüft von", "ZZZZZ_last": "" diff --git a/resources/views/phrase/index.blade.php b/resources/views/phrase/index.blade.php index 5d1cd88..06bf963 100644 --- a/resources/views/phrase/index.blade.php +++ b/resources/views/phrase/index.blade.php @@ -6,18 +6,15 @@ - - - + + {{__('Phrase')}} - {{__('Language')}} - {{__('Owner')}} - {{__('Verifiedby')}} + {{__('Translation')}} @@ -26,9 +23,7 @@ {{$phrase->phrase}} - {{ __($phrase->language_scope) }} - {{$phrase->owner_id}} - {{$phrase->verifiedby_id}} + {{ __($phrase->translation) }} @endforeach -- 2.39.5