Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Sep 9, 2024
1 parent 1d1a435 commit 921e25e
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 24 deletions.
4 changes: 2 additions & 2 deletions lib/RexVar/TableData.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
use rex_i18n;
use rex_select;
use rex_var;
use rex_yform_manager_table;
use rex_yform_value_be_manager_relation;
use Yakamara\YForm\Manager\Table\Table;

use function in_array;

Expand Down Expand Up @@ -48,7 +48,7 @@ protected function getOutput()
return self::quote('[table param not defined]');
}

$table = \Yakamara\YForm\Manager\Table\Table::get($tableName);
$table = Table::get($tableName);
if (!$table) {
return self::quote('[table not in YForm?]');
}
Expand Down
7 changes: 7 additions & 0 deletions lib/YForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@
use rex_yform_validate_abstract;
use rex_yform_value_abstract;

use function array_key_exists;
use function count;
use function in_array;
use function is_array;

use const E_USER_WARNING;

class YForm
{
use rex_factory_trait;
Expand Down
4 changes: 2 additions & 2 deletions lib/yform/value/be_manager_relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,11 +508,11 @@ public function getDefinitions(): array
'db_type' => ['text', 'varchar(191)', 'int', 'int(10) unsigned'],
'formbuilder' => false,
'hooks' => [
'preCreate' => static function (\Yakamara\YForm\Manager\Field $field) {
'preCreate' => static function (Yakamara\YForm\Manager\Field $field) {
return !$field->getElement('relation_table') && ('4' != $field->getElement('type') && '5' != $field->getElement('type'));
},
],
'multi_edit' => static function (\Yakamara\YForm\Manager\Field $field) {
'multi_edit' => static function (Yakamara\YForm\Manager\Field $field) {
return ('4' != $field->getElement('type') && '5' != $field->getElement('type')) && !$field->getElement('relation_table');
},
];
Expand Down
4 changes: 2 additions & 2 deletions lib/yform/value/checkbox.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getDefinitions(): array
'db_type' => ['tinyint(1)'],
'famous' => true,
'hooks' => [
'preDefault' => static function (\Yakamara\YForm\Manager\Field $field) {
'preDefault' => static function (Yakamara\YForm\Manager\Field $field) {
return (1 == $field->getElement('default')) ? '1' : '0';
},
],
Expand All @@ -82,7 +82,7 @@ public static function getSearchField($params)
]);
}

public static function getSearchFilter($params): \Yakamara\YForm\Manager\Query
public static function getSearchFilter($params): Yakamara\YForm\Manager\Query
{
$value = $params['value'];
/** @var \Yakamara\YForm\Manager\Query $query */
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/value/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private function getRelationValues(array $relations)
return $nextIndex;
};

