]> gitweb.hamatoma.de Git - gadeku.git/commitdiff
V 0.1.7 Übersetzungen in Words
authorHamatoma <author@hamatoma.de>
Sat, 13 Apr 2024 20:19:47 +0000 (22:19 +0200)
committerHamatoma <author@hamatoma.de>
Sat, 13 Apr 2024 20:20:32 +0000 (22:20 +0200)
- Phrase:
  - Setzen/Löschen von verifiedby_id
- Word
  - Behandlung von Übersetzungen
  - Setzen/Löschen von verifiedby_id

- Word:
  - Attribut word_id

CHANGELOG.md
app/Http/Controllers/PhraseController.php
app/Http/Controllers/WordController.php
app/Models/Word.php
composer.lock
database/migrations/2024_04_13_131901_change_words_word_id.php [new file with mode: 0644]
resources/views/phrase/index.blade.php
resources/views/word/edit.blade.php
resources/views/word/index.blade.php

index 0cbfcc38686458c504ca6af37a3a0f84e09b70d9..60d33d6e193dfe2f6457da0b0472a462801580dc 100644 (file)
@@ -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"
 
index 3f47a1af9845bf350cecdf7220e190aca4b405b0..1c31c0a22ca212893fb5791a98706a8a9c3a08a7 100644 (file)
@@ -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();
index eb5ccf88ed293aad639e59141d3207f5ca0d46fb..15b540283dc256875925cb544d82e4e479cd25b3 100644 (file)
@@ -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'], __('<Please select>'));
-            $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'], __('<Please select>'));
-            $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'], __('<All>'));
+            $optionsLanguage = SProperty::optionsByScope('localization', $fields['language']);
             $optionsOwner = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['owner'], __('<All>'));
+            $optionsVerified = [
+                ['text' => __('<All>'), '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<string, string> 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;
index bbcd1d5129058f1e51bfc941a6d81d320c504330..a66217e3a4d81b7fa68ee39ce74fa8301c9fa1d0 100644 (file)
@@ -17,7 +17,7 @@ class Word extends Model
         'usage',
         'wordtype_scope',
         'language_scope',
-        'baselanguage_id',
+        'word_id',
         'verifiedby_id',
         'owner_id'
     ];
index e336d5044e98d286e814030c35d7befc2537772b..6c22dbffc506d55b263d039bfde2f3f6388ad15f 100644 (file)
             "dist": {
                 "type": "path",
                 "url": "../laraknife",
-                "reference": "47a41b7a9e0479870ed354c33653009296af812d"
+                "reference": "0578f3c7527bb061c7671f3d9f9ffe2db04688f9"
             },
             "require-dev": {
                 "phpunit/phpunit": "11.0.x-dev"
         },
         {
             "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": {
                 "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",
             ],
             "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": [
                 {
                     "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 (file)
index 0000000..8d93f93
--- /dev/null
@@ -0,0 +1,26 @@
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+return new class extends Migration
+{
+    /**
+     * Run the migrations.
+     */
+    public function up(): void
+    {
+        Schema::table('words', function(Blueprint $table) {
+            $table->renameColumn('baselanguage_id', 'word_id');
+        });
+    }
+
+    /**
+     * Reverse the migrations.
+     */
+    public function down(): void
+    {
+        //
+    }
+};
index 06bf963ad9d6bc66bcf5a95077145d6392c38c22..43d1ff3fbfe53559502b1e62e63bd7fb51d428e0 100644 (file)
@@ -23,7 +23,7 @@
         <tr>
             <td><x-laraknife.icons.change-record module="phrase" no="{{ $phrase->id }}" /></td>
               <td>{{$phrase->phrase}}</td>
-              <td> {{ __($phrase->translation) }}</td>
+              <td> {{ $phrase->translation }}</td>
             <td><x-laraknife.icons.delete-record module="phrase" no="{{ $phrase->id }}" /></td>
         </tr>
 @endforeach
index 692866ae053156bd00fb03544938d62b3f5d7ca7..1b6175636477d3bce8f53ab9888ca12839e4d9a5 100644 (file)
@@ -4,14 +4,16 @@
     <form id="word-edit" action="/word-update/{{ $context->model->id }}" method="POST">
         @csrf
         <x-laraknife.panels.edit title="{{ __('Change of a Word') }}">
-        <x-laraknife.forms.string position="first" name="name" label="Name" value="{{ $context->valueOf('name') }}"
-            width2="4" />
-            <x-laraknife.forms.combobox position="last" name="wordtype_scope" label="Wordtype" :options="$optionsWordtype"
+            <input type="hidden" name="lastLanguage" value="{{ $context->valueOf('lastLanguage') }}">
+            <x-laraknife.forms.combobox position="alone" name="language" label="Language" :options="$optionsLanguage" width2="4" class="lkn-autoupdate"/>
+            <x-laraknife.forms.string position="first" name="name" label="Name" value="{{ $context->valueOf('word') }}"
+                width2="4" />
+                <x-laraknife.forms.combobox position="last" name="wordtype_scope" label="Wordtype" :options="$optionsWordtype"
                 width2="4" attribute="readonly" />
+                <x-laraknife.forms.string position="alone" name="translation" label="Translation"
+                    value="{{ $context->valueOf('translation') }}" width2="4" />
             <x-laraknife.forms.text position="alone" name="usage" label="Usage" value="{{ $context->valueOf('usage') }}"
                 width2="10" rows="3" />
-            <x-laraknife.forms.combobox position="alone" name="verifiedby_id" label="Verifiedby" :options="$optionsVerifiedby"
-                width2="4" />
         </x-laraknife.panels.edit>
     </form>
 @endsection
index e8b01a48ba21aa27f3e4e55095e7b7e9a93b52a9..75cdf490b53962a0ace51f5bbe556a7c13c15d1f 100644 (file)
@@ -7,7 +7,7 @@
             <x-laraknife.panels.filter legend="{{ $pagination->legendText() }}">
                 <x-laraknife.forms.combobox position="first" name="wordtype" label="Wordtype" :options="$optionsWordtype"
                     class="lkn-autoupdate" width2="4" />
-                <x-laraknife.forms.combobox position="last" name="verifiedby" label="Verifiedby" :options="$optionsVerifiedby"
+                <x-laraknife.forms.combobox position="last" name="verified" label="Verified" :options="$optionsVerified"
                     class="lkn-autoupdate" width2="4" />
                 <x-laraknife.forms.string position="first" name="word" label="Name"
                     value="{{ $context->valueOf('name') }}" width2="4" />
@@ -19,9 +19,8 @@
                     <tr>
                         <th></th>
                         <th sortId="name">{{ __('Name') }}</th>
+                        <th sortId="translation">{{__('Translation')}}</th>
                         <th sortId="wordtype">{{ __('Wordtype') }}</th>
-                        <th sortId="verifiedby">{{ __('Verifiedby') }}</th>
-                        <th sortId="owner">{{ __('Owner') }}</th>
                         @if ($context->isAdmin())
                         <th></th>
                         @endif
@@ -32,9 +31,8 @@
                         <tr>
                             <td><x-laraknife.icons.change-record module="word" no="{{ $word->id }}" /></td>
                             <td>{{ $word->word }}</td>
+                            <td> {{ $word->translation }}</td>
                             <td> {{ __($word->wordtype) }}</td>
-                            <td>{{ $word->verifiedby }}</td>
-                            <td>{{ $word->owner }}</td>
                             @if ($context->isAdmin())
                             <td><x-laraknife.icons.delete-record module="word" no="{{ $word->id }}" /></td>
                             @endif