Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Sep 7, 2024
1 parent eb275d9 commit 13cb06b
Show file tree
Hide file tree
Showing 12 changed files with 82 additions and 115 deletions.
7 changes: 0 additions & 7 deletions pages/email.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,6 @@
use Yakamara\YForm\Email\Template;
use Yakamara\YForm\YForm;

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/

$_csrf_key = 'yform_email';

echo rex_view::title(rex_i18n::msg('yform_email_templates'));
Expand Down
7 changes: 3 additions & 4 deletions pages/manager.data_export.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

/**
* @var rex_yform_manager $this
* @psalm-scope-this rex_yform_manager
*/
use Yakamara\YForm\Manager\Manager;

/** @var Manager $this */

$rex_yform_filter ??= [];
$rex_yform_set ??= [];
Expand Down
22 changes: 13 additions & 9 deletions pages/manager.data_history.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

/** @var rex_yform_manager $this */
use Yakamara\YForm\Manager\Dataset;
use Yakamara\YForm\Manager\Manager;
use Yakamara\YForm\YForm;

/** @var Manager $this */

$subfunc = rex_request('subfunc', 'string');
$datasetId = rex_request('data_id', 'int', null);
Expand All @@ -15,7 +19,7 @@

$dataset = null;
if ($datasetId) {
$dataset = \Yakamara\YForm\Manager\Dataset::getRaw($datasetId, $this->table->getTableName());
$dataset = Dataset::getRaw($datasetId, $this->table->getTableName());
} else {
$filterDataset = false;
}
Expand Down Expand Up @@ -214,9 +218,9 @@
$list->setColumnLabel('action', rex_i18n::msg('yform_history_action'));
$list->setColumnFormat('action', 'custom', static function (array $params) {
static $classes = [
\Yakamara\YForm\Manager\Dataset::ACTION_CREATE => 'success',
\Yakamara\YForm\Manager\Dataset::ACTION_UPDATE => 'primary',
\Yakamara\YForm\Manager\Dataset::ACTION_DELETE => 'danger',
Dataset::ACTION_CREATE => 'success',
Dataset::ACTION_UPDATE => 'primary',
Dataset::ACTION_DELETE => 'danger',
];
$class = $classes[$params['subject']] ?? 'default';
return sprintf('<span class="label label-%s">%s</span>', $class, rex_i18n::msg('yform_history_action_' . $params['subject']));
Expand Down Expand Up @@ -264,7 +268,7 @@
$options = '<small class="rex-panel-option-title">' . rex_i18n::msg('yform_history_delete') . ':</small> ' . $fragment->parse('core/buttons/button_group.php');
}

$historySearchForm = new \Yakamara\YForm\YForm();
$historySearchForm = new YForm();
$historySearchForm->setObjectparams('form_action', $list->getUrl());
$historySearchForm->setObjectparams('form_showformafterupdate', true);
$historySearchForm->setObjectparams('real_field_names', true);
Expand All @@ -291,9 +295,9 @@
'label' => 'Action',
'choices' => [
'' => rex_i18n::msg('yform_manager_actions_all'),
\Yakamara\YForm\Manager\Dataset::ACTION_CREATE => rex_i18n::msg('yform_history_action_' . \Yakamara\YForm\Manager\Dataset::ACTION_CREATE),
\Yakamara\YForm\Manager\Dataset::ACTION_UPDATE => rex_i18n::msg('yform_history_action_' . \Yakamara\YForm\Manager\Dataset::ACTION_UPDATE),
\Yakamara\YForm\Manager\Dataset::ACTION_DELETE => rex_i18n::msg('yform_history_action_' . \Yakamara\YForm\Manager\Dataset::ACTION_DELETE),
Dataset::ACTION_CREATE => rex_i18n::msg('yform_history_action_' . Dataset::ACTION_CREATE),
Dataset::ACTION_UPDATE => rex_i18n::msg('yform_history_action_' . Dataset::ACTION_UPDATE),
Dataset::ACTION_DELETE => rex_i18n::msg('yform_history_action_' . Dataset::ACTION_DELETE),
],
]);

