From 21a382edf4a7b2bf71d4277b54c4ac2498935006 Mon Sep 17 00:00:00 2001 From: alxndr-w Date: Sat, 25 May 2024 18:49:11 +0000 Subject: [PATCH] Apply php-cs-fixer changes --- boot.php | 28 ++++++------- .../backend/WildcardQuicknavigationButton.php | 8 ++-- install.php | 39 +++++++++---------- lib/QuickNavigationButton.php | 12 ++++-- lib/Sync.php | 34 ++++++++-------- lib/rex_api_call_wildcard.php | 8 ++-- lib/wildcard.php | 11 +++--- pages/docs.php | 5 +-- 8 files changed, 74 insertions(+), 71 deletions(-) diff --git a/boot.php b/boot.php index 52e7a1c..8da96ce 100644 --- a/boot.php +++ b/boot.php @@ -2,12 +2,14 @@ namespace Alexplusde\Wildcard; +use FriendsOfRedaxo\QuickNavigation\Button\ButtonRegistry; use rex; use rex_addon; use rex_config; use rex_extension; +use rex_package; +use rex_view; use rex_yform_manager_dataset; -use FriendsOfRedaxo\QuickNavigation\Button\ButtonRegistry; if (rex_addon::get('yform')->isAvailable() && !rex::isSafeMode()) { rex_yform_manager_dataset::setModelClass( @@ -16,7 +18,7 @@ ); } -if(rex::isBackend() && rex::isDebugMode() && rex_addon::get('developer') && rex_addon::get('developer')->isAvailable()) { +if (rex::isBackend() && rex::isDebugMode() && rex_addon::get('developer') && rex_addon::get('developer')->isAvailable()) { FragmentScanner::scan('sh_neues'); Sync::fileToDb(); } @@ -34,26 +36,26 @@ /* Darstellung im Backend der Datalist ändern */ if (rex::isBackend()) { - rex_extension::register('YFORM_DATA_LIST', function ($ep) { - if ($ep->getParam('table')->getTableName() == 'rex_wildcard') { + rex_extension::register('YFORM_DATA_LIST', static function ($ep) { + if ('rex_wildcard' == $ep->getParam('table')->getTableName()) { $list = $ep->getSubject(); $list->setColumnFormat( 'package', 'custom', - function ($a) { + static function ($a) { /* get the icon of the package.yml of the addon */ - $packageIcon = \rex_package::get($a['list']->getValue('package'))->getProperty('page')['icon'] ?? 'rex-icon-package'; - return '
 '.$a['list']->getValue('package').'
'; - } + $packageIcon = rex_package::get($a['list']->getValue('package'))->getProperty('page')['icon'] ?? 'rex-icon-package'; + return '
 ' . $a['list']->getValue('package') . '
'; + }, ); $list->setColumnFormat( 'wildcard', 'custom', - function ($a) { - $value = rex_config::get('wildcard', 'opentag') . $a['list']->getValue('wildcard') . rex_config::get('wildcard', 'closetag'); - return '
'.$a['list']->getValue('wildcard') . '
'; - } + static function ($a) { + $value = rex_config::get('wildcard', 'opentag') . $a['list']->getValue('wildcard') . rex_config::get('wildcard', 'closetag'); + return '
' . $a['list']->getValue('wildcard') . '
'; + }, ); } }); @@ -61,7 +63,7 @@ function ($a) { /* Javascript-Asset laden */ if (rex::isBackend() && rex::getUser()) { - \rex_view::addJsFile($this->getAssetsUrl('js/backend.js')); + rex_view::addJsFile($this->getAssetsUrl('js/backend.js')); } /* Wenn quick_navigation installiert, dann */ diff --git a/fragments/wildcard/backend/WildcardQuicknavigationButton.php b/fragments/wildcard/backend/WildcardQuicknavigationButton.php index 9f4aecb..d663e14 100644 --- a/fragments/wildcard/backend/WildcardQuicknavigationButton.php +++ b/fragments/wildcard/backend/WildcardQuicknavigationButton.php @@ -7,8 +7,8 @@ diff --git a/install.php b/install.php index 2509564..4b3fa9d 100644 --- a/install.php +++ b/install.php @@ -4,8 +4,7 @@ $addon = rex_addon::get('wildcard'); if (rex_addon::get('yform')->isAvailable() && !rex::isSafeMode()) { - - // Laden Sie die JSON-Datei + // Laden Sie die JSON-Datei $tableset = rex_file::get(rex_path::addon($addon->getName(), 'install/rex_wildcard.tableset.json')); // Konvertieren Sie die JSON-Datei in ein PHP-Array @@ -13,30 +12,29 @@ // Durchsuchen Sie das Array nach dem Feld mit dem Namen "wildcard" und der Priorität 2 foreach ($data['rex_wildcard']['fields'] as $index => $field) { - if ($field['name'] === 'wildcard' && $field['prio'] === 2) { + if ('wildcard' === $field['name'] && 2 === $field['prio']) { foreach (rex_clang::getAll() as $clang) { - // Erstellen Sie das neue Feld $newField = [ - "table_name" => "rex_wildcard", - "prio" => 3, - "type_id" => "value", - "type_name" => "textarea", - "db_type" => "text", - "list_hidden" => 0, - "search" => 1, - "name" => "text_".$clang->getCode(), - "label" => "translate:wildcard_text_".$clang->getCode(), - "not_required" => "", - "attributes" => "", - "default" => "", - "no_db" => "0", - "notice" => "", + 'table_name' => 'rex_wildcard', + 'prio' => 3, + 'type_id' => 'value', + 'type_name' => 'textarea', + 'db_type' => 'text', + 'list_hidden' => 0, + 'search' => 1, + 'name' => 'text_' . $clang->getCode(), + 'label' => 'translate:wildcard_text_' . $clang->getCode(), + 'not_required' => '', + 'attributes' => '', + 'default' => '', + 'no_db' => '0', + 'notice' => '', ]; // Fügen Sie das neue Feld direkt nach dem gefundenen Feld ein array_splice($data['rex_wildcard']['fields'], $index + 1, 0, [$newField]); - } + } // Sobald das neue Feld hinzugefügt wurde, beenden Sie die Schleife break; } @@ -49,7 +47,6 @@ rex_yform_manager_table::deleteCache(); } - /* Zusätzliche Eigenschaften an der Tabelle direkt setzen, z.B. Index-Felder zur Performance-Optimierung */ $table = rex_sql_table::get(rex::getTable('wildcard')); @@ -57,7 +54,7 @@ $table = $table->ensureColumn(new rex_sql_column('package', 'varchar(191)', false, 'project')); $table = $table->ensureColumn(new rex_sql_column('wildcard', 'varchar(191)', false, '')); foreach (rex_clang::getAll() as $clang) { - $table = $table->ensureColumn(new rex_sql_column('text_' . \rex_string::normalize($clang->getCode()), 'text', true)); + $table = $table->ensureColumn(new rex_sql_column('text_' . rex_string::normalize($clang->getCode()), 'text', true)); } $table = $table->ensureColumn(new rex_sql_column('createdate', 'datetime')); $table = $table->ensureColumn(new rex_sql_column('createuser', 'varchar(191)', false, '')); diff --git a/lib/QuickNavigationButton.php b/lib/QuickNavigationButton.php index 725c3e3..84204e5 100644 --- a/lib/QuickNavigationButton.php +++ b/lib/QuickNavigationButton.php @@ -1,11 +1,15 @@ parse('wildcard/backend/WildcardQuicknavigationButton.php'); } } diff --git a/lib/Sync.php b/lib/Sync.php index 2c3c357..86e1226 100644 --- a/lib/Sync.php +++ b/lib/Sync.php @@ -2,19 +2,24 @@ namespace Alexplusde\Wildcard; -use rex_config; +use rex_file; use rex_path; +use function dirname; + +use const DIRECTORY_SEPARATOR; + class Sync { /* Synchronisiere die Wildcard-Dateien mit der Datenbank. */ - private static function getWildcardFiles(string $packageName = null) :array + private static function getWildcardFiles(?string $packageName = null): array { - if($packageName) { - return [rex_path::addon($packageName) . 'wildcard'. \DIRECTORY_SEPARATOR .'translations.json']; + if ($packageName) { + return [rex_path::addon($packageName) . 'wildcard' . DIRECTORY_SEPARATOR . 'translations.json']; } - return glob(rex_path::src('addons') . \DIRECTORY_SEPARATOR . '*' . \DIRECTORY_SEPARATOR . 'wildcard'. \DIRECTORY_SEPARATOR .'translations.json'); + return glob(rex_path::src('addons') . DIRECTORY_SEPARATOR . '*' . DIRECTORY_SEPARATOR . 'wildcard' . DIRECTORY_SEPARATOR . 'translations.json'); } + public static function fileToDb() { // Hole alle Wildcard-Dateien. @@ -22,40 +27,37 @@ public static function fileToDb() foreach ($wildcardFiles as $wildcardFile) { // Lese die Datei ein. - $wildcardData = json_decode(\rex_file::get($wildcardFile), true); - $packageName = basename(dirname(dirname($wildcardFile))); + $wildcardData = json_decode(rex_file::get($wildcardFile), true); + $packageName = basename(dirname($wildcardFile, 2)); // Trage alle Übersetzungen in die Datenbank ein. - if(!isset($wildcardData['wildcards'])) { + if (!isset($wildcardData['wildcards'])) { continue; } - foreach($wildcardData['wildcards'] as $wildcard => $data) { - - if(!$wildcard || !$data) { + foreach ($wildcardData['wildcards'] as $wildcard => $data) { + if (!$wildcard || !$data) { continue; } $wildcard_dataset = wildcard::findByWildcard($packageName, $wildcard); - if($wildcard_dataset && ($wildcard_dataset->getUpdatedate() <= $data['timestamp'])) { + if ($wildcard_dataset && ($wildcard_dataset->getUpdatedate() <= $data['timestamp'])) { // continue; } - if(!$wildcard_dataset) { + if (!$wildcard_dataset) { /** @var Wildcard $yform_wildcard */ $wildcard_dataset = Wildcard::create(); $wildcard_dataset->setValue('package', $packageName); $wildcard_dataset->setValue('wildcard', $wildcard); $wildcard_dataset->setValue('createuser', '🎴'); } - if(isset($data['de_DE'])) { + if (isset($data['de_DE'])) { dd($data['de_DE']); $wildcard_dataset->setValue('text_de_DE', $data['de_DE']); } $wildcard_dataset->setValue('updatedate', $data['timestamp']); $wildcard_dataset->save(); - } - } } } diff --git a/lib/rex_api_call_wildcard.php b/lib/rex_api_call_wildcard.php index e1fa291..97c422a 100644 --- a/lib/rex_api_call_wildcard.php +++ b/lib/rex_api_call_wildcard.php @@ -1,5 +1,7 @@ whereRaw( - "`package` LIKE '%".$search."%' OR `wildcard` LIKE '%".$search."%' OR `text_de_DE` LIKE '%".$search."%'" - )->limit(10)->orderBy('package')->orderBy('wildcard')->find(['search' => $search]); + $result = Wildcard::query()->whereRaw( + "`package` LIKE '%" . $search . "%' OR `wildcard` LIKE '%" . $search . "%' OR `text_de_DE` LIKE '%" . $search . "%'", + )->limit(10)->orderBy('package')->orderBy('wildcard')->find(['search' => $search]); $wildcards = []; foreach ($result as $item) { $wildcards[$item->wildcard] = ['de_DE' => $item->text_de_DE]; diff --git a/lib/wildcard.php b/lib/wildcard.php index b1f6448..8721c24 100644 --- a/lib/wildcard.php +++ b/lib/wildcard.php @@ -17,17 +17,16 @@ public static function getCurrentFieldName($field = 'text', $separator = '_') return $field . $separator . rex_clang::getCurrentId(); } - public static function findByWildcard(string $package = '', string $wildcard): ?self + public static function findByWildcard(string $package, string $wildcard): ?self { - return self::query() - ->where('wildcard', $wildcard) - ->where('package', $package) - ->findOne(); + return self::query() + ->where('wildcard', $wildcard) + ->where('package', $package) + ->findOne(); } public static function findWildcard(string $wildcard, mixed $clang_code = null) { - $clang_code ??= rex_clang::getCurrent()->getCode(); $wildcard = self::query() ->where('wildcard', $wildcard) diff --git a/pages/docs.php b/pages/docs.php index 3105372..82fb108 100644 --- a/pages/docs.php +++ b/pages/docs.php @@ -1,4 +1 @@ -