From 46b9d80fdfb09bb37699f6cf03af96af4e06bffb Mon Sep 17 00:00:00 2001 From: Hamatoma Date: Mon, 20 May 2024 20:04:33 +0200 Subject: [PATCH] =?utf8?q?V=200.3.9=20Snaketext-Pr=C3=BCfung?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit - TextProcessor: neu: wordStatistics() - TaskController: neu: checkSnakeText() - PageController: Redirect von Create nach Edit --- CHANGELOG.md | 9 +++++++++ app/Helpers/TextProcessor.php | 24 ++++++++++++++++++++++++ app/Http/Controllers/PageController.php | 5 ++++- app/Http/Controllers/TaskController.php | 16 +++++++++++++++- lang/de_DE.json | 3 +++ public/css/purple.css | 4 ++-- resources/lang/sources/gadeku.de.json | 1 + tests/abrevations.txt | 2 ++ 8 files changed, 60 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2989513..9c11774 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# V 0.3.9 Snaketext-Prüfung + +## Added +- TextProcessor: neu: wordStatistics() +- TaskController: neu: checkSnakeText() + +## Changed +- PageController: Redirect von Create nach Edit + # V 0.3.8 Design ## Added diff --git a/app/Helpers/TextProcessor.php b/app/Helpers/TextProcessor.php index fe634ec..74a0569 100644 --- a/app/Helpers/TextProcessor.php +++ b/app/Helpers/TextProcessor.php @@ -28,4 +28,28 @@ class TextProcessor ); return $rc; } + public static function wordStatistics(string $text): array{ + $rc = []; + $max = strlen($text) - 1; + $match = null; + while($text !== ''){ + if (preg_match('/^\s+/', $text, $match)){ + $text = substr($text, strlen($match[0])); + continue; + } + if (preg_match('/^([äöüÄÖÜß\w]+[*:][iI][äöüÄÖÜ\w]+|[äöüÄÖÜß\w]+|[:.,;?-])/', $text, $match)){ + $word = $match[1]; + $text = substr($text, strlen($word)); + } else { + $word = $text[0]; + $text = substr($text, 1); + } + if (array_key_exists($word, $rc)){ + $rc[$word]++; + } else { + $rc[$word] = 1; + } + } + return $rc; + } } diff --git a/app/Http/Controllers/PageController.php b/app/Http/Controllers/PageController.php index fc0dfbf..f024ab5 100644 --- a/app/Http/Controllers/PageController.php +++ b/app/Http/Controllers/PageController.php @@ -348,7 +348,10 @@ LEFT JOIN sproperties t4 ON t4.id=t0.owner_id $validated['info'] = strip_tags($validated['info']); $validated['owner_id'] = $fields['owner_id']; $validated['contents'] = MediaWiki::expandStarItems($validated['contents']); - Page::create($validated); + $page = Page::create($validated); + if ($page != null){ + $rc = redirect("/page-edit/$page->id"); + } } } if ($rc == null) { diff --git a/app/Http/Controllers/TaskController.php b/app/Http/Controllers/TaskController.php index 7a80d68..5b8db95 100644 --- a/app/Http/Controllers/TaskController.php +++ b/app/Http/Controllers/TaskController.php @@ -33,6 +33,19 @@ class TaskController extends Controller $rc->pageId = $pageId; return $rc; } + private function checkSnakeText($solution, $original): int{ + $solutionWords = TextProcessor::wordStatistics($solution); + $originalWords = TextProcessor::wordStatistics($original); + $rc = 0; + foreach ($originalWords as $key => $count){ + if (! array_key_exists($key, $solutionWords)){ + $rc += $count; + } elseif ($count != ($count2 = $solutionWords[$key])){ + $rc += abs($count - $count2); + } + } + return $rc; + } public function create(Request $request) { $rc = null; @@ -100,7 +113,8 @@ class TaskController extends Controller } } if ($request->btnSubmit === 'btnCheck') { - $fields['message'] = __('I found 3 errors.'); + $errors = $this->checkSnakeText($fields['solution'], $page->contents); + $fields['message'] = __('I found :n error(s)', ['n' => $errors]); } if ($request->btnSubmit === 'btnStore') { $note->update(['body' => $fields['solution']]); diff --git a/lang/de_DE.json b/lang/de_DE.json index fe32dfb..b4036f5 100644 --- a/lang/de_DE.json +++ b/lang/de_DE.json @@ -79,6 +79,7 @@ "Group": "Gruppe", "Groups": "Gruppen", "Hello": "Hallo", + "I found :n error(s)": "Ich habe :n Fehler gefunden", "Id": "Id", "Imprint": "Impressum", "Info": "Info", @@ -124,6 +125,7 @@ "Reference": "Referenz", "Remain signed in": "Angemeldet bleiben", "Repetition": "Wiederholung", + "Responsibility changed": "Verantwortung ge\u00e4ndert", "Role": "Rolle", "Roles": "Rollen", "Scope": "Bereich", @@ -149,6 +151,7 @@ "Text": "Text", "The provided credentials do not match our records.": "EMail und Passwort passen nicht zu den gespeicherten Daten.", "The repetion field is required.": "Das Feld Wiederholung ist notwendig", + "The responsibility has been transferred to you": "Die Verantwortung einer Notiz wurde auf dich \u00fcbertragen", "The search criteria select %d out of %d data records.": "Die Suchkriterien w\u00e4hlen %d von %d Datens\u00e4tzen aus.", "The search criterion selects %d out of %d data records.": "Das Suchkriterium w\u00e4hlt %d von %d Datens\u00e4tzen aus.", "Title": "Titel", diff --git a/public/css/purple.css b/public/css/purple.css index e881b33..84d4cbf 100644 --- a/public/css/purple.css +++ b/public/css/purple.css @@ -9,7 +9,7 @@ h4{ color: #9D8C84 ; border-bottom: solid 0.1rem #9D8C84; } .lkn-text { color: black; background-color: white; - border: 0.15rem solid #143F4E; + border: 0.15rem solid #607375; } /* Links */ @@ -29,7 +29,7 @@ h4{ color: #9D8C84 ; border-bottom: solid 0.1rem #9D8C84; } .lkn-header-frame { background-color: #c2b0a8; - border: 0.2rem solid #143F4E; + border: 0.15rem solid #607375; } .lkn-pagination-block { diff --git a/resources/lang/sources/gadeku.de.json b/resources/lang/sources/gadeku.de.json index 1ef2458..58eb867 100644 --- a/resources/lang/sources/gadeku.de.json +++ b/resources/lang/sources/gadeku.de.json @@ -20,6 +20,7 @@ "free text": "Freier Text", "Genus": "Geschlecht", "grammar rules": "Grammatikregeln", +"I found :n error(s)": "Ich habe :n Fehler gefunden", "masculine": "Maskulinum", "neuter": "Neutrum", "Not verified": "Nicht überprüft", diff --git a/tests/abrevations.txt b/tests/abrevations.txt index 17f97f1..ac1b5f9 100644 --- a/tests/abrevations.txt +++ b/tests/abrevations.txt @@ -4,6 +4,8 @@ {| |- +| a |} + || U+x2B50; \ No newline at end of file -- 2.39.5