Skip to content

Commit

Permalink
Apply php-cs-fixer changes
Browse files Browse the repository at this point in the history
  • Loading branch information
alxndr-w authored and github-actions[bot] committed May 25, 2024
1 parent d988789 commit 21a382e
Show file tree
Hide file tree
Showing 8 changed files with 74 additions and 71 deletions.
28 changes: 15 additions & 13 deletions boot.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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();
}
Expand All @@ -34,34 +36,34 @@

/* 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 '<div class="text-nowrap"><i class="rex-icon '.$packageIcon.'"></i>&nbsp;'.$a['list']->getValue('package').'</div>';
}
$packageIcon = rex_package::get($a['list']->getValue('package'))->getProperty('page')['icon'] ?? 'rex-icon-package';
return '<div class="text-nowrap"><i class="rex-icon ' . $packageIcon . '"></i>&nbsp;' . $a['list']->getValue('package') . '</div>';
},
);
$list->setColumnFormat(
'wildcard',
'custom',
function ($a) {
$value = rex_config::get('wildcard', 'opentag') . $a['list']->getValue('wildcard') . rex_config::get('wildcard', 'closetag');
return '<div class="text-nowrap" data-wildcard-copy="'.$value.'" role="button"> <i class="rex-icon fa-clone"></i> <code> '.$a['list']->getValue('wildcard') . '</code></div>';
}
static function ($a) {
$value = rex_config::get('wildcard', 'opentag') . $a['list']->getValue('wildcard') . rex_config::get('wildcard', 'closetag');
return '<div class="text-nowrap" data-wildcard-copy="' . $value . '" role="button"> <i class="rex-icon fa-clone"></i> <code> ' . $a['list']->getValue('wildcard') . '</code></div>';
},
);
}
});
}

/* 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 */
Expand Down
8 changes: 4 additions & 4 deletions fragments/wildcard/backend/WildcardQuicknavigationButton.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@
</button>
<div style="max-width: calc(100vw - 200px); width: 700px" class="quicknavi quicknavi-items list-group dropdown-menu dropdown-menu-right" aria-labelledby="wildcardSearch">
<div style="padding: 10px;">


<div class="input-group">
<input type="search" class="form-control" name="q" placeholder="<?= \rex_i18n::msg('wildcard_quicknavigation_search_placeholder') ?>">
<span class="input-group-btn">
<button class="btn btn-primary" id="wildcardSearchButton"><span class="rex-icon fa-search"></span> <?= \rex_i18n::msg('wildcard_quicknavigation_search_button') ?></button>
</span>
</div>
</form>

<div id="wildcardSearchResults" style="padding-top: 10px;">
</div>
</div>


</div>
</div>
39 changes: 18 additions & 21 deletions install.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@
$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
$data = json_decode($tableset, true);

// 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;
}
Expand All @@ -49,15 +47,14 @@
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'));
$table = $table->ensurePrimaryIdColumn();
$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, ''));
Expand Down
12 changes: 8 additions & 4 deletions lib/QuickNavigationButton.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
<?php


namespace Alexplusde\Wildcard;
class QuickNavigationButton implements \FriendsOfRedaxo\QuickNavigation\Button\ButtonInterface {
public function get(): string {

$fragment = new \rex_fragment();
use FriendsOfRedaxo\QuickNavigation\Button\ButtonInterface;
use rex_fragment;

class QuickNavigationButton implements ButtonInterface
{
public function get(): string
{
$fragment = new rex_fragment();
return $fragment->parse('wildcard/backend/WildcardQuicknavigationButton.php');
}
}
34 changes: 18 additions & 16 deletions lib/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,60 +2,62 @@

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.
$wildcardFiles = self::getWildcardFiles();

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();

}

}
}
}
8 changes: 5 additions & 3 deletions lib/rex_api_call_wildcard.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
<?php

use Alexplusde\Wildcard\Wildcard;

class rex_api_wildcard_search extends rex_api_function
{
protected $published = true;

public function execute()
{
$search = rex_request('q', 'string', '');
$result = Alexplusde\Wildcard\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]);
$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];
Expand Down
11 changes: 5 additions & 6 deletions lib/wildcard.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 1 addition & 4 deletions pages/docs.php
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
<?php

/** Standard-Methoden, um README.md in REDAXO auszugeben */
echo rex_view::title(rex_i18n::msg('wildcard_title'));
<?=/** Standard-Methoden, um README.md in REDAXO auszugeben */ rex_view::title(rex_i18n::msg('wildcard_title'));

0 comments on commit 21a382e

Please sign in to comment.