]> gitweb.hamatoma.de Git - gadeku.git/commitdiff
V 0.3.2 Phrase Word
authorHamatoma <author@hamatoma.de>
Sat, 11 May 2024 07:01:32 +0000 (09:01 +0200)
committerHamatoma <author@hamatoma.de>
Sat, 11 May 2024 07:01:32 +0000 (09:01 +0200)
- 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
app/Http/Controllers/PhraseController.php
app/Http/Controllers/WordController.php
composer.lock
resources/lang/sources/gadeku.de.json
resources/views/phrase/create.blade.php
resources/views/phrase/edit.blade.php
resources/views/phrase/index.blade.php
resources/views/word/edit-verb.blade.php

index ba1ebd7f1e5f3d8f02a800174d91720cf679c8e8..230badf72265f9f4d627e0b3d014f65eb2868fc6 100644 (file)
@@ -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
index f178c2fa00a91e9766d93a6c3a8f44923c613179..3d80f35d8a950f398801fecef3ff5b1212b4f778 100644 (file)
@@ -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'], __('<Please select>'));
-            $optionsVerifiedby = DbHelper::comboboxDataOfTable('users', 'name', 'id', $fields['verifiedby_id'], __('<Please select>'));
+            $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<string, string> 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) {
index d357b9892462121cf69e84cf4fd25efa042898a3..9b34171341da5d0b805e2b9a5c702b3a06987861 100644 (file)
@@ -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<string, string> 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();
index eece4603b32363a58fa4138fe76b68ecfa15fe88..ec2ed4783e3465ead1cea720c6e7cdef440af790 100644 (file)
             "dist": {
                 "type": "path",
                 "url": "../laraknife",
-                "reference": "542a161082cb090cb635241880b7fd56267d66d1"
+                "reference": "51702fba5a786ac71dd1628e7aee3aae747d6003"
             },
             "require-dev": {
                 "phpunit/phpunit": "11.0.x-dev"
         },
         {
             "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",
                     "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",
                 "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",
index 806f65a26e49578fde7c60420c9423c831ae1e75..80cbedd2ebbb7c03ecd3d6dad79bdda11786ef83 100644 (file)
 "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",
index 2112871cd0c04ce2dea7a718b5e597401030a422..de600b3b52e459d976a7ceff0d6fde0966d4f87a 100644 (file)
@@ -6,9 +6,7 @@
         @method('PUT')
         <x-laraknife.panels.create title="{{ __('Creation of a Phrase') }}">
         <x-laraknife.forms.combobox position="alone" name="language_scope" label="Language" :options="$optionsLanguage" width2="4"/>
-        <x-laraknife.forms.combobox position="alone" name="owner_id" label="Owner" :options="$optionsOwner" width2="4"/>
-        <x-laraknife.forms.combobox position="alone" name="verifiedby_id" label="Verifiedby" :options="$optionsVerifiedby" width2="4"/>
-        <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}" width2="4" rows="2" />
+        <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}" width2="10" rows="3" />
             
 </x-laraknife.panels.create>
     </form>
index 12698f2fabe7c4c048d4c374a336012582fa1d9d..3795610a17de11534c784c23f1cf018bd5a00717 100644 (file)
@@ -1,13 +1,16 @@
 @extends('layouts.backend')
 
 @section('content')
-    <form id="phrase-edit" action="/phrase-update/{{ $context->model->id  }}" method="POST">
+    <form id="phrase-edit" action="/phrase-update/{{ $context->model->id }}" method="POST">
         @csrf
         <input type="hidden" name="lastLanguage" value="{{ $context->valueOf('lastLanguage') }}">
         <x-laraknife.panels.edit title="{{ __('Change of a Phrase') }}">
-        <x-laraknife.forms.combobox position="alone" name="language" label="Language" :options="$optionsLanguage" width2="4" class="lkn-autoupdate"/>
-        <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}" width2="10" rows="3" />
-        <x-laraknife.forms.text position="alone" name="translation" label="Translation" value="{{ $context->valueOf('translation') }}" width2="10" rows="3" />
+            <x-laraknife.forms.text position="alone" name="phrase" label="Phrase" value="{{ $context->valueOf('phrase') }}"
+                width2="10" rows="3" />
+            <x-laraknife.forms.combobox position="alone" name="language" label="Language" :options="$optionsLanguage" width2="4"
+                class="lkn-autoupdate" />
+            <x-laraknife.forms.text position="alone" name="translation" label="Translation"
+                value="{{ $context->valueOf('translation') }}" width2="10" rows="3" />
         </x-laraknife.panels.edit>
     </form>
 @endsection
index 43d1ff3fbfe53559502b1e62e63bd7fb51d428e0..47d64e8df9b5ed013d18123e733ac058b8ac5108 100644 (file)
@@ -9,6 +9,7 @@
         <x-laraknife.forms.combobox position="last" name="verified" label="Verified" :options="$optionsVerified" class="lkn-autoupdate" width2="4" />
         <x-laraknife.forms.string position="alone" name="text" label="Text" value="{{ $context->valueOf('text') }}" width2="4" />
       </x-laraknife.panels.filter>
+      <x-laraknife.panels.index-button buttonType="new"/>
       <x-laraknife.panels.sortable-table :context="$context" :pagination="$pagination">
         <thead>
           <tr>
index 83457a6e91db6e59ff1d93b83da32216f610ef5b..254335bacf2b7a51428725eb307a8502fd0ad2bd 100644 (file)
                         value="{{ $context->valueOf('c5') }}" width1="1" width2="2" />
                     <x-laraknife.forms.string position="last" name="c6" label="Sie"
                         value="{{ $context->valueOf('c6') }}" width1="1" width2="2" />
-                    <x-laraknife.forms.string position="first" name="c7" label="Imperfekt Ich"
+                    <x-laraknife.forms.string position="first" name="c7" label="Präteritum Ich"
                         value="{{ $context->valueOf('c7') }}" width2="2" />
                     <x-laraknife.forms.string position="middle" name="c8" label="Du"
                         value="{{ $context->valueOf('c8') }}" width1="1" width2="2" />
                     <x-laraknife.forms.string position="last" name="c9" label="Er/Sie/Es"
                         value="{{ $context->valueOf('c9') }}" width1="1" width2="2" />
-                    <x-laraknife.forms.string position="first" name="c10" label="Imperfekt Wir"
+                    <x-laraknife.forms.string position="first" name="c10" label="Präteritum Wir"
                         value="{{ $context->valueOf('c10') }}" width2="2" />
                     <x-laraknife.forms.string position="middle" name="c11" label="Ihr"
                         value="{{ $context->valueOf('c11') }}" width1="1" width2="2" />