$addFieldsAndJoins = static function (array $columns, \Yakamara\YForm\Manager\Field $relation, $index) use (&$addFieldsAndJoins, $addJoin, &$fields, $sql) {
$addFieldsAndJoins = static function (array $columns, Yakamara\YForm\Manager\Field $relation, $index) use (&$addFieldsAndJoins, $addJoin, &$fields, $sql) {
$table = \Yakamara\YForm\Manager\Table\Table::get($relation->getElement('table'));

$fieldFormat = 't%d.%s';
Expand Down
4 changes: 2 additions & 2 deletions lib/yform/value/integer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ public static function getSearchFilter($params)
$field = $query->getTableAlias() . '.' . $params['field']->getName();

if ('(empty)' == $value) {
return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) {
return $query->whereNested(static function (Yakamara\YForm\Manager\Query $query) use ($field) {
$query
->where($field, '')
->where($field, null)
;
}, 'OR');
}
if ('!(empty)' == $value) {
return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) {
return $query->whereNested(static function (Yakamara\YForm\Manager\Query $query) use ($field) {
$query
->where($field, '', '<>')
->where($field, null, '<>')
Expand Down
2 changes: 1 addition & 1 deletion lib/yform/value/number.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function getDefinitions(): array
'description' => rex_i18n::msg('yform_values_number_description'),
'db_type' => ['DECIMAL({precision},{scale})'],
'hooks' => [
'preCreate' => static function (\Yakamara\YForm\Manager\Field $field, $db_type) {
'preCreate' => static function (Yakamara\YForm\Manager\Field $field, $db_type) {
$db_type = str_replace('{precision}', (string) ($field->getElement('precision') ?? 6), $db_type);
$db_type = str_replace('{scale}', (string) ($field->getElement('scale') ?? 2), $db_type);
return $db_type;
Expand Down
6 changes: 3 additions & 3 deletions lib/yform/value/text.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public function getDefinitions(): array
'db_type' => ['varchar(191)', 'text'],
'famous' => true,
'hooks' => [
'preDefault' => static function (\Yakamara\YForm\Manager\Field $field) {
'preDefault' => static function (Yakamara\YForm\Manager\Field $field) {
return $field->getElement('default');
},
],
Expand All @@ -83,15 +83,15 @@ public static function getSearchFilter($params)
$field = $query->getTableAlias() . '.' . $params['field']->getName();

if ('(empty)' == $value) {
return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) {
return $query->whereNested(static function (Yakamara\YForm\Manager\Query $query) use ($field) {
$query
->where($field, '')
->where($field, null)
;
}, 'OR');
}
if ('!(empty)' == $value) {
return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) {
return $query->whereNested(static function (Yakamara\YForm\Manager\Query $query) use ($field) {
$query
->where($field, '', '<>')
->where($field, null, '<>')
Expand Down
22 changes: 11 additions & 11 deletions tests/Manager/Table/ApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function testTableAPI()
$tableNameRelation = $prefix . 'related';

$table = self::setUpTable($tableName);
self::assertEquals(
static::assertEquals(
$table::class,
'Yakamara\YForm\Manager\Table\Table',
'table creation failed. (\Yakamara\YForm\Manager\Table\Api::setTable)',
Expand All @@ -76,14 +76,14 @@ public function testTableAPI()
// prüfen ob es angelegt ist.

$fields = Table::get($tableName)->getFields();
self::assertEquals(
static::assertEquals(
count($fields),
1,
'field creation failed (rex_yform_manager_table_api::setTableField)',
);

if (1 == count($fields)) {
self::assertEquals($fields[0]->getName(), $fieldName, 'fieldname validation failed');
static::assertEquals($fields[0]->getName(), $fieldName, 'fieldname validation failed');
}

// TODO: prüfen ob field gelöscht werden kann
Expand All @@ -92,8 +92,8 @@ public function testTableAPI()
$dataset = Dataset::create($tableName);
$dataset->setValue($fieldName, $fieldValue);

self::assertTrue($dataset->save(), 'dataset creation failed (rex_yform_manager_dataset::create)');
self::assertEquals(
static::assertTrue($dataset->save(), 'dataset creation failed (rex_yform_manager_dataset::create)');
static::assertEquals(
count($dataset->getMessages()),
0,
'dataset creation failed with Messages: ' . implode(',', $dataset->getMessages()),
Expand All @@ -103,31 +103,31 @@ public function testTableAPI()
$SQLDatasets = rex_sql::factory()->getArray(
'select * from ' . $tableName,
);
self::assertEquals(count($SQLDatasets), 1, 'dataset not found - creation failed (SQL Test)');
static::assertEquals(count($SQLDatasets), 1, 'dataset not found - creation failed (SQL Test)');

// YORM - Datensatz auslesen
$datasetId = $dataset->getId();
$dataset = Dataset::get($datasetId, $tableName);
self::assertNotNull($dataset, 'dataset not found - get via ID failed');
static::assertNotNull($dataset, 'dataset not found - get via ID failed');

// YORM - Datensatz bearbeiten
$fieldValueEdit = $fieldValue . ' overwrite';
$dataset
->setValue($fieldName, $fieldValueEdit)
->save();
$dataset = Dataset::get($datasetId, $tableName);
self::assertEquals(
static::assertEquals(
$dataset->getValue($fieldName),
$fieldValueEdit,
'dataset update failes - YOrm update failed',
);

// YORM - Datensatz löschen
if ($dataset) {
self::assertTrue($dataset->delete(), 'dataset delete failed (rex_yform_manager_dataset::delete)');
static::assertTrue($dataset->delete(), 'dataset delete failed (rex_yform_manager_dataset::delete)');

$dataset = Dataset::get($datasetId, $tableName);
self::assertFalse($dataset->exists(), 'dataset delete failed - YOrm delete failed');
static::assertFalse($dataset->exists(), 'dataset delete failed - YOrm delete failed');
}

// TODO - YORM - Relationen mit Relationstabelle prüfen
Expand Down Expand Up @@ -214,7 +214,7 @@ public function testTableAPI()

$table = Table::get($tableName);

self::assertNull($table, 'table schema removing failed');
static::assertNull($table, 'table schema removing failed');

// Cleanup
try {
Expand Down

0 comments on commit 921e25e

Please sign in to comment.