Expand Down
27 changes: 11 additions & 16 deletions pages/manager.data_import.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*
* @var rex_yform_manager $this
*/
use Yakamara\YForm\Manager\Field;
use Yakamara\YForm\Manager\Manager;
use Yakamara\YForm\Manager\Table\Api;
use Yakamara\YForm\Manager\Table\Table;

/** @var Manager $this */

$_csrf_key ??= '';

Expand Down Expand Up @@ -79,7 +77,6 @@

try {
$sql_db->transactional(function () use ($filename, $show_importform, $div, $fieldarray, $missing_columns, $debug, &$counter, &$dcounter, &$ecounter, &$rcounter, &$icounter, &$errorcounter, $fields) {

$fp = fopen($filename, 'r');
$firstbytes = fread($fp, 3);
$bom = pack('CCC', 0xEF, 0xBB, 0xBF);
Expand Down Expand Up @@ -131,7 +128,7 @@

foreach ($mc as $mcc) {
rex_sql::factory()
->setTable(\Yakamara\YForm\Manager\Field::table())
->setTable(Field::table())
->setValue('table_name', $this->table->getTablename())
->setValue('prio', 999)
->setValue('type_id', 'value')
Expand All @@ -145,10 +142,10 @@
echo rex_view::info(rex_i18n::msg('yform_manager_import_field_added', $mcc));
}

\Yakamara\YForm\Manager\Table\Api::generateTablesAndFields();
Api::generateTablesAndFields();

$fields = [];
foreach (\Yakamara\YForm\Manager\Table\Table::get($this->table->getTableName())->getFields() as $field) {
foreach (Table::get($this->table->getTableName())->getFields() as $field) {
$fields[strtolower($field->getName())] = $field;
}
} else {
Expand Down Expand Up @@ -232,10 +229,8 @@
'data_errors' => $errorcounter,
],
));

});

} catch (\Throwable $e) {
} catch (Throwable $e) {
$error_message = $e->getMessage();
}

Expand All @@ -252,7 +247,7 @@
echo rex_view::error(rex_i18n::msg('yform_manager_import_info_data_imported', $dcounter));
}

\Yakamara\YForm\Manager\Table\Table::deleteCache();
Table::deleteCache();
}
}

Expand Down
42 changes: 20 additions & 22 deletions pages/manager.table_edit.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
use Yakamara\YForm\Manager\Field;
use Yakamara\YForm\Manager\Table\Api;
use Yakamara\YForm\Manager\Table\Table;
use Yakamara\YForm\YForm;

echo rex_view::title(rex_i18n::msg('yform'));
$_csrf_key = 'yform_table_edit';
Expand All @@ -19,7 +17,7 @@
$show_list = true;

if ('tableset_import' == $func && rex::getUser()->isAdmin()) {
$yform = new \Yakamara\YForm\YForm();
$yform = new YForm();
$yform->setDebug(true);
$yform->setHiddenField('page', $page);
$yform->setHiddenField('func', $func);
Expand Down Expand Up @@ -58,7 +56,7 @@
} else {
try {
$content = file_get_contents($yform->objparams['value_pool']['email']['importfile']);
\Yakamara\YForm\Manager\Table\Api::importTablesets($content);
Api::importTablesets($content);
echo rex_view::info(rex_i18n::msg('yform_manager_table_import_success'));
} catch (Exception $e) {
echo rex_view::warning(rex_i18n::msg('yform_manager_table_import_failed', '', $e->getMessage()));
Expand All @@ -67,13 +65,13 @@
} elseif (('add' == $func || 'edit' == $func) && rex::getUser()->isAdmin()) {
$table = null;
if ('edit' == $func) {
$table = \Yakamara\YForm\Manager\Table\Table::getById($table_id);
$table = Table::getById($table_id);
if (!$table) {
$func = 'add';
}
}

$yform = new \Yakamara\YForm\YForm();
$yform = new YForm();
// $yform->setDebug(TRUE);
$yform->setObjectparams('form_name', $_csrf_key);
$yform->setHiddenField('page', $page);
Expand All @@ -85,7 +83,7 @@
$yform->setHiddenField('start', rex_request('start', 'string'));

$yform->setActionField('showtext', ['', rex_i18n::msg('yform_manager_table_entry_saved')]);
$yform->setObjectparams('main_table', \Yakamara\YForm\Manager\Table\Table::table());
$yform->setObjectparams('main_table', Table::table());

$yform->setValueField('html', ['html' => '<div class="row"><div class="col-md-6">']);
$yform->setValueField('html', ['html' => '<label>' . rex_i18n::msg('yform_manager_table_basic_info') . '</label>']);
Expand All @@ -97,7 +95,7 @@
$yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_update_table'));
$yform->setValueField('showvalue', ['table_name', rex_i18n::msg('yform_manager_table_name')]);
$yform->setHiddenField('table_id', $table->getId());
$yform->setActionField('db', [\Yakamara\YForm\Manager\Table\Table::table(), 'id=' . $table->getId()]);
$yform->setActionField('db', [Table::table(), 'id=' . $table->getId()]);
$yform->setObjectparams('main_id', $table->getId());
$yform->setObjectparams('main_where', 'id=' . $table->getId());
$yform->setObjectparams('getdata', true);
Expand All @@ -112,9 +110,9 @@
return !count($matches) || current($matches) != $table;
}, '', rex_i18n::msg('yform_manager_table_enter_specialchars')]);
$yform->setValidateField('customfunction', ['table_name', static function ($label = '', $table = '', $params = '') {
return (bool) \Yakamara\YForm\Manager\Table\Table::get($table);
return (bool) Table::get($table);
}, '', rex_i18n::msg('yform_manager_table_exists')]);
$yform->setActionField('db', [\Yakamara\YForm\Manager\Table\Table::table()]);
$yform->setActionField('db', [Table::table()]);
break;
}

Expand Down Expand Up @@ -147,7 +145,7 @@
$sortFields = ['id'];
if ('edit' === $func) {
$sortFieldsSql = rex_sql::factory();
$sortFieldsSql->setQuery('SELECT f.name FROM `' . \Yakamara\YForm\Manager\Field::table() . '` f LEFT JOIN `' . \Yakamara\YForm\Manager\Table\Table::table() . '` t ON f.table_name = t.table_name WHERE t.id = :id ORDER BY f.prio', [
$sortFieldsSql->setQuery('SELECT f.name FROM `' . Field::table() . '` f LEFT JOIN `' . Table::table() . '` t ON f.table_name = t.table_name WHERE t.id = :id ORDER BY f.prio', [
'id' => (int) $table_id,
]);
while ($sortFieldsSql->hasNext()) {
Expand Down Expand Up @@ -223,19 +221,19 @@
switch ($func) {
case 'edit':
$table_name = $yform->objparams['value_pool']['email']['table_name'];
$table = \Yakamara\YForm\Manager\Table\Table::get($table_name);
$table = Table::get($table_name);
if ($table) {
\Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table);
Api::generateTableAndFields($table);
}
echo rex_view::info(rex_i18n::msg('yform_manager_table_updated'));
break;
case 'add':
default:
\Yakamara\YForm\Manager\Table\Table::deleteCache();
Table::deleteCache();
$table_name = $yform->objparams['value_pool']['sql']['table_name'];
$table = \Yakamara\YForm\Manager\Table\Table::get($table_name);
$table = Table::get($table_name);
if ($table) {
\Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table);
Api::generateTableAndFields($table);
echo rex_view::success(rex_i18n::msg('yform_manager_table_added'));
}
break;
Expand All @@ -248,7 +246,7 @@
echo rex_view::error(rex_i18n::msg('csrf_token_invalid'));
} else {
$table_name = rex_request('table_name', 'string');
\Yakamara\YForm\Manager\Table\Api::removeTable($table_name);
Api::removeTable($table_name);

$func = '';
echo rex_view::success(rex_i18n::msg('yform_manager_table_deleted'));
Expand Down Expand Up @@ -310,7 +308,7 @@ function rex_yform_list_translate($params)
$fragment->setVar('size', 'xs', false);
$panel_options = $fragment->parse('core/buttons/button_group.php');

$sql = 'select id, prio, name, table_name, status, hidden, import, export, search, mass_deletion, mass_edit, history from `' . \Yakamara\YForm\Manager\Table\Table::table() . '`';
$sql = 'select id, prio, name, table_name, status, hidden, import, export, search, mass_deletion, mass_edit, history from `' . Table::table() . '`';

$list = rex_list::factory($sql, 200, defaultSort: [
'prio' => 'asc',
Expand Down
12 changes: 4 additions & 8 deletions pages/manager.table_field.php
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
use Yakamara\YForm\Manager\Manager;
use Yakamara\YForm\Manager\Table\Table;

echo rex_view::title(rex_i18n::msg('yform'));

$table_name = rex_request('table_name', 'string');
$table = \Yakamara\YForm\Manager\Table\Table::get($table_name);
$table = Table::get($table_name);

if ($table) {
try {
$page = new rex_yform_manager();
$page = new Manager();
$page->setTable($table);
$page->setLinkVars(['page' => 'yform/manager/table_field']);
echo $page->getFieldPage();
Expand Down
17 changes: 7 additions & 10 deletions pages/manager.table_migrate.php
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
use Yakamara\YForm\Manager\Table\Api;
use Yakamara\YForm\Manager\Table\Table;
use Yakamara\YForm\YForm;

echo rex_view::title(rex_i18n::msg('yform'));
$_csrf_key = 'table_migrate';
Expand All @@ -17,7 +14,7 @@
$yform_tables = [];
$missing_tables = [];

foreach (\Yakamara\YForm\Manager\Table\Table::getAll() as $g_table) {
foreach (Table::getAll() as $g_table) {
$yform_tables[] = $g_table->getTableName();
}

Expand All @@ -27,7 +24,7 @@
}
}

$yform = new \Yakamara\YForm\YForm();
$yform = new YForm();
$yform->setObjectparams('form_showformafterupdate', 1);
$yform->setObjectparams('form_name', $_csrf_key);
$yform->setHiddenField('page', $page);
Expand All @@ -40,12 +37,12 @@
$schema_overwrite = (int) $yform->objparams['value_pool']['sql']['schema_overwrite'];

try {
\Yakamara\YForm\Manager\Table\Api::migrateTable($table_name, (0 == $schema_overwrite) ? false : true); // with convert id / auto_increment finder
Api::migrateTable($table_name, (0 == $schema_overwrite) ? false : true); // with convert id / auto_increment finder
echo rex_view::success(rex_i18n::msg('yform_manager_table_migrated_success'));

unset($missing_tables[$table_name]);

$yform = new \Yakamara\YForm\YForm();
$yform = new YForm();
$yform->setObjectparams('form_showformafterupdate', 1);
$yform->setHiddenField('page', $page);
$yform->setValueField('choice', ['name' => 'table_name', 'label' => rex_i18n::msg('yform_table'), 'choices' => $missing_tables]);
Expand Down
15 changes: 6 additions & 9 deletions pages/manager.tableset_export.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?php

/**
* yform.
*
* @author jan.kristinus[at]redaxo[dot]org Jan Kristinus
* @author <a href="http://www.yakamara.de">www.yakamara.de</a>
*/
use Yakamara\YForm\Manager\Table\Api;
use Yakamara\YForm\Manager\Table\Table;
use Yakamara\YForm\YForm;

echo rex_view::title(rex_i18n::msg('yform'));
$_csrf_key = 'tableset_export';

$page = rex_request('page', 'string', '');

$yform_tables = [];
foreach (\Yakamara\YForm\Manager\Table\Table::getAll() as $g_table) {
foreach (Table::getAll() as $g_table) {
$table_name = $g_table->getTableName();
$yform_tables[$table_name] = $g_table->getNameLocalized() . ' [' . $table_name . ']';
}

$yform = new \Yakamara\YForm\YForm();
$yform = new YForm();
$yform->setHiddenField('page', $page);
$yform->setObjectparams('real_field_names', true);
$yform->setObjectparams('form_name', $_csrf_key);
Expand All @@ -29,7 +26,7 @@
if ($yform->objparams['actions_executed']) {
try {
$table_names = rex_request('table_names');
$fileContent = \Yakamara\YForm\Manager\Table\Api::exportTablesets($table_names);
$fileContent = Api::exportTablesets($table_names);

$tablenames = implode('_', $table_names);
if (mb_strlen($tablenames) > 100) {
Expand Down
Loading

0 comments on commit 13cb06b

Please sign in to comment.