From aaae23c17ab970908e44b0bd332c40d44ec789e8 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 18:47:00 +0200 Subject: [PATCH 01/12] namespace YForm --- boot.php | 4 +++- composer.json | 13 +++++++++++-- lib/{yform/yform.php => YForm.php} | 20 +++++++++++++++++++- lib/manager/collection.php | 8 ++++---- lib/manager/dataset.php | 18 +++++++++--------- lib/manager/manager.php | 10 +++++----- lib/manager/search.php | 4 ++-- lib/yform/value/abstract.php | 4 ++-- lib/yform/value/be_table.php | 6 +++--- pages/email.php | 2 +- pages/manager.data_history.php | 2 +- pages/manager.table_edit.php | 4 ++-- pages/manager.table_migrate.php | 4 ++-- pages/manager.tableset_export.php | 2 +- pages/manager.tableset_import.php | 2 +- pages/rest.access.php | 2 +- pages/rest.token.php | 2 +- pages/setup.php | 2 +- rector.php | 16 ++++++++++++++++ ytemplates/bootstrap/value.fieldset.tpl.php | 3 +-- 20 files changed, 86 insertions(+), 42 deletions(-) rename lib/{yform/yform.php => YForm.php} (98%) create mode 100644 rector.php diff --git a/boot.php b/boot.php index 9eeeb7103..4f4cedd4b 100644 --- a/boot.php +++ b/boot.php @@ -5,7 +5,9 @@ * @psalm-scope-this rex_addon */ -rex_yform::addTemplatePath(rex_path::addon('yform', 'ytemplates')); +class_alias('Yakamara\YForm\YForm', 'rex_yform'); + +\Yakamara\YForm\YForm::addTemplatePath(rex_path::addon('yform', 'ytemplates')); if (rex::isBackend() && rex::getUser()) { /* @var $this rex_addon */ diff --git a/composer.json b/composer.json index 079348ba7..72a6e7c34 100644 --- a/composer.json +++ b/composer.json @@ -8,11 +8,20 @@ "require-dev": { "redaxo/php-cs-fixer-config": "^2.0", "friendsofphp/php-cs-fixer": "v3.37.1", - "phpunit/phpunit": "^9.5" + "phpunit/phpunit": "^9.5", + "rector/rector": "^1.2" }, "scripts": { "cs-dry": "php-cs-fixer fix -v --ansi --dry-run --config=.php-cs-fixer.dist.php", "cs-fix": "php-cs-fixer fix -v --ansi --config=.php-cs-fixer.dist.php", - "test": "phpunit --testdox" + "test": "phpunit --testdox", + "rector": [ + "Composer\\Config::disableProcessTimeout", + "rector process --ansi" + ], + "rector:no-cache": [ + "Composer\\Config::disableProcessTimeout", + "rector process --clear-cache --ansi" + ] } } diff --git a/lib/yform/yform.php b/lib/YForm.php similarity index 98% rename from lib/yform/yform.php rename to lib/YForm.php index c0e7d8417..4998bb424 100644 --- a/lib/yform/yform.php +++ b/lib/YForm.php @@ -7,7 +7,25 @@ * @author www.yakamara.de */ -class rex_yform +namespace Yakamara\YForm; + +use Exception; +use rex; +use rex_article; +use rex_autoload; +use rex_clang; +use rex_extension; +use rex_extension_point; +use rex_factory_trait; +use rex_fragment; +use rex_i18n; +use rex_response; +use rex_sql; +use rex_yform_base_abstract; +use rex_yform_validate_abstract; +use rex_yform_value_abstract; + +class YForm { use rex_factory_trait; diff --git a/lib/manager/collection.php b/lib/manager/collection.php index fc3379c5f..564188b71 100644 --- a/lib/manager/collection.php +++ b/lib/manager/collection.php @@ -428,9 +428,9 @@ public function delete(): bool return $success; } - public function getForm(): rex_yform + public function getForm(): \Yakamara\YForm\YForm { - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\YForm(); $yform->setDebug(self::$debug); $yform->objparams['form_name'] = 'yform-manager-multi-edit'; $yform->objparams['form_class'] .= ' yform-manager-multi-edit'; @@ -529,9 +529,9 @@ public function getForm(): rex_yform } /** - * @param null|callable(rex_yform):void $afterFieldsExecuted + * @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted */ - public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string + public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string { $yform->executeFields(); diff --git a/lib/manager/dataset.php b/lib/manager/dataset.php index aca1e6233..13dbb9871 100644 --- a/lib/manager/dataset.php +++ b/lib/manager/dataset.php @@ -492,7 +492,7 @@ public function getFields(array $filter = []): array return $this->getTable()->getFields($filter); } - public function getForm(): rex_yform + public function getForm(): \Yakamara\YForm\YForm { $yform = $this->createForm(); $this->setFormMainId($yform); @@ -501,18 +501,18 @@ public function getForm(): rex_yform } /** - * @param null|callable(rex_yform):void $afterFieldsExecuted + * @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted */ - public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string + public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string { $exists = $this->exists(); $oldData = $this->getData(); if ($exists) { - /** @var rex_yform $yform */ + /** @var \Yakamara\YForm\YForm $yform */ $yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_UPDATE', $yform, ['table' => $this->getTable(), 'data_id' => $this->id, 'data' => $this])); } else { - /** @var rex_yform $yform */ + /** @var \Yakamara\YForm\YForm $yform */ $yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_ADD', $yform, ['table' => $this->getTable(), 'data' => $this])); } @@ -672,7 +672,7 @@ public function __set(string $key, $value): void $this->setValue($key, $value); } - private function getInternalForm(): rex_yform + private function getInternalForm(): \Yakamara\YForm\YForm { $dummy = new static($this->table, 0); @@ -685,9 +685,9 @@ private function getInternalForm(): rex_yform return $yform; } - private function createForm(): rex_yform + private function createForm(): \Yakamara\YForm\YForm { - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\YForm(); $fields = $this->getFields(); $yform->setDebug(self::$debug); @@ -721,7 +721,7 @@ private function createForm(): rex_yform return $yform; } - private function setFormMainId(rex_yform $yform): void + private function setFormMainId(\Yakamara\YForm\YForm $yform): void { if ($this->exists()) { $where = 'id = ' . (int) $this->id; diff --git a/lib/manager/manager.php b/lib/manager/manager.php index b6e887eb2..1a4465fde 100644 --- a/lib/manager/manager.php +++ b/lib/manager/manager.php @@ -135,7 +135,7 @@ public function getDataPage() - transactional(static function () use (&$form, &$yform, $data, $func) { - $afterFieldsExecuted = static function (rex_yform $yform) { + $afterFieldsExecuted = static function (\Yakamara\YForm\YForm $yform) { /** @var rex_yform_value_abstract $valueObject */ foreach ($yform->objparams['values'] as $valueObject) { if ('submit' == $valueObject->getName()) { @@ -390,7 +390,7 @@ public function getDataPage() }; if ('clone' == $func) { - $afterFieldsExecuted = static function (rex_yform $yform) use ($afterFieldsExecuted) { + $afterFieldsExecuted = static function (\Yakamara\YForm\YForm $yform) use ($afterFieldsExecuted) { $yform->objparams['form_hiddenfields']['func'] = 'add'; unset($yform->objparams['form_hiddenfields']['data_id']); @@ -824,7 +824,7 @@ public function getFieldPage() echo $fragment->parse('core/page/section.php'); } - $types = rex_yform::getTypeArray(); + $types = \Yakamara\YForm\YForm::getTypeArray(); if ('choosenadd' == $func) { $link = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=add&'; @@ -913,7 +913,7 @@ public function getFieldPage() if (('add' == $func || 'edit' == $func) && isset($types[$type_id][$type_name])) { $field = new rex_yform_manager_field(['type_id' => $type_id, 'type_name' => $type_name]); - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\YForm(); $yform->setDebug(false); foreach ($this->getLinkVars() as $k => $v) { diff --git a/lib/manager/search.php b/lib/manager/search.php index a40459990..ae639adf2 100644 --- a/lib/manager/search.php +++ b/lib/manager/search.php @@ -46,9 +46,9 @@ public function setScriptPath(string $scriptpath): self return $this; } - public function getYForm(): rex_yform + public function getYForm(): \Yakamara\YForm\YForm { - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\YForm(); $yform->setObjectparams('form_name', 'rex_yform_searchvars-' . $this->table->getTableName()); $yform->setObjectparams('form_showformafterupdate', 1); $yform->setObjectparams('csrf_protection', false); diff --git a/lib/yform/value/abstract.php b/lib/yform/value/abstract.php index 278a619f6..7fc88e11c 100644 --- a/lib/yform/value/abstract.php +++ b/lib/yform/value/abstract.php @@ -312,7 +312,7 @@ public function canView(bool $viewable = true) public function isEditable() { - /** @var rex_yform $yform */ + /** @var \Yakamara\YForm\YForm $yform */ $yform = $this->params['this']; if (!$yform->isEditable()) { return false; @@ -326,7 +326,7 @@ public function isEditable() public function isViewable() { - /** @var rex_yform $yform */ + /** @var \Yakamara\YForm\YForm $yform */ $yform = $this->params['this']; if (!$yform->isViewable()) { return false; diff --git a/lib/yform/value/be_table.php b/lib/yform/value/be_table.php index 9a63bf378..6fa8942d3 100644 --- a/lib/yform/value/be_table.php +++ b/lib/yform/value/be_table.php @@ -13,7 +13,7 @@ public static function getColumnsByName($definition) if (count($_columns)) { foreach ($_columns as $index => $col) { // Use ;; for separating choice columns instead of , - $values = explode('|', trim(trim(str_replace(';;', ',', rex_yform::unhtmlentities($col))), '|')); + $values = explode('|', trim(trim(str_replace(';;', ',', \Yakamara\YForm\YForm::unhtmlentities($col))), '|')); if (1 == count($values)) { $values = ['text', 'text_' . $index, $values[0]]; } @@ -79,8 +79,8 @@ public function enterObject() $this->fieldData = $data; - $yfparams = rex_yform::factory()->objparams; - $yfparams['this'] = rex_yform::factory(); + $yfparams = \Yakamara\YForm\YForm::factory()->objparams; + $yfparams['this'] = \Yakamara\YForm\YForm::factory(); /* TODO * error class von validierung ans Eingabefeld übergeben diff --git a/pages/email.php b/pages/email.php index 1dac02ff8..3634dc7cf 100644 --- a/pages/email.php +++ b/pages/email.php @@ -68,7 +68,7 @@ $form_data[] = 'datestamp|updatedate||||0'; - $yform = rex_yform::factory(); + $yform = \Yakamara\YForm\YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/email'); $yform->setObjectparams('form_name', 'yform-email-template'); diff --git a/pages/manager.data_history.php b/pages/manager.data_history.php index a41413600..0edc7f0d4 100644 --- a/pages/manager.data_history.php +++ b/pages/manager.data_history.php @@ -264,7 +264,7 @@ $options = '' . rex_i18n::msg('yform_history_delete') . ': ' . $fragment->parse('core/buttons/button_group.php'); } -$historySearchForm = new rex_yform(); +$historySearchForm = new \Yakamara\YForm\YForm(); $historySearchForm->setObjectparams('form_action', $list->getUrl()); $historySearchForm->setObjectparams('form_showformafterupdate', true); $historySearchForm->setObjectparams('real_field_names', true); diff --git a/pages/manager.table_edit.php b/pages/manager.table_edit.php index 66fb690dc..131a06614 100644 --- a/pages/manager.table_edit.php +++ b/pages/manager.table_edit.php @@ -19,7 +19,7 @@ $show_list = true; if ('tableset_import' == $func && rex::getUser()->isAdmin()) { - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\YForm(); $yform->setDebug(true); $yform->setHiddenField('page', $page); $yform->setHiddenField('func', $func); @@ -73,7 +73,7 @@ } } - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\YForm(); // $yform->setDebug(TRUE); $yform->setObjectparams('form_name', $_csrf_key); $yform->setHiddenField('page', $page); diff --git a/pages/manager.table_migrate.php b/pages/manager.table_migrate.php index 4b835023d..fcc145fbc 100644 --- a/pages/manager.table_migrate.php +++ b/pages/manager.table_migrate.php @@ -27,7 +27,7 @@ } } -$yform = new rex_yform(); +$yform = new \Yakamara\YForm\YForm(); $yform->setObjectparams('form_showformafterupdate', 1); $yform->setObjectparams('form_name', $_csrf_key); $yform->setHiddenField('page', $page); @@ -45,7 +45,7 @@ unset($missing_tables[$table_name]); - $yform = new rex_yform(); + $yform = new \Yakamara\YForm\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]); diff --git a/pages/manager.tableset_export.php b/pages/manager.tableset_export.php index 2575adaa4..f2d99faff 100644 --- a/pages/manager.tableset_export.php +++ b/pages/manager.tableset_export.php @@ -18,7 +18,7 @@ $yform_tables[$table_name] = $g_table->getNameLocalized() . ' [' . $table_name . ']'; } -$yform = new rex_yform(); +$yform = new \Yakamara\YForm\YForm(); $yform->setHiddenField('page', $page); $yform->setObjectparams('real_field_names', true); $yform->setObjectparams('form_name', $_csrf_key); diff --git a/pages/manager.tableset_import.php b/pages/manager.tableset_import.php index 450d5375e..f7b7322bc 100644 --- a/pages/manager.tableset_import.php +++ b/pages/manager.tableset_import.php @@ -12,7 +12,7 @@ $page = rex_request('page', 'string', ''); -$yform = new rex_yform(); +$yform = new \Yakamara\YForm\YForm(); $yform->setHiddenField('page', $page); $yform->setObjectparams('real_field_names', true); $yform->setObjectparams('form_name', $_csrf_key); diff --git a/pages/rest.access.php b/pages/rest.access.php index cb9c892fa..49eff94c6 100644 --- a/pages/rest.access.php +++ b/pages/rest.access.php @@ -34,7 +34,7 @@ $form_data[] = 'datetime|datetime_created|translate:yform_rest_token_access_datetime_created'; $form_data[] = 'text|url|translate:yform_rest_token_url'; - $yform = rex_yform::factory(); + $yform = \Yakamara\YForm\YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/rest/access'); $yform->setFormData(implode("\n", $form_data)); diff --git a/pages/rest.token.php b/pages/rest.token.php index efba4a7ac..ef77f40f3 100644 --- a/pages/rest.token.php +++ b/pages/rest.token.php @@ -46,7 +46,7 @@ $form_data[] = 'integer|amount|translate:yform_rest_token_amount'; $form_data[] = 'choice|paths|translate:yform_rest_token_token_paths|' . implode(',', $routes) . '||1'; - $yform = rex_yform::factory(); + $yform = \Yakamara\YForm\YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/rest/token'); $yform->setObjectparams('form_name', 'yform-rest-token-form'); diff --git a/pages/setup.php b/pages/setup.php index f0c2e2df8..6a3c6affc 100644 --- a/pages/setup.php +++ b/pages/setup.php @@ -69,5 +69,5 @@ $fragment = new rex_fragment(); $fragment->setVar('title', $this->i18n('description_type_heading'), false); -$fragment->setVar('body', rex_yform::showHelp(), false); +$fragment->setVar('body', \Yakamara\YForm\YForm::showHelp(), false); echo $fragment->parse('core/page/section.php'); diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..4c7d5f55d --- /dev/null +++ b/rector.php @@ -0,0 +1,16 @@ +withPaths(['docs', 'fragments', 'lib', 'module', 'pages', 'ytemplates', 'boot.php']) + ->withParallel() + ->withPhpVersion(PhpVersion::PHP_83) + ->withConfiguredRule( + RenameClassRector::class, + [ + 'rex_yform' => 'Yakamara\YForm\YForm', + ], + ); diff --git a/ytemplates/bootstrap/value.fieldset.tpl.php b/ytemplates/bootstrap/value.fieldset.tpl.php index 4c1de3088..216371f5a 100644 --- a/ytemplates/bootstrap/value.fieldset.tpl.php +++ b/ytemplates/bootstrap/value.fieldset.tpl.php @@ -1,10 +1,9 @@ Date: Sat, 7 Sep 2024 19:13:27 +0200 Subject: [PATCH 02/12] REST namespaced --- boot.php | 10 ++- lib/rest/{auth/auth.php => AuthToken.php} | 20 ++++-- lib/rest/rest.php | 18 ++++-- lib/rest/route.php | 77 ++++++++++++++--------- pages/rest.access.php | 2 +- pages/rest.token.php | 4 +- rector.php | 3 + 7 files changed, 88 insertions(+), 46 deletions(-) rename lib/rest/{auth/auth.php => AuthToken.php} (90%) diff --git a/boot.php b/boot.php index 4f4cedd4b..b1e17db27 100644 --- a/boot.php +++ b/boot.php @@ -1,13 +1,19 @@ getArray('select * from ' . rex::getTable('yform_rest_token') . ' where status=1 and token=? and FIND_IN_SET(?, paths)', [$myToken, $route->getPath()]); @@ -57,13 +65,13 @@ public static function addHit(array $TokenAuth) ->setTable(rex::getTable('yform_rest_token_access')) ->setValue('token_id', $TokenAuth['id']) ->setValue('datetime_created', date(rex_sql::FORMAT_DATETIME)) - ->setValue('url', rex_yform_rest::getCurrentUrl()) + ->setValue('url', Rest::getCurrentUrl()) ->insert(); } /** * @throws rex_sql_exception - * @return null|mixed + * @return mixed|null */ public static function get(int $id) { @@ -81,7 +89,7 @@ public static function get(int $id) /** * @throws rex_sql_exception - * @return null|mixed + * @return mixed|null */ public static function getCurrentIntervalAmount(string $interval, $token_id) { diff --git a/lib/rest/rest.php b/lib/rest/rest.php index f82d8810a..dec6b5d52 100644 --- a/lib/rest/rest.php +++ b/lib/rest/rest.php @@ -1,6 +1,13 @@ hasAuth()) { self::sendError('400', 'no-access'); } else { @@ -163,7 +169,7 @@ public static function getHeader($key = '', $default = '') * @param array $params * @param array $additionalPaths */ - public static function getLinkByPath(rex_yform_rest_route $route, $params = [], $additionalPaths = []): string + public static function getLinkByPath(Route $route, $params = [], $additionalPaths = []): string { if (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && 'https' == $_SERVER['HTTP_X_FORWARDED_PROTO']) { $url = 'https://'; @@ -188,7 +194,7 @@ public static function getLinkByPath(rex_yform_rest_route $route, $params = [], } /** - * @return null|mixed + * @return mixed|null */ public static function getRouteByInstance($instance) { diff --git a/lib/rest/route.php b/lib/rest/route.php index 625645587..6e85f2055 100644 --- a/lib/rest/route.php +++ b/lib/rest/route.php @@ -1,6 +1,26 @@ additionalHeaders as $name => $value) { - rex_yform_rest::setHeader($name, $value); + Rest::setHeader($name, $value); } - rex_yform_rest::sendContent($status, $content, $contentType); + Rest::sendContent($status, $content, $contentType); exit; } @@ -87,12 +107,12 @@ public function getPath() public function handleRequest(array $paths, array $get) { if (!isset($this->config['table'])) { - rex_yform_rest::sendError('400', 'table-not-available'); + Rest::sendError('400', 'table-not-available'); } $requestMethod = $this->getRequestMethod(); if (in_array($requestMethod, self::$requestMethods) && !isset($this->config[$requestMethod])) { - rex_yform_rest::sendError('400', 'request-method-not-available'); + Rest::sendError('400', 'request-method-not-available'); } /** @var rex_yform_manager_table $table */ @@ -150,7 +170,7 @@ public function handleRequest(array $paths, array $get) $instances = $query->find(); } catch (rex_sql_exception $e) { - rex_yform_rest::sendError('400', 'query-error', []); + Rest::sendError('400', 'query-error', []); } } @@ -178,7 +198,7 @@ public function handleRequest(array $paths, array $get) } if (!$instance) { - rex_yform_rest::sendError('400', 'dataset-not-found', ['paths' => $paths, 'table' => $instances->getTable()->getTableName()]); + Rest::sendError('400', 'dataset-not-found', ['paths' => $paths, 'table' => $instances->getTable()->getTableName()]); } $attribute = null; $instances = null; @@ -194,7 +214,7 @@ public function handleRequest(array $paths, array $get) $instance = $query->findOne(); if (!$instance) { - rex_yform_rest::sendError('400', 'dataset-not-found', ['paths' => $paths, 'table' => $query->getTable()->getTableName()]); + Rest::sendError('400', 'dataset-not-found', ['paths' => $paths, 'table' => $query->getTable()->getTableName()]); } $fields = $this->getFields('get', $instance); @@ -203,7 +223,7 @@ public function handleRequest(array $paths, array $get) $attribute = $path; if (!array_key_exists($attribute, $fields)) { - rex_yform_rest::sendError('400', 'attribute-not-found', ['paths' => $paths, 'table' => $table->getTableName()]); + Rest::sendError('400', 'attribute-not-found', ['paths' => $paths, 'table' => $table->getTableName()]); } if ('be_manager_relation' == $fields[$attribute]->getTypeName()) { @@ -221,7 +241,6 @@ public function handleRequest(array $paths, array $get) $data = []; if ($instances) { foreach ($instances as $instance) { - $instance_data = $this->getInstanceData( $instance, array_merge($paths, [$instance->getId()]), @@ -256,19 +275,19 @@ public function handleRequest(array $paths, array $get) $meta['itemsPerPage'] = $per_page; $meta['currentPage'] = $currentPage; - $links['self'] = rex_yform_rest::getLinkByPath($this, $linkParams); - $links['first'] = rex_yform_rest::getLinkByPath($this, array_merge( + $links['self'] = Rest::getLinkByPath($this, $linkParams); + $links['first'] = Rest::getLinkByPath($this, array_merge( $linkParams, ['page' => 1], )); if (($currentPage - 1) > 0) { - $links['prev'] = rex_yform_rest::getLinkByPath($this, array_merge( + $links['prev'] = Rest::getLinkByPath($this, array_merge( $linkParams, ['page' => ($currentPage - 1)], )); } if (($currentPage * $per_page) < $itemsAll) { - $links['next'] = rex_yform_rest::getLinkByPath($this, array_merge( + $links['next'] = Rest::getLinkByPath($this, array_merge( $linkParams, ['page' => ($currentPage + 1)], )); @@ -317,11 +336,11 @@ public function handleRequest(array $paths, array $get) $status = '400'; if (self::getTypeFromInstance($instance) != $type) { - rex_yform_rest::sendError($status, 'post-data-type-different'); + Rest::sendError($status, 'post-data-type-different'); } if (0 == count($data)) { - rex_yform_rest::sendError($status, 'post-data-attributes-empty'); + Rest::sendError($status, 'post-data-attributes-empty'); } else { $dataset = null; if (isset($in['id'])) { @@ -369,12 +388,12 @@ public function handleRequest(array $paths, array $get) } if ($dataset->save()) { - rex_yform_rest::sendContent($status, ['id' => $dataset->getId()]); + Rest::sendContent($status, ['id' => $dataset->getId()]); } else { foreach ($dataset->getMessages() as $message_key => $message) { $errors[] = rex_i18n::translate($message); } - rex_yform_rest::sendError($status, 'errors-set', $errors); + Rest::sendError($status, 'errors-set', $errors); } } @@ -389,12 +408,12 @@ public function handleRequest(array $paths, array $get) $query = $this->getFilterQuery($query, $fields, $get); if ($queryClone === $query && isset($get['filter'])) { - rex_yform_rest::sendError($status, 'no-available-filter-set'); + Rest::sendError($status, 'no-available-filter-set'); } elseif ($queryClone->getQuery() !== $query->getQuery()) { // filter set -> true $status = '200'; } elseif (0 == count($paths)) { - rex_yform_rest::sendError($status, 'no-id-set'); + Rest::sendError($status, 'no-id-set'); } else { $id = current($paths); $query->where('id', $id); @@ -419,7 +438,7 @@ public function handleRequest(array $paths, array $get) $content['dataset'][] = $date; } - rex_yform_rest::sendContent($status, $content); + Rest::sendContent($status, $content); break; @@ -430,13 +449,13 @@ public function handleRequest(array $paths, array $get) $availableMethods[] = strtoupper($method); } } - rex_yform_rest::sendError('404', 'no-request-method-found', ['please only use: ' . implode(',', $availableMethods)]); + Rest::sendError('404', 'no-request-method-found', ['please only use: ' . implode(',', $availableMethods)]); } } /** * @throws rex_api_exception - * @return rex_yform_manager_field[] + * @return array */ public function getFields(string $type = 'get', $instance = null): array { @@ -490,7 +509,7 @@ public function getFilterQuery(rex_yform_manager_query $query, array $fields, ar 'query' => $query, ]); } catch (Error $e) { - rex_yform_rest::sendError('400', 'field-static-method-call-failed', ['class' => 'rex_yform_value_' . $field->getTypeName(), 'field' => $fieldName]); + Rest::sendError('400', 'field-static-method-call-failed', ['class' => 'rex_yform_value_' . $field->getTypeName(), 'field' => $fieldName]); exit; } } else { @@ -509,7 +528,7 @@ public function getFilterQuery(rex_yform_manager_query $query, array $fields, ar public function getInstanceData($instance, $paths, $onlyId = false, $parents = []): array { $links = []; - $links['self'] = rex_yform_rest::getLinkByPath($this, [], $paths); + $links['self'] = Rest::getLinkByPath($this, [], $paths); if ($onlyId) { return @@ -551,7 +570,7 @@ public function getInstanceAttributes(rex_yform_manager_dataset $instance, $pare private function getIncludes(): array { if (null === $this->includes) { - $includes = @rex_request('include', 'string', ''); + $includes = @rex_request('include', 'string'); if ('' == $includes) { $this->includes = []; } else { @@ -621,13 +640,13 @@ public function getInstanceRelationships(rex_yform_manager_dataset $instance, $p ]; $links = []; - $links['self'] = rex_yform_rest::getLinkByPath($this, [], array_merge($paths, [$field->getName()])); + $links['self'] = Rest::getLinkByPath($this, [], array_merge($paths, [$field->getName()])); if (isset($relationInstance)) { - $route = rex_yform_rest::getRouteByInstance($relationInstance); + $route = Rest::getRouteByInstance($relationInstance); if ($route) { - $links['absolute'] = rex_yform_rest::getLinkByPath($route, []); + $links['absolute'] = Rest::getLinkByPath($route, []); } } diff --git a/pages/rest.access.php b/pages/rest.access.php index 49eff94c6..c83fdd097 100644 --- a/pages/rest.access.php +++ b/pages/rest.access.php @@ -154,7 +154,7 @@ $list->setColumnParams('token_id', ['page' => 'yform/rest/token', 'func' => 'edit', 'data_id' => '###rest_id###']); $list->setColumnFormat('token_id', 'custom', static function ($params) { - $token = rex_yform_rest_auth_token::get($params['subject']); + $token = \Yakamara\YForm\Rest\AuthToken::get($params['subject']); if ($token) { return '' . $token['name'] . ''; } diff --git a/pages/rest.token.php b/pages/rest.token.php index ef77f40f3..703871505 100644 --- a/pages/rest.token.php +++ b/pages/rest.token.php @@ -21,7 +21,7 @@ $show_list = true; $routes = []; -foreach (rex_yform_rest::getRoutes() as $route) { +foreach (\Yakamara\YForm\Rest\Rest::getRoutes() as $route) { $routes[] = $route->getPath(); } @@ -189,7 +189,7 @@ $return = $maxHits; if ('none' != $list->getValue('interval')) { - $currentHits = rex_yform_rest_auth_token::getCurrentIntervalAmount($list->getValue('interval'), $list->getValue('id')); + $currentHits = \Yakamara\YForm\Rest\AuthToken::getCurrentIntervalAmount($list->getValue('interval'), $list->getValue('id')); $return = $currentHits . ' / ' . $maxHits . ' / ' . $list->getValue('interval') . ''; } diff --git a/rector.php b/rector.php index 4c7d5f55d..789e148c4 100644 --- a/rector.php +++ b/rector.php @@ -12,5 +12,8 @@ RenameClassRector::class, [ 'rex_yform' => 'Yakamara\YForm\YForm', + 'rex_yform_rest' => 'Yakamara\YForm\Rest\Rest', + 'rex_yform_rest_route' => 'Yakamara\YForm\Rest\Route', + 'rex_yform_rest_auth_token' => 'Yakamara\YForm\Rest\AuthToken', ], ); From 297cd8ba33104881b05dddfce3524e99932e3ff2 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 19:26:21 +0200 Subject: [PATCH 03/12] List namespaced --- boot.php | 2 + lib/{list.php => List/List.php} | 56 +++++++++++++++++--------- lib/{list_tools.php => List/Tools.php} | 11 +++-- rector.php | 2 + 4 files changed, 46 insertions(+), 25 deletions(-) rename lib/{list.php => List/List.php} (96%) rename lib/{list_tools.php => List/Tools.php} (92%) diff --git a/boot.php b/boot.php index b1e17db27..5beaa4ca9 100644 --- a/boot.php +++ b/boot.php @@ -12,6 +12,8 @@ class_alias('Yakamara\YForm\YForm', 'rex_yform'); class_alias('Yakamara\YForm\Rest\Rest', 'rex_yform_rest'); class_alias('Yakamara\YForm\Rest\Route', 'rex_yform_rest_route'); class_alias('Yakamara\YForm\Rest\AuthToken', 'rex_yform_rest_auth_token'); +class_alias('Yakamara\YForm\List\YList', 'rex_yform_list'); +class_alias('Yakamara\YForm\List\Tools', 'rex_yform_list_tools'); YForm::addTemplatePath(rex_path::addon('yform', 'ytemplates')); diff --git a/lib/list.php b/lib/List/List.php similarity index 96% rename from lib/list.php rename to lib/List/List.php index ed4918041..2c5ecb696 100644 --- a/lib/list.php +++ b/lib/List/List.php @@ -1,18 +1,37 @@ |callable(self):string */ + /** @psalm-var array|callable(\Yakamara\YForm\List\YList):string */ private $rowAttributes; // --------- Column Attributes @@ -339,11 +358,10 @@ public function getLinkAttributes($column, $default = null) } // row attribute setter/getter - /** * Methode, um der Zeile () Attribute hinzuzufügen. * - * @param array|callable(self):string $attr Entweder ein array: [attributname => attribut, ...] + * @param array|callable(\Yakamara\YForm\List\YList):string $attr Entweder ein array: [attributname => attribut, ...] * oder eine Callback-Funktion */ public function setRowAttributes($attr): void @@ -354,7 +372,7 @@ public function setRowAttributes($attr): void /** * Methode, um die Zeilen-Attribute () abzufragen. * - * @return array|callable(self):string Entweder ein array: [attributname => attribut, ...] + * @return array|callable(\Yakamara\YForm\List\YList):string Entweder ein array: [attributname => attribut, ...] * oder eine Callback-Funktion */ public function getRowAttributes() @@ -529,8 +547,8 @@ public function getColumnFormat($columnName, $default = null) */ public function setColumnSortable($columnName, $direction = 'asc') { - $this->setColumnOption($columnName, REX_LIST_OPT_SORT, true); - $this->setColumnOption($columnName, REX_LIST_OPT_SORT_DIRECTION, strtolower($direction)); + $this->setColumnOption($columnName, self::LIST_OPT_SORT, true); + $this->setColumnOption($columnName, self::LIST_OPT_SORT_DIRECTION, strtolower($direction)); } /** @@ -980,7 +998,7 @@ public function isCustomFormat($format) * Formatiert einen übergebenen String anhand der rexFormatter Klasse. * * @param string $value Zu formatierender String - * @param null|array $format mit den Formatierungsinformationen + * @param array|null $format mit den Formatierungsinformationen * @param bool $escape Flag, Ob escapen von $value erlaubt ist * @param string $field * @@ -1122,11 +1140,11 @@ public function get() $s .= ' ' . "\n"; foreach ($columnNames as $columnName) { $columnHead = $this->getColumnLabel($columnName); - if ($this->hasColumnOption($columnName, REX_LIST_OPT_SORT)) { + if ($this->hasColumnOption($columnName, self::LIST_OPT_SORT)) { if ($columnName == $sortColumn) { $columnSortType = 'desc' == $sortType ? 'asc' : 'desc'; } else { - $columnSortType = $this->getColumnOption($columnName, REX_LIST_OPT_SORT_DIRECTION, 'asc'); + $columnSortType = $this->getColumnOption($columnName, self::LIST_OPT_SORT_DIRECTION, 'asc'); } $columnHead = '' . $columnHead . ''; } diff --git a/lib/list_tools.php b/lib/List/Tools.php similarity index 92% rename from lib/list_tools.php rename to lib/List/Tools.php index 34d6aefa2..6d48869fd 100644 --- a/lib/list_tools.php +++ b/lib/List/Tools.php @@ -1,11 +1,10 @@ 'Yakamara\YForm\Rest\Rest', 'rex_yform_rest_route' => 'Yakamara\YForm\Rest\Route', 'rex_yform_rest_auth_token' => 'Yakamara\YForm\Rest\AuthToken', + 'rex_yform_list' => 'Yakamara\YForm\List\YList', + 'rex_yform_list_tools' => 'Yakamara\YForm\List\Tools', ], ); From a7e0f9e72c5320afc58ac5bfdf93ea0efd3dbd95 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 20:22:01 +0200 Subject: [PATCH 04/12] RexVars namespaced --- lib/{var_yform_data.php => RexVar/Data.php} | 9 ++++- .../TableData.php} | 33 ++++++++----------- rector.php | 2 ++ 3 files changed, 24 insertions(+), 20 deletions(-) rename lib/{var_yform_data.php => RexVar/Data.php} (90%) rename lib/{var_yform_dataset.php => RexVar/TableData.php} (90%) diff --git a/lib/var_yform_data.php b/lib/RexVar/Data.php similarity index 90% rename from lib/var_yform_data.php rename to lib/RexVar/Data.php index 982b1e4b2..000313cea 100644 --- a/lib/var_yform_data.php +++ b/lib/RexVar/Data.php @@ -5,7 +5,14 @@ * * @package redaxo\structure\content */ -class rex_var_yform_data extends rex_var + +namespace Yakamara\YForm\RexVar; + +use rex_var; + +use function in_array; + +class Data extends rex_var { /** * @return false|string|bool diff --git a/lib/var_yform_dataset.php b/lib/RexVar/TableData.php similarity index 90% rename from lib/var_yform_dataset.php rename to lib/RexVar/TableData.php index 7c9dfa649..74a7fe2a1 100644 --- a/lib/var_yform_dataset.php +++ b/lib/RexVar/TableData.php @@ -8,7 +8,20 @@ * * @package redaxo\yform\manager */ -class rex_var_yform_table_data extends rex_var + +namespace Yakamara\YForm\RexVar; + +use rex_formatter; +use rex_fragment; +use rex_i18n; +use rex_select; +use rex_var; +use rex_yform_manager_table; +use rex_yform_value_be_manager_relation; + +use function in_array; + +class TableData extends rex_var { protected function getOutput() { @@ -73,24 +86,6 @@ protected function getOutput() $value = self::getSingleWidget($id, 'REX_INPUT_VALUE[' . $id . ']', $value, $args); } } - // else { - // if ($value && $this->hasArg('output') && $this->getArg('output') != 'id') { - // if ($tableName == '') { - // return self::quote('[table param not defined]'); - // } - // - // $table = rex_yform_manager_table::get($tableName); - // if (!$table) { - // return self::quote('[table not in YForm?]'); - // } - // - // $query = rex_yform_manager_dataset::query($table->getTableName()); - // $method = (strpos($value, ',') === false) ? 'findId' : 'findIDs'; - // $value = $query->{$method}($value); - // //return 'rex_var::nothing(require rex_stream::factory(mb_substr(__FILE__, 6) . \'/REX_YFORM_DATASET/'.$id.'\', '.self::quote(json_encode($value)).'))'; - // return self::quote(json_encode($value)); - // } - // } return self::quote($value); } diff --git a/rector.php b/rector.php index cd9a4dec0..3cb7a3557 100644 --- a/rector.php +++ b/rector.php @@ -17,5 +17,7 @@ 'rex_yform_rest_auth_token' => 'Yakamara\YForm\Rest\AuthToken', 'rex_yform_list' => 'Yakamara\YForm\List\YList', 'rex_yform_list_tools' => 'Yakamara\YForm\List\Tools', + 'rex_var_yform_data' => 'Yakamara\YForm\RexVar\Data', + 'rex_var_yform_table_data' => 'Yakamara\YForm\RexVar\TableData', ], ); From 1a08f4b04f8a06208f787969240013eaa953cc08 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 20:31:57 +0200 Subject: [PATCH 05/12] EMail namespaced --- boot.php | 3 +++ fragments/yform/manager/page/list.php | 4 ++-- .../Template.php} | 21 +++++++++++++++++-- lib/yform/action/tpl2email.php | 6 +++--- pages/email.php | 9 +++++--- rector.php | 1 + .../value.be_manager_relation.tpl.php | 6 +++--- 7 files changed, 37 insertions(+), 13 deletions(-) rename lib/{email_template.php => Email/Template.php} (94%) diff --git a/boot.php b/boot.php index 5beaa4ca9..7b919bbdd 100644 --- a/boot.php +++ b/boot.php @@ -14,6 +14,9 @@ class_alias('Yakamara\YForm\Rest\Route', 'rex_yform_rest_route'); class_alias('Yakamara\YForm\Rest\AuthToken', 'rex_yform_rest_auth_token'); class_alias('Yakamara\YForm\List\YList', 'rex_yform_list'); class_alias('Yakamara\YForm\List\Tools', 'rex_yform_list_tools'); +class_alias('Yakamara\YForm\RexVar\Data', 'rex_var_yform_data'); +class_alias('Yakamara\YForm\RexVar\TableData', 'rex_var_yform_data'); +class_alias('Yakamara\YForm\Email\Template', 'rex_yform_email_template'); YForm::addTemplatePath(rex_path::addon('yform', 'ytemplates')); diff --git a/fragments/yform/manager/page/list.php b/fragments/yform/manager/page/list.php index 176caea0f..6771c53c1 100644 --- a/fragments/yform/manager/page/list.php +++ b/fragments/yform/manager/page/list.php @@ -13,8 +13,8 @@ $popup = $this->getVar('popup'); $hasDataPageFunctions = $this->getVar('hasDataPageFunctions'); -/** @var rex_yform_list $list */ -$list = rex_yform_list::factory($query, $table->getListAmount()); +/** @var \Yakamara\YForm\List\YList $list */ +$list = \Yakamara\YForm\List\YList::factory($query, $table->getListAmount()); $list->addTableAttribute('class', 'table-striped table-hover yform-table-' . rex_string::normalize($this->table->getTableName())); diff --git a/lib/email_template.php b/lib/Email/Template.php similarity index 94% rename from lib/email_template.php rename to lib/Email/Template.php index 2e0f87c0f..f025d6cf0 100644 --- a/lib/email_template.php +++ b/lib/Email/Template.php @@ -7,7 +7,24 @@ * @author www.yakamara.de */ -class rex_yform_email_template +namespace Yakamara\YForm\Email; + +use PHPMailer\PHPMailer\Exception; +use rex; +use rex_article; +use rex_extension; +use rex_extension_point; +use rex_file; +use rex_mailer; +use rex_sql; +use rex_sql_exception; +use rex_stream; +use rex_var; + +use function count; +use function is_array; + +class Template { /** * @throws rex_sql_exception @@ -91,7 +108,7 @@ public static function makeSingleLine(string $str): string } /** - * @throws \PHPMailer\PHPMailer\Exception + * @throws Exception * @return bool */ public static function sendMail(array $template, string $template_name = '') diff --git a/lib/yform/action/tpl2email.php b/lib/yform/action/tpl2email.php index c0a80356c..5e2502114 100644 --- a/lib/yform/action/tpl2email.php +++ b/lib/yform/action/tpl2email.php @@ -12,7 +12,7 @@ class rex_yform_action_tpl2email extends rex_yform_action_abstract public function executeAction(): void { $template_name = $this->getElement(2); - if ($etpl = rex_yform_email_template::getTemplate($template_name)) { + if ($etpl = \Yakamara\YForm\Email\Template::getTemplate($template_name)) { $email_to = rex::getErrorEmail(); if (filter_var($this->getElement(3), FILTER_VALIDATE_EMAIL)) { @@ -41,7 +41,7 @@ public function executeAction(): void dump($etpl); } - $etpl = rex_yform_email_template::replaceVars($etpl, $this->params['value_pool']['email']); + $etpl = \Yakamara\YForm\Email\Template::replaceVars($etpl, $this->params['value_pool']['email']); $etpl['mail_to'] = $email_to; $etpl['mail_to_name'] = $email_to_name; @@ -66,7 +66,7 @@ public function executeAction(): void dump($etpl); } - if (!rex_yform_email_template::sendMail($etpl, $template_name)) { + if (!\Yakamara\YForm\Email\Template::sendMail($etpl, $template_name)) { if ($this->params['debug']) { dump('email could not be sent'); } diff --git a/pages/email.php b/pages/email.php index 3634dc7cf..bc374e90d 100644 --- a/pages/email.php +++ b/pages/email.php @@ -1,5 +1,8 @@ setObjectparams('form_action', 'index.php?page=yform/email'); $yform->setObjectparams('form_name', 'yform-email-template'); diff --git a/rector.php b/rector.php index 3cb7a3557..3eb23ea4c 100644 --- a/rector.php +++ b/rector.php @@ -19,5 +19,6 @@ 'rex_yform_list_tools' => 'Yakamara\YForm\List\Tools', 'rex_var_yform_data' => 'Yakamara\YForm\RexVar\Data', 'rex_var_yform_table_data' => 'Yakamara\YForm\RexVar\TableData', + 'rex_yform_email_template' => 'Yakamara\YForm\Email\Template', ], ); diff --git a/ytemplates/bootstrap/value.be_manager_relation.tpl.php b/ytemplates/bootstrap/value.be_manager_relation.tpl.php index 1f561af56..e25210856 100644 --- a/ytemplates/bootstrap/value.be_manager_relation.tpl.php +++ b/ytemplates/bootstrap/value.be_manager_relation.tpl.php @@ -64,7 +64,7 @@ getRelationType()) { - echo \rex_var_yform_table_data::getRelationWidget($id, $this->getFieldName(), $this->getValue(), $link, $this->params['main_id']); + echo \Yakamara\YForm\RexVar\TableData::getRelationWidget($id, $this->getFieldName(), $this->getValue(), $link, $this->params['main_id']); } elseif (2 == $this->getRelationType()) { $name = $this->getFieldName(); $args = []; @@ -74,7 +74,7 @@ $_csrf_key = rex_yform_manager_table::get($this->relation['target_table'])->getCSRFKey(); $args += rex_csrf_token::factory($_csrf_key)->getUrlParams(); $value = implode(',', $this->getValue()); - echo \rex_var_yform_table_data::getSingleWidget($id, $name, $value, $args); + echo \Yakamara\YForm\RexVar\TableData::getSingleWidget($id, $name, $value, $args); } else { $name = $this->getFieldName(); $args = []; @@ -86,7 +86,7 @@ $_csrf_key = rex_yform_manager_table::get($this->relation['target_table'])->getCSRFKey(); $args += rex_csrf_token::factory($_csrf_key)->getUrlParams(); $value = implode(',', $this->getValue()); - echo \rex_var_yform_table_data::getMultipleWidget($id, $name, $value, $args); + echo \Yakamara\YForm\RexVar\TableData::getMultipleWidget($id, $name, $value, $args); } ?> From eb275d90e5a7c33a30625a43f46131d92edb021b Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 22:21:08 +0200 Subject: [PATCH 06/12] Manager namespaced --- boot.php | 25 ++- docs/04_yorm.md | 10 +- fragments/yform/manager/page/layout.php | 2 +- fragments/yform/manager/page/list.php | 2 +- lib/List/List.php | 21 ++- lib/RexVar/TableData.php | 2 +- lib/manager/collection.php | 61 +++++--- lib/manager/dataset.php | 93 +++++++----- lib/manager/field.php | 17 ++- lib/manager/manager.php | 143 ++++++++++-------- lib/manager/query.php | 65 +++++--- lib/manager/search.php | 26 +++- lib/manager/{table.php => table/Table.php} | 77 ++++++---- lib/manager/table/api.php | 78 ++++++---- lib/manager/table/authorization.php | 24 ++- lib/manager/table/perm/edit.php | 15 +- lib/manager/table/perm/view.php | 15 +- lib/rest/route.php | 44 +++--- lib/yform/value/be_link.php | 8 +- lib/yform/value/be_manager_relation.php | 34 ++--- lib/yform/value/be_media.php | 6 +- lib/yform/value/checkbox.php | 6 +- lib/yform/value/choice.php | 2 +- lib/yform/value/date.php | 2 +- lib/yform/value/datetime.php | 2 +- lib/yform/value/index.php | 10 +- lib/yform/value/integer.php | 6 +- lib/yform/value/number.php | 2 +- lib/yform/value/text.php | 8 +- lib/yform/value/upload.php | 2 +- pages/manager.data_edit.php | 14 +- pages/manager.data_history.php | 14 +- pages/manager.data_import.php | 8 +- pages/manager.table_edit.php | 28 ++-- pages/manager.table_field.php | 2 +- pages/manager.table_migrate.php | 4 +- pages/manager.tableset_export.php | 4 +- pages/manager.tableset_import.php | 2 +- rector.php | 22 ++- tests/rex_yform_yorm_test.php | 38 ++--- .../value.be_manager_relation.tpl.php | 4 +- 41 files changed, 556 insertions(+), 392 deletions(-) rename lib/manager/{table.php => table/Table.php} (89%) diff --git a/boot.php b/boot.php index 7b919bbdd..f98c0a340 100644 --- a/boot.php +++ b/boot.php @@ -1,5 +1,7 @@ getParam('table')); + $table = Table::get($ep->getParam('table')); if (!$table) { return; } $dataset = $ep->getParam('form')->getParam('manager_dataset'); if (!$dataset) { - $dataset = rex_yform_manager_dataset::getRaw($ep->getParam('id'), $table->getTableName()); + $dataset = Dataset::getRaw($ep->getParam('id'), $table->getTableName()); } $dataset->invalidateData(); if ($table->hasHistory() && $dataset->isHistoryEnabled()) { - $action = 'insert' === $ep->getParam('action') ? rex_yform_manager_dataset::ACTION_CREATE : rex_yform_manager_dataset::ACTION_UPDATE; + $action = 'insert' === $ep->getParam('action') ? Dataset::ACTION_CREATE : Dataset::ACTION_UPDATE; $dataset->makeSnapshot($action); } }); diff --git a/docs/04_yorm.md b/docs/04_yorm.md index 6261b6afa..a86c8da5d 100644 --- a/docs/04_yorm.md +++ b/docs/04_yorm.md @@ -24,9 +24,9 @@ dump($items); Es stehen folgende Klassen zur Verfügung: -- `rex_yform_manager_dataset` -- `rex_yform_manager_collection` -- `rex_yform_manager_query` +- `Yakamara\YForm\Manager\Collection` +- `Yakamara\YForm\Manager\Dataset` +- `Yakamara\YForm\Manager\Query` @@ -519,7 +519,7 @@ Beispiel für resetSelect() // resetSelect() ermöglicht es im Anschluss per select nur die Felder des Datensatzes zu erhalten, die man wirklich benötigt. ```php -$dataset = rex_yform_manager_query::get('rex_yf_example') +$dataset = Yakamara\YForm\Manager\Query::get('rex_yf_example') ->resetSelect() ->select('id') ->select('title') @@ -682,7 +682,7 @@ Nachteil: Man kann keine anderen Operatoren als = verwenden. Mit `whereNested` in der Callback-Notation arbeiten: ``` -$query->whereNested(function (rex_yform_manager_query $query) { +$query->whereNested(function (Yakamara\YForm\Manager\Query $query) { $query ->where('foo', 1) ->where('bar', 2) diff --git a/fragments/yform/manager/page/layout.php b/fragments/yform/manager/page/layout.php index 99c8753ad..358be6fd3 100644 --- a/fragments/yform/manager/page/layout.php +++ b/fragments/yform/manager/page/layout.php @@ -8,7 +8,7 @@ /** @var rex_yform_manager $manager */ $manager = $this->getVar('this'); -/** @var rex_yform_manager_table $table */ +/** @var \Yakamara\YForm\Manager\Table\Table $table */ $table = $this->getVar('table'); $detailForm = $this->getVar('detailForm'); $historyPage = $this->getVar('historyPage'); diff --git a/fragments/yform/manager/page/list.php b/fragments/yform/manager/page/list.php index 6771c53c1..2b232e5f4 100644 --- a/fragments/yform/manager/page/list.php +++ b/fragments/yform/manager/page/list.php @@ -104,7 +104,7 @@ static function ($params) { } } else { [$table_name, $field_name] = explode('.', $params['params']['opener_field']); - $table = rex_yform_manager_table::get($table_name); + $table = \Yakamara\YForm\Manager\Table\Table::get($table_name); if ($table) { $fields = $table->getValueFields(['name' => $field_name]); if (isset($fields[$field_name])) { diff --git a/lib/List/List.php b/lib/List/List.php index 2c5ecb696..14e508519 100644 --- a/lib/List/List.php +++ b/lib/List/List.php @@ -16,8 +16,8 @@ use rex_url; use rex_url_provider_interface; use rex_view; -use rex_yform_manager_dataset; -use rex_yform_manager_query; +use Yakamara\YForm\Manager\Dataset; +use Yakamara\YForm\Manager\Query; use function count; use function in_array; @@ -32,9 +32,9 @@ class YList implements rex_url_provider_interface public const LIST_OPT_SORT_DIRECTION = 1; public const LIST_OPT_SORT = 0; - /** @var rex_yform_manager_query */ + /** @var Query */ private $query; - /** @var rex_yform_manager_dataset */ + /** @var Dataset */ private $currentItem; /** @var bool */ /** @phpstan-ignore-next-line */ @@ -99,12 +99,12 @@ class YList implements rex_url_provider_interface /** * Erstellt ein rex_list Objekt. * - * @param rex_yform_manager_query $query YForm Query Objekt + * @param Query $query YForm Query Objekt * @param int $rowsPerPage Anzahl der Elemente pro Zeile * @param string|null $listName Name der Liste * @param bool $debug */ - protected function __construct(rex_yform_manager_query $query, int $rowsPerPage = 30, $listName = null, $debug = false) + protected function __construct(Query $query, int $rowsPerPage = 30, $listName = null, $debug = false) { // --------- Validation if (!$listName) { @@ -190,7 +190,7 @@ protected function __construct(rex_yform_manager_query $query, int $rowsPerPage } /** - * @param rex_yform_manager_query $query + * @param Query $query * @param int $rowsPerPage * @param string|null $listName * @param bool $debug @@ -212,9 +212,8 @@ public function init() } // ---------------------- setters/getters - /** - * @return rex_yform_manager_query + * @return Query */ public function getQuery() { @@ -222,9 +221,9 @@ public function getQuery() } /** - * @return rex_yform_manager_query + * @return Query */ - public function setQuery(rex_yform_manager_query $query) + public function setQuery(Query $query) { $this->query = $query; return $this->query; diff --git a/lib/RexVar/TableData.php b/lib/RexVar/TableData.php index 74a7fe2a1..c26c7a7a7 100644 --- a/lib/RexVar/TableData.php +++ b/lib/RexVar/TableData.php @@ -48,7 +48,7 @@ protected function getOutput() return self::quote('[table param not defined]'); } - $table = rex_yform_manager_table::get($tableName); + $table = \Yakamara\YForm\Manager\Table\Table::get($tableName); if (!$table) { return self::quote('[table not in YForm?]'); } diff --git a/lib/manager/collection.php b/lib/manager/collection.php index 564188b71..e41ec6778 100644 --- a/lib/manager/collection.php +++ b/lib/manager/collection.php @@ -1,13 +1,30 @@ * - * @method rex_yform_manager_dataset offsetGet($offset) + * @method \Yakamara\YForm\Manager\Dataset offsetGet($offset) * @method list toArray() */ -class rex_yform_manager_collection extends \SplFixedArray + +namespace Yakamara\YForm\Manager; + +use Closure; +use InvalidArgumentException; +use rex_i18n; +use rex_yform_base_abstract; +use rex_yform_value_abstract; +use SplFixedArray; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\YForm; + +use function array_slice; +use function call_user_func; +use function count; +use function is_string; + +class Collection extends SplFixedArray { /** @var bool */ private static $debug = false; @@ -16,7 +33,7 @@ class rex_yform_manager_collection extends \SplFixedArray private $table; /** - * @param T[] $data + * @param array $data */ final public function __construct(string $table, array $data = []) { @@ -31,13 +48,13 @@ public function getTableName(): string return $this->table; } - public function getTable(): rex_yform_manager_table + public function getTable(): Table { - return rex_yform_manager_table::require($this->table); + return Table::require($this->table); } /** - * @param T[] $data + * @param array $data * @return $this */ public function setData(array $data): self @@ -64,17 +81,17 @@ public function isEmpty(): bool } /** - * @return null|T + * @return T|null */ - public function first(): ?rex_yform_manager_dataset + public function first(): ?Dataset { return $this->count() ? $this[0] : null; } /** - * @return null|T + * @return T|null */ - public function last(): ?rex_yform_manager_dataset + public function last(): ?Dataset { return $this->count() ? $this[$this->count() - 1] : null; } @@ -162,7 +179,7 @@ public function chunk(int $size): array } /** - * @return T[] + * @return array */ public function toKeyIndex(string $key = 'id'): array { @@ -185,7 +202,7 @@ public function toKeyValue(string $key, string $value): array } /** - * @param string|string[] $keys + * @param string|array $keys */ public function groupBy($keys, ?string $value = null): array { @@ -195,7 +212,7 @@ public function groupBy($keys, ?string $value = null): array $keys = array_reverse($keys); } - $setValue = static function (&$array, array $keys, rex_yform_manager_dataset $dataset) use (&$setValue, $value) { + $setValue = static function (&$array, array $keys, Dataset $dataset) use (&$setValue, $value) { if (!$keys) { $array[] = $value ? $dataset->getValue($value) : $dataset; return; @@ -221,12 +238,12 @@ public function groupBy($keys, ?string $value = null): array /** * @param string|Closure $value Field name or callback * @param string $separator Separator between elements - * @param null|string $and Optional separator between last two elements + * @param string|null $and Optional separator between last two elements */ public function implode($value, string $separator, ?string $and = null): string { if (!$value instanceof Closure) { - $value = static function (rex_yform_manager_dataset $dataset) use ($value) { + $value = static function (Dataset $dataset) use ($value) { return $dataset->getValue($value); }; } @@ -307,7 +324,7 @@ public function setValue(string $key, $value): self } /** - * @return self A new collection containing all datasets related to this collection by $key relation + * @return Collection A new collection containing all datasets related to this collection by $key relation */ public function populateRelation(string $key) { @@ -321,7 +338,7 @@ public function populateRelation(string $key) return new self($relation['table']); } - $query = rex_yform_manager_dataset::query($relation['table']); + $query = Dataset::query($relation['table']); if (0 == $relation['type'] || 2 == $relation['type']) { $query->where('id', $this->getValues($key)); @@ -428,9 +445,9 @@ public function delete(): bool return $success; } - public function getForm(): \Yakamara\YForm\YForm + public function getForm(): YForm { - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); $yform->setDebug(self::$debug); $yform->objparams['form_name'] = 'yform-manager-multi-edit'; $yform->objparams['form_class'] .= ' yform-manager-multi-edit'; @@ -529,9 +546,9 @@ public function getForm(): \Yakamara\YForm\YForm } /** - * @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted + * @param callable(\Yakamara\YForm\YForm):void|null $afterFieldsExecuted */ - public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string + public function executeForm(YForm $yform, ?callable $afterFieldsExecuted = null): string { $yform->executeFields(); diff --git a/lib/manager/dataset.php b/lib/manager/dataset.php index 13dbb9871..fae2887ec 100644 --- a/lib/manager/dataset.php +++ b/lib/manager/dataset.php @@ -1,6 +1,27 @@ > */ + /** @var array> */ private static array $tableToModel = []; - /** @var array, string> */ + /** @var array, string> */ private static array $modelToTable = []; private string $table; @@ -28,10 +49,10 @@ class rex_yform_manager_dataset private bool $dataLoaded = false; - /** @var array */ + /** @var array */ private array $relatedCollections = []; - /** @var string[] */ + /** @var array */ private array $messages = []; /** @var bool */ @@ -59,7 +80,7 @@ public static function create(?string $table = null): self return $dataset; } - /** @return null|static */ + /** @return static|null */ public static function get(int $id, ?string $table = null): ?self { if ($id <= 0) { @@ -122,14 +143,14 @@ public static function getRaw(int $id, ?string $table = null): self } /** - * @return rex_yform_manager_collection + * @return \Yakamara\YForm\Manager\Collection */ - public static function getAll(?string $table = null): rex_yform_manager_collection + public static function getAll(?string $table = null): Collection { return static::query($table)->find(); } - public static function table(): rex_yform_manager_table + public static function table(): Table { $class = static::class; @@ -137,19 +158,19 @@ public static function table(): rex_yform_manager_table throw new RuntimeException(sprintf('Method "%s()" is only callable for registered model classes.', __METHOD__)); } - return rex_yform_manager_table::require(self::$modelToTable[$class]); + return Table::require(self::$modelToTable[$class]); } /** - * @return rex_yform_manager_query + * @return \Yakamara\YForm\Manager\Query */ - public static function query(?string $table = null): rex_yform_manager_query + public static function query(?string $table = null): Query { - return rex_yform_manager_query::get($table ?: static::modelToTable()); + return Query::get($table ?: static::modelToTable()); } /** - * @return null|static + * @return static|null */ public static function queryOne(string $query, array $params = [], ?string $table = null): ?self { @@ -179,9 +200,9 @@ public static function queryOne(string $query, array $params = [], ?string $tabl } /** - * @return rex_yform_manager_collection + * @return \Yakamara\YForm\Manager\Collection */ - public static function queryCollection(string $query, array $params = [], ?string $table = null): rex_yform_manager_collection + public static function queryCollection(string $query, array $params = [], ?string $table = null): Collection { $table = $table ?: static::modelToTable(); @@ -201,11 +222,11 @@ public static function queryCollection(string $query, array $params = [], ?strin $datasets[] = static::fromSqlData($row, $table); } - return new rex_yform_manager_collection($table, $datasets); + return new Collection($table, $datasets); } /** - * @param class-string $modelClass + * @param class-string<\Yakamara\YForm\Manager\Dataset> $modelClass */ public static function setModelClass(string $table, string $modelClass): void { @@ -214,7 +235,7 @@ public static function setModelClass(string $table, string $modelClass): void } /** - * @return null|class-string + * @return class-string|null */ public static function getModelClass(string $table): ?string { @@ -226,9 +247,9 @@ public function getTableName(): string return $this->table; } - public function getTable(): rex_yform_manager_table + public function getTable(): Table { - return rex_yform_manager_table::require($this->table); + return Table::require($this->table); } public function getId(): int @@ -343,7 +364,7 @@ public function getRelatedDataset(string $key): ?self return $class::get($id, $relation['table']); } - public function getRelatedCollection(string $key): rex_yform_manager_collection + public function getRelatedCollection(string $key): Collection { if (isset($this->relatedCollections[$key])) { return $this->relatedCollections[$key]; @@ -359,14 +380,14 @@ public function getRelatedCollection(string $key): rex_yform_manager_collection * * @internal */ - public function setRelatedCollection(string $key, rex_yform_manager_collection $collection): self + public function setRelatedCollection(string $key, Collection $collection): self { $this->relatedCollections[$key] = $collection; return $this; } - public function getRelatedQuery(string $key): rex_yform_manager_query + public function getRelatedQuery(string $key): Query { $relation = $this->getTable()->getRelation($key); @@ -446,7 +467,7 @@ public function save(): bool } /** - * @return string[] + * @return array */ public function getMessages(): array { @@ -485,14 +506,14 @@ public function delete(): bool /** * Fields of yform Definitions. * - * @return rex_yform_manager_field[] + * @return array<\Yakamara\YForm\Manager\Field> */ public function getFields(array $filter = []): array { return $this->getTable()->getFields($filter); } - public function getForm(): \Yakamara\YForm\YForm + public function getForm(): YForm { $yform = $this->createForm(); $this->setFormMainId($yform); @@ -501,18 +522,18 @@ public function getForm(): \Yakamara\YForm\YForm } /** - * @param null|callable(\Yakamara\YForm\YForm):void $afterFieldsExecuted + * @param callable(\Yakamara\YForm\YForm):void|null $afterFieldsExecuted */ - public function executeForm(\Yakamara\YForm\YForm $yform, ?callable $afterFieldsExecuted = null): string + public function executeForm(YForm $yform, ?callable $afterFieldsExecuted = null): string { $exists = $this->exists(); $oldData = $this->getData(); if ($exists) { - /** @var \Yakamara\YForm\YForm $yform */ + /** @var YForm $yform */ $yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_UPDATE', $yform, ['table' => $this->getTable(), 'data_id' => $this->id, 'data' => $this])); } else { - /** @var \Yakamara\YForm\YForm $yform */ + /** @var YForm $yform */ $yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_ADD', $yform, ['table' => $this->getTable(), 'data' => $this])); } @@ -672,7 +693,7 @@ public function __set(string $key, $value): void $this->setValue($key, $value); } - private function getInternalForm(): \Yakamara\YForm\YForm + private function getInternalForm(): YForm { $dummy = new static($this->table, 0); @@ -685,9 +706,9 @@ private function getInternalForm(): \Yakamara\YForm\YForm return $yform; } - private function createForm(): \Yakamara\YForm\YForm + private function createForm(): YForm { - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); $fields = $this->getFields(); $yform->setDebug(self::$debug); @@ -721,7 +742,7 @@ private function createForm(): \Yakamara\YForm\YForm return $yform; } - private function setFormMainId(\Yakamara\YForm\YForm $yform): void + private function setFormMainId(YForm $yform): void { if ($this->exists()) { $where = 'id = ' . (int) $this->id; @@ -733,7 +754,7 @@ private function setFormMainId(\Yakamara\YForm\YForm $yform): void } /** - * @return class-string + * @return class-string<\Yakamara\YForm\Manager\Dataset> */ private static function tableToModel(string $table): string { diff --git a/lib/manager/field.php b/lib/manager/field.php index 5fc6a2584..4b81efbf1 100644 --- a/lib/manager/field.php +++ b/lib/manager/field.php @@ -1,6 +1,19 @@ www.yakamara.de */ -if (!function_exists('rex_yform_manager_checkField')) { - function rex_yform_manager_checkField($l, $v, $p) - { - return rex_yform_manager::checkField($l, $v, $p); - } -} - -class rex_yform_manager +namespace Yakamara\YForm\Manager; + +use Exception; +use rex; +use rex_context; +use rex_csrf_token; +use rex_extension; +use rex_extension_point; +use rex_fragment; +use rex_i18n; +use rex_list; +use rex_path; +use rex_response; +use rex_sql; +use rex_url; +use rex_view; +use rex_yform_base_abstract; +use rex_yform_value_abstract; +use rex_yform_value_be_manager_relation; +use rex_yform_value_submit; +use Throwable; +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\Manager\Table\Authorization; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\YForm; + +class Manager { - /** @var rex_yform_manager_table|null */ + /** @var Table|null */ public $table; public $linkvars = []; public $type = ''; @@ -38,7 +57,7 @@ public function setDataPageFunctions($f = ['add', 'delete', 'search', 'export', public function hasDataPageFunction($f) { - return in_array($f, $this->dataPageFunctions) ? true : false; + return \in_array($f, $this->dataPageFunctions) ? true : false; } // ----- Seitenausgabe @@ -68,14 +87,14 @@ public function getDataPage() $rex_yform_filter = rex_request('rex_yform_filter', 'array'); foreach ($rex_yform_filter as $k => $v) { - if (!in_array($k, $field_names)) { + if (!\in_array($k, $field_names)) { unset($rex_yform_filter[$k]); } } $rex_yform_set = rex_request('rex_yform_set', 'array'); foreach ($rex_yform_set as $k => $v) { - if (!in_array($k, $field_names)) { + if (!\in_array($k, $field_names)) { unset($rex_yform_set[$k]); } } @@ -108,7 +127,7 @@ public function getDataPage() 'table' => $this->table, ])); - $searchObject = new rex_yform_manager_search($this->table); + $searchObject = new Search($this->table); $searchObject ->setSearchLinkVars($this->getLinkVars()) ->setSearchLinkVars($rex_yform_list) @@ -167,7 +186,7 @@ public function getDataPage() $data_query = $this->getDataListQuery($data_query, array_merge($rex_yform_filter, $rex_yform_set), $searchObject); $data_collection = $data_query->find(); - if (1 == count($data_collection)) { + if (1 == \count($data_collection)) { $data_id = $data_collection[0]->getId(); } else { $data_id = null; @@ -178,7 +197,7 @@ public function getDataPage() $mainMessages = []; if ($this->table->isGranted('EDIT', rex::getUser())) { - $func = !in_array($func, ['delete', 'dataset_delete', 'truncate_table', 'add', 'edit', 'clone', 'import', 'history', 'dataset_export', 'collection_edit']) ? '' : $func; + $func = !\in_array($func, ['delete', 'dataset_delete', 'truncate_table', 'add', 'edit', 'clone', 'import', 'history', 'dataset_export', 'collection_edit']) ? '' : $func; } else { $func = ('edit' != $func) ? '' : 'edit'; } @@ -202,7 +221,7 @@ public function getDataPage() ]; ob_start(); - include rex_path::plugin('yform', 'manager', 'pages/data_import.php'); + include rex_path::addon('yform', 'pages/manager.data_import.php'); $dataImport = ob_get_contents(); ob_end_clean(); @@ -218,7 +237,7 @@ public function getDataPage() ]; ob_start(); - include rex_path::plugin('yform', 'manager', 'pages/data_history.php'); + include rex_path::addon('yform', 'pages/manager.data_history.php'); $dataHistory = ob_get_contents(); ob_end_clean(); @@ -284,8 +303,8 @@ public function getDataPage() $yform->setObjectparams('form_name', 'data_edit-' . $this->table->getTableName()); } - $yform->canEdit(rex_yform_manager_table_authorization::onAttribute('EDIT', $this->table, rex::getUser())); - $yform->canView(rex_yform_manager_table_authorization::onAttribute('VIEW', $this->table, rex::getUser())); + $yform->canEdit(Authorization::onAttribute('EDIT', $this->table, rex::getUser())); + $yform->canView(Authorization::onAttribute('VIEW', $this->table, rex::getUser())); $yform->setHiddenFields($this->getLinkVars()); $yform->setHiddenFields($rex_yform_list); @@ -377,7 +396,7 @@ public function getDataPage() $sql_db = rex_sql::factory(); $form = ''; $sql_db->transactional(static function () use (&$form, &$yform, $data, $func) { - $afterFieldsExecuted = static function (\Yakamara\YForm\YForm $yform) { + $afterFieldsExecuted = static function (YForm $yform) { /** @var rex_yform_value_abstract $valueObject */ foreach ($yform->objparams['values'] as $valueObject) { if ('submit' == $valueObject->getName()) { @@ -390,7 +409,7 @@ public function getDataPage() }; if ('clone' == $func) { - $afterFieldsExecuted = static function (\Yakamara\YForm\YForm $yform) use ($afterFieldsExecuted) { + $afterFieldsExecuted = static function (YForm $yform) use ($afterFieldsExecuted) { $yform->objparams['form_hiddenfields']['func'] = 'add'; unset($yform->objparams['form_hiddenfields']['data_id']); @@ -415,7 +434,7 @@ public function getDataPage() } } - if (is_callable($afterFieldsExecuted)) { + if (\is_callable($afterFieldsExecuted)) { $afterFieldsExecuted($yform); } }; @@ -607,20 +626,20 @@ public function getDataPage() ), ); - if (count($dataset_links) > 0) { + if (\count($dataset_links) > 0) { $fragment = new rex_fragment(); $fragment->setVar('size', 'xs', false); $fragment->setVar('buttons', $dataset_links, false); $panel_options[] = '' . rex_i18n::msg('yform_dataset') . ' ' . $fragment->parse('core/buttons/button_group.php'); } - if (count($table_links) > 0) { + if (\count($table_links) > 0) { $fragment = new rex_fragment(); $fragment->setVar('size', 'xs', false); $fragment->setVar('buttons', $table_links, false); $panel_options[] = '' . rex_i18n::msg('yform_table') . ' ' . $fragment->parse('core/buttons/button_group.php'); } - if (count($field_links) > 0) { + if (\count($field_links) > 0) { $fragment = new rex_fragment(); $fragment->setVar('size', 'xs', false); $fragment->setVar('buttons', $field_links, false); @@ -696,14 +715,14 @@ public function getDataPage() $fragment->setVar( 'hasDataPageFunctions', static function ($fnc) use ($data_page_function) { - return in_array($fnc, $data_page_function) ? true : false; + return \in_array($fnc, $data_page_function) ? true : false; }, false, ); $filterMessages = []; if ($rex_yform_filter) { - $getFilter = static function (rex_yform_manager_field $field, $value, $table) { + $getFilter = static function (Field $field, $value, $table) { $class = 'rex_yform_value_' . $field->getTypeName(); $listValues = ''; try { @@ -737,14 +756,14 @@ static function ($fnc) use ($data_page_function) { return $this->table->parseLayout($mainFragment); } - public function getDataListQuery(rex_yform_manager_query $query, array $rex_filter = [], ?rex_yform_manager_search $searchObject = null) + public function getDataListQuery(Query $query, array $rex_filter = [], ?Search $searchObject = null) { $fields = $query->getTable()->getFields(); foreach ($query->getTable()->getFields() as $field) { - if (array_key_exists($field->getName(), $rex_filter) && 'value' == $field->getType()) { // && $field->isSearchable() + if (\array_key_exists($field->getName(), $rex_filter) && 'value' == $field->getType()) { // && $field->isSearchable() if (method_exists('rex_yform_value_' . $field->getTypeName(), 'getSearchFilter')) { - $query = call_user_func( + $query = \call_user_func( 'rex_yform_value_' . $field->getTypeName() . '::getSearchFilter', [ 'field' => $field, @@ -753,8 +772,8 @@ public function getDataListQuery(rex_yform_manager_query $query, array $rex_filt 'query' => $query, ], ); - if ('rex_yform_manager_query' != $query::class) { - throw new Exception('getSearchFilter in rex_yform_value_' . $field->getTypeName() . ' does not return a rex_yform_manager_query'); + if (Query::class != $query::class) { + throw new Exception('getSearchFilter in rex_yform_value_' . $field->getTypeName() . ' does not return a Yakamara\YForm\Manager\Query object'); } } } @@ -765,17 +784,13 @@ public function getDataListQuery(rex_yform_manager_query $query, array $rex_filt return rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_LIST_QUERY', $query, ['filter' => $rex_filter])); } - // ---------------------------------- table functions - public function setTable(rex_yform_manager_table $table) + public function setTable(Table $table) { $this->table = $table; } - // ---------------------------------- field functions public function getFieldPage() { - // ********************************************* FIELD ADD/EDIT/LIST - $func = rex_request('func', 'string', 'list'); $type_id = rex_request('type_id', 'string'); $type_name = rex_request('type_name', 'string'); @@ -795,7 +810,7 @@ public function getFieldPage() $_csrf_key = $this->table->getCSRFKey(); - if ('' != $func && in_array($func, ['delete', 'updatetablewithdelete', 'updatetable'])) { + if ('' != $func && \in_array($func, ['delete', 'updatetablewithdelete', 'updatetable'])) { if (!rex_csrf_token::factory($_csrf_key)->isValid()) { echo rex_view::error(rex_i18n::msg('csrf_token_invalid')); $func = 'list'; @@ -804,7 +819,7 @@ public function getFieldPage() $mfields = $table->getMissingFields(); $type_real_field = rex_request('type_real_field', 'string'); - if ('' != $type_real_field && !array_key_exists($type_real_field, $mfields)) { + if ('' != $type_real_field && !\array_key_exists($type_real_field, $mfields)) { $type_real_field = ''; } @@ -824,7 +839,7 @@ public function getFieldPage() echo $fragment->parse('core/page/section.php'); } - $types = \Yakamara\YForm\YForm::getTypeArray(); + $types = YForm::getTypeArray(); if ('choosenadd' == $func) { $link = 'index.php?' . $link_vars . '&table_name=' . $table->getTableName() . '&func=add&'; @@ -834,7 +849,7 @@ public function getFieldPage() if (!$table->hasId()) { $content[] = rex_i18n::msg('yform_id_is_missing') . '' . rex_i18n::msg('yform_id_missing_info'); } else { - if ('' == $type_real_field && count($mfields) > 0) { + if ('' == $type_real_field && \count($mfields) > 0) { $tmp = ''; $d = 0; foreach ($mfields as $k => $v) { @@ -911,9 +926,9 @@ public function getFieldPage() } if (('add' == $func || 'edit' == $func) && isset($types[$type_id][$type_name])) { - $field = new rex_yform_manager_field(['type_id' => $type_id, 'type_name' => $type_name]); + $field = new Field(['type_id' => $type_id, 'type_name' => $type_name]); - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); $yform->setDebug(false); foreach ($this->getLinkVars() as $k => $v) { @@ -985,7 +1000,7 @@ public function getFieldPage() break; case 'table': - $_tables = rex_yform_manager_table::getAll(); + $_tables = Table::getAll(); $_options = []; if (isset($v['empty_option']) && $v['empty_option']) { $_options[0] = '–='; @@ -1038,24 +1053,24 @@ public function getFieldPage() } } - if (isset($types[$type_id][$type_name]['validates']) && is_array($types[$type_id][$type_name]['validates'])) { + if (isset($types[$type_id][$type_name]['validates']) && \is_array($types[$type_id][$type_name]['validates'])) { foreach ($types[$type_id][$type_name]['validates'] as $v) { $yform->setValidateField(key($v), current($v)); } } $yform->setActionField('showtext', ['', '

' . rex_i18n::msg('yform_thankyouforentry') . '

']); - $yform->setObjectparams('main_table', rex_yform_manager_field::table()); + $yform->setObjectparams('main_table', Field::table()); switch ($func) { case 'edit': $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_field_update')); $yform->setHiddenField('field_id', $field_id); - $yform->setActionField('manage_db', [rex_yform_manager_field::table(), "id=$field_id"]); + $yform->setActionField('manage_db', [Field::table(), "id=$field_id"]); $yform->setObjectparams('main_id', $field_id); $yform->setObjectparams('main_where', "id=$field_id"); $sql = rex_sql::factory(); - $sql->setQuery('SELECT * FROM ' . rex_yform_manager_field::table() . " WHERE id=$field_id"); + $sql->setQuery('SELECT * FROM ' . Field::table() . " WHERE id=$field_id"); foreach ($selectFields as $alias => $s_field) { if ($alias != $s_field) { if ((!$sql->hasValue($s_field) || null === $sql->getValue($s_field) || '' === $sql->getValue($s_field)) && $sql->hasValue($alias)) { @@ -1070,7 +1085,7 @@ public function getFieldPage() case 'add': default: $yform->setObjectparams('submit_btn_label', rex_i18n::msg('yform_field_add')); - $yform->setActionField('manage_db', [rex_yform_manager_field::table()]); + $yform->setActionField('manage_db', [Field::table()]); break; } @@ -1117,12 +1132,12 @@ public function getFieldPage() } else { switch ($func) { case 'edit': - rex_yform_manager_table_api::generateTableAndFields($table); + Api::generateTableAndFields($table); echo rex_view::success(rex_i18n::msg('yform_thankyouforupdate')); break; case 'add': default: - rex_yform_manager_table_api::generateTableAndFields($table); + Api::generateTableAndFields($table); echo rex_view::success(rex_i18n::msg('yform_thankyouforentry')); break; } @@ -1136,15 +1151,15 @@ public function getFieldPage() } else { $sf = rex_sql::factory(); $sf->setDebug(self::$debug); - $sf->setQuery('select * from ' . rex_yform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id); + $sf->setQuery('select * from ' . Field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id); $sfa = $sf->getArray(); - if (1 == count($sfa)) { - $query = 'delete from ' . rex_yform_manager_field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id; + if (1 == \count($sfa)) { + $query = 'delete from ' . Field::table() . ' where table_name="' . $table->getTableName() . '" and id=' . $field_id; $delsql = rex_sql::factory(); $delsql->setDebug(self::$debug); $delsql->setQuery($query); echo rex_view::success(rex_i18n::msg('yform_tablefielddeleted')); - rex_yform_manager_table_api::generateTableAndFields($table); + Api::generateTableAndFields($table); } else { echo rex_view::warning(rex_i18n::msg('yform_tablefieldnotfound')); } @@ -1154,13 +1169,13 @@ public function getFieldPage() // ********************************************* CREATE/UPDATE FIELDS if ('updatetable' == $func) { - rex_yform_manager_table_api::generateTableAndFields($table); + Api::generateTableAndFields($table); echo rex_view::info(rex_i18n::msg('yform_tablesupdated')); $func = 'list'; } if ('updatetablewithdelete' == $func) { - rex_yform_manager_table_api::generateTableAndFields($table, true); + Api::generateTableAndFields($table, true); echo rex_view::info(rex_i18n::msg('yform_tablesupdated')); $func = 'list'; } @@ -1332,7 +1347,7 @@ public function getFieldPage() ], false); $panel_options .= '' . rex_i18n::msg('yform_table') . ' ' . $fragment->parse('core/buttons/button_group.php'); - $sql = 'select id, prio, type_id, type_name, name, label from ' . rex_yform_manager_field::table() . ' where table_name="' . $table->getTableName() . '"'; + $sql = 'select id, prio, type_id, type_name, name, label from ' . Field::table() . ' where table_name="' . $table->getTableName() . '"'; $list = rex_list::factory($sql, rowsPerPage: 200, defaultSort: [ 'prio' => 'asc', ]); @@ -1399,7 +1414,7 @@ public function getFieldPage() private function getFieldName($key, $type) { - if (is_int($key)) { + if (\is_int($key)) { ++$key; if (1 === $key) { return 'name'; @@ -1410,7 +1425,7 @@ private function getFieldName($key, $type) return 'f' . $key; } - if (in_array($key, self::$reservedFieldColumns)) { + if (\in_array($key, self::$reservedFieldColumns)) { $key = 'field_' . $key; } return $key; @@ -1422,7 +1437,7 @@ private function getFieldName($key, $type) public static function checkField($l, $v, $p) { - $q = 'select * from ' . rex_yform_manager_field::table() . ' where table_name="' . $p['table_name'] . '" and type_id="value" and ' . $l . '="' . $v . '" LIMIT 1'; + $q = 'select * from ' . Field::table() . ' where table_name="' . $p['table_name'] . '" and type_id="value" and ' . $l . '="' . $v . '" LIMIT 1'; $c = rex_sql::factory(); $c->setDebug(self::$debug); $c->setQuery($q); @@ -1442,8 +1457,8 @@ public function createTable($mifix, $data_table, $params = [], $debug = false) // Tabellenset in die Basics einbauen, wenn noch nicht vorhanden $c = rex_sql::factory(); $c->setDebug($debug); - $c->setQuery('DELETE FROM ' . rex_yform_manager_table::table() . ' where table_name="' . $data_table . '"'); - $c->setTable(rex_yform_manager_table::table()); + $c->setQuery('DELETE FROM ' . Table::table() . ' where table_name="' . $data_table . '"'); + $c->setTable(Table::table()); $params['table_name'] = $data_table; if (!isset($params['status'])) { @@ -1481,7 +1496,7 @@ public function createTable($mifix, $data_table, $params = [], $debug = false) public static function url(string $tableName, int $id = 0, array $params = []): string { - $table = rex_yform_manager_table::require($tableName); + $table = Table::require($tableName); $params['table_name'] = $table->getTableName(); diff --git a/lib/manager/query.php b/lib/manager/query.php index 466c895ef..96f442016 100644 --- a/lib/manager/query.php +++ b/lib/manager/query.php @@ -1,10 +1,27 @@ */ -class rex_yform_manager_query implements IteratorAggregate, Countable + +namespace Yakamara\YForm\Manager; + +use Countable; +use DateTimeInterface; +use InvalidArgumentException; +use IteratorAggregate; +use rex_pager; +use rex_sql; +use Yakamara\YForm\Manager\Table\Table; + +use function call_user_func; +use function in_array; +use function is_array; +use function is_bool; +use function is_object; + +class Query implements IteratorAggregate, Countable { private const PARAM_WHERE = 'where'; private const PARAM_HAVING = 'having'; @@ -71,9 +88,9 @@ public function getTableName(): string return $this->table; } - public function getTable(): rex_yform_manager_table + public function getTable(): Table { - return rex_yform_manager_table::require($this->table); + return Table::require($this->table); } /** @@ -350,7 +367,7 @@ public function whereNotBetween(string $column, $from, $to): self * Where the comma separated list column contains the given value or any of the given values. * * @param string $column Column with comma separated list - * @param string|int|int[] $value Single value (string or int) or array of values (ints only) + * @param string|int|array $value Single value (string or int) or array of values (ints only) * @return $this */ public function whereListContains(string $column, $value): self @@ -373,7 +390,7 @@ public function whereRaw(string $where, array $params = []): self } /** - * @param array|callable(self):void $nested + * @param array|callable(\Yakamara\YForm\Manager\Query):void $nested * @param 'AND'|'OR' $operator * @return $this */ @@ -497,7 +514,7 @@ public function havingNotBetween(string $column, $from, $to): self * Where the comma separated list column contains the given value or any of the given values. * * @param string $column Column with comma separated list - * @param string|int|int[] $value Single value (string or int) or array of values (ints only) + * @param string|int|array $value Single value (string or int) or array of values (ints only) * @return $this */ public function havingListContains(string $column, $value): self @@ -656,26 +673,26 @@ public function getParams(): array } /** - * @return rex_yform_manager_collection + * @return \Yakamara\YForm\Manager\Collection */ - public function getIterator(): rex_yform_manager_collection + public function getIterator(): Collection { return $this->find(); } /** - * @return rex_yform_manager_collection + * @return \Yakamara\YForm\Manager\Collection */ - public function find(): rex_yform_manager_collection + public function find(): Collection { - /** @var rex_yform_manager_collection */ - return rex_yform_manager_dataset::queryCollection($this->getQuery(), $this->getParams(), $this->table); + /** @var Collection */ + return Dataset::queryCollection($this->getQuery(), $this->getParams(), $this->table); } /** - * @return rex_yform_manager_collection + * @return \Yakamara\YForm\Manager\Collection */ - public function paginate(rex_pager $pager): rex_yform_manager_collection + public function paginate(rex_pager $pager): Collection { $pager->setRowCount($this->count()); $this->limit($pager->getCursor(), $pager->getRowsPerPage()); @@ -686,28 +703,28 @@ public function paginate(rex_pager $pager): rex_yform_manager_collection /** * @param list $ids * - * @return rex_yform_manager_collection + * @return \Yakamara\YForm\Manager\Collection */ - public function findIds(array $ids): rex_yform_manager_collection + public function findIds(array $ids): Collection { return $this->where($this->getTableAlias() . '.id', $ids)->find(); } /** - * @return null|T + * @return T|null */ - public function findOne(): ?rex_yform_manager_dataset + public function findOne(): ?Dataset { $this->limit(1); - /** @var null|T */ - return rex_yform_manager_dataset::queryOne($this->getQuery(), $this->getParams(), $this->table); + /** @var T|null */ + return Dataset::queryOne($this->getQuery(), $this->getParams(), $this->table); } /** - * @return null|T + * @return T|null */ - public function findId(int $id): ?rex_yform_manager_dataset + public function findId(int $id): ?Dataset { return $this->where($this->getTableAlias() . '.id', $id)->resetOrderBy()->findOne(); } @@ -872,7 +889,7 @@ private function buildCondition(string $type, string $column, mixed $value, ?str /** * @param self::PARAM_* $type * @param string $column Column with comma separated list - * @param string|int|int[] $value Single value (string or int) or array of values (ints only) + * @param string|int|array $value Single value (string or int) or array of values (ints only) */ private function buildListContains(string $type, string $column, $value): string { diff --git a/lib/manager/search.php b/lib/manager/search.php index ae639adf2..db52f8bfc 100644 --- a/lib/manager/search.php +++ b/lib/manager/search.php @@ -1,19 +1,29 @@ table = $table; - $id_field = [new rex_yform_manager_field([ + $id_field = [new Field([ 'id' => 0, 'table_name' => $this->table->getTableName(), 'type_id' => 'value', @@ -46,9 +56,9 @@ public function setScriptPath(string $scriptpath): self return $this; } - public function getYForm(): \Yakamara\YForm\YForm + public function getYForm(): YForm { - $yform = new \Yakamara\YForm\YForm(); + $yform = new YForm(); $yform->setObjectparams('form_name', 'rex_yform_searchvars-' . $this->table->getTableName()); $yform->setObjectparams('form_showformafterupdate', 1); $yform->setObjectparams('csrf_protection', false); @@ -132,8 +142,8 @@ public function getQueryFilter($query) 'query' => $query, ], ); - if ('rex_yform_manager_query' != $query::class) { - throw new Exception('getSearchFilter in rex_yform_value_' . $field->getTypeName() . ' does not return a rex_yform_manager_query'); + if (Query::class != $query::class) { + throw new Exception('getSearchFilter in rex_yform_value_' . $field->getTypeName() . ' does not return a Yakamara\YForm\Manager\Query'); } } } diff --git a/lib/manager/table.php b/lib/manager/table/Table.php similarity index 89% rename from lib/manager/table.php rename to lib/manager/table/Table.php index c5398d5d8..e8f6a424e 100644 --- a/lib/manager/table.php +++ b/lib/manager/table/Table.php @@ -1,13 +1,26 @@ www.yakamara.de - */ - -final class rex_yform_manager_table implements ArrayAccess +namespace Yakamara\YForm\Manager\Table; + +use ArrayAccess; +use Exception; +use rex; +use rex_exception; +use rex_file; +use rex_fragment; +use rex_i18n; +use rex_path; +use rex_sql; +use rex_user; +use RuntimeException; +use Yakamara\YForm\Manager\Dataset; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Query; + +use function array_key_exists; +use function count; + +final class Table implements ArrayAccess { public static array $tableLayouts = []; public static string $defaultTableLayout = 'yform/manager/page/layout.php'; @@ -15,15 +28,15 @@ final class rex_yform_manager_table implements ArrayAccess protected $values = []; protected $columns = []; - /** @var array */ + /** @var array<\Yakamara\YForm\Manager\Field> */ protected $fields = []; - /** @var array */ + /** @var array<\Yakamara\YForm\Manager\Field> */ protected $relations; protected static bool $debug = false; - /** @var array */ + /** @var array<\Yakamara\YForm\Manager\Table\Table> */ protected static $tables = []; protected static bool $loadedAllTables = false; @@ -56,7 +69,7 @@ public function getTableLayout(): string /** * @param string $tableName * - * @return rex_yform_manager_table|null + * @return Table|null */ public static function get($tableName) { @@ -86,7 +99,7 @@ public static function require(string $tableName): self } /** - * @return rex_yform_manager_table|null + * @return Table|null */ public static function getById(int $tableID) { @@ -102,7 +115,7 @@ public static function getById(int $tableID) } /** - * @return array + * @return array<\Yakamara\YForm\Manager\Table\Table> */ public static function getAll() { @@ -249,14 +262,14 @@ public function getCustomIcon(): ?string /** * Fields of yform Definitions. * - * @return array + * @return array<\Yakamara\YForm\Manager\Field> */ public function getFields(array $filter = []) { if (0 == count($this->fields)) { foreach ($this->fieldValues as $field) { try { - $this->fields[] = new rex_yform_manager_field($field); + $this->fields[] = new Field($field); } catch (Exception $e) { // ignore missing fields } @@ -279,7 +292,7 @@ public function getFields(array $filter = []) } /** - * @return array + * @return array<\Yakamara\YForm\Manager\Field> */ public function getValueFields(array $filter = []) { @@ -305,7 +318,7 @@ public function getValueField($name) } /** - * @return array + * @return array<\Yakamara\YForm\Manager\Field> */ public function getRelations() { @@ -319,7 +332,7 @@ public function getRelations() /** * @param string $table * - * @return array + * @return array<\Yakamara\YForm\Manager\Field> */ public function getRelationsTo($table) { @@ -327,7 +340,7 @@ public function getRelationsTo($table) } /** - * @return rex_yform_manager_field|null + * @return Field|null */ public function getRelation(string $column) { @@ -414,7 +427,7 @@ public static function getMaximumTablePrio() public function getMaximumPrio() { - $sql = 'select max(prio) as prio from ' . rex_yform_manager_field::table() . ' where table_name="' . $this->getTableName() . '"'; + $sql = 'select max(prio) as prio from ' . Field::table() . ' where table_name="' . $this->getTableName() . '"'; $gf = rex_sql::factory(); if (self::$debug) { $gf->setDebug(); @@ -424,39 +437,39 @@ public function getMaximumPrio() } /** - * @return rex_yform_manager_dataset + * @return Dataset */ public function createDataset() { - return rex_yform_manager_dataset::create($this->getTableName()); + return Dataset::create($this->getTableName()); } /** * @param int $id * - * @return rex_yform_manager_dataset|null + * @return Dataset|null */ public function getDataset($id) { - return rex_yform_manager_dataset::get($id, $this->getTableName()); + return Dataset::get($id, $this->getTableName()); } /** * @param int $id * - * @return rex_yform_manager_dataset + * @return Dataset */ public function getRawDataset($id) { - return rex_yform_manager_dataset::getRaw($id, $this->getTableName()); + return Dataset::getRaw($id, $this->getTableName()); } /** - * @return rex_yform_manager_query + * @return Query */ public function query() { - return new rex_yform_manager_query($this->getTableName()); + return new Query($this->getTableName()); } // ------------------------------------------- Array Access @@ -535,7 +548,7 @@ private static function getCache(): mixed self::$cache[$tableName]['fields'] = []; } - $fields = $sql->getArray('select * from ' . rex_yform_manager_field::table() . ' order by prio'); + $fields = $sql->getArray('select * from ' . Field::table() . ' order by prio'); foreach ($fields as $field) { if (isset(self::$cache[(string) $field['table_name']])) { self::$cache[(string) $field['table_name']]['fields'][] = $field; @@ -559,12 +572,12 @@ private static function getCache(): mixed private static function cachePath(): string { - return rex_path::pluginCache('yform', 'manager', 'tables.cache'); + return rex_path::addonCache('yform', 'manager', 'tables.cache'); } public function isGranted(string $type, rex_user $user): bool { - return rex_yform_manager_table_authorization::onAttribute($type, $this, $user); + return Authorization::onAttribute($type, $this, $user); } public function getCSRFKey(): string diff --git a/lib/manager/table/api.php b/lib/manager/table/api.php index 44a1a1cc9..5940330ce 100644 --- a/lib/manager/table/api.php +++ b/lib/manager/table/api.php @@ -1,6 +1,22 @@ */ public static array $table_fields = ['status', 'name', 'description', 'table_icon', 'list_amount', 'list_sortfield', 'list_sortorder', 'prio', 'search', 'hidden', 'export', 'import', 'schema_overwrite']; @@ -12,20 +28,20 @@ class rex_yform_manager_table_api * @param array $table_fields * @throws rex_sql_exception */ - public static function setTable(array $table, array $table_fields = []): ?rex_yform_manager_table + public static function setTable(array $table, array $table_fields = []): ?Table { if (!isset($table['table_name'])) { throw new Exception('table[table_name] must be set'); } $table_name = $table['table_name']; - $currentTable = rex_yform_manager_table::get($table_name); + $currentTable = Table::get($table_name); if (!$currentTable) { // Insert $table_insert = rex_sql::factory(); $table_insert->setDebug(self::$debug); - $table_insert->setTable(rex_yform_manager_table::table()); + $table_insert->setTable(Table::table()); $table_insert->setValue('table_name', $table_name); if (!isset($table['name']) || '' == $table['name']) { @@ -38,7 +54,7 @@ public static function setTable(array $table, array $table_fields = []): ?rex_yf } } if (!isset($table['prio'])) { - $table_insert->setValue('prio', rex_yform_manager_table::getMaximumTablePrio() + 1); + $table_insert->setValue('prio', Table::getMaximumTablePrio() + 1); } $table_insert->insert(); } else { @@ -56,7 +72,7 @@ public static function setTable(array $table, array $table_fields = []): ?rex_yf $table_update = rex_sql::factory(); $table_update->setDebug(self::$debug); - $table_update->setTable(rex_yform_manager_table::table()); + $table_update->setTable(Table::table()); $table_update->setWhere('table_name = :table_name', [':table_name' => $table_name]); foreach (self::$table_fields as $field) { @@ -67,8 +83,8 @@ public static function setTable(array $table, array $table_fields = []): ?rex_yf $table_update->update(); } - rex_yform_manager_table::deleteCache(); - $table = rex_yform_manager_table::get($table_name); + Table::deleteCache(); + $table = Table::get($table_name); self::generateTableAndFields($table); if (count($table_fields) > 0) { @@ -76,9 +92,9 @@ public static function setTable(array $table, array $table_fields = []): ?rex_yf self::setTableField($table_name, $field); } } - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); - return rex_yform_manager_table::get($table_name); + return Table::get($table_name); } /** @@ -105,7 +121,7 @@ public static function importTablesets(string $tableset_content): bool $fields = $table['fields']; $settable['schema_overwrite'] = 1; self::setTable($settable, $fields); - $table = rex_yform_manager_table::get($settable['table_name']); + $table = Table::get($settable['table_name']); self::generateTableAndFields($table); } return true; @@ -128,7 +144,7 @@ public static function exportTablesets(array $table_names) $export = []; foreach ($table_names as $table_name) { - $export_table = rex_yform_manager_table::get($table_name); + $export_table = Table::get($table_name); $export_fields = []; foreach ($export_table->getFields() as $field) { $export_fields[] = array_diff_key($field->toArray(), ['id' => 0]); @@ -149,11 +165,11 @@ public static function exportTablesets(array $table_names) */ public static function removeTable(string $table_name): void { - $table = rex_yform_manager_table::get($table_name); + $table = Table::get($table_name); $t = rex_sql::factory(); $t->setDebug(self::$debug); - $t->setQuery('delete from ' . rex_yform_manager_table::table() . ' where table_name=:table_name ', [':table_name' => $table_name]); + $t->setQuery('delete from ' . Table::table() . ' where table_name=:table_name ', [':table_name' => $table_name]); if ($table) { foreach ($table->getFields() as $remove_field) { @@ -161,7 +177,7 @@ public static function removeTable(string $table_name): void } } - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } /** @@ -189,7 +205,7 @@ public static function setTableField(string $table_name, array $table_field) $fieldIdentifier['type_name'] = $table_field['type_name']; } - $currentFields = rex_yform_manager_table::get($table_name)->getFields($fieldIdentifier); + $currentFields = Table::get($table_name)->getFields($fieldIdentifier); // validate specials if ('validate' == $table_field['type_id']) { @@ -206,21 +222,21 @@ public static function setTableField(string $table_name, array $table_field) // Insert $field_insert = rex_sql::factory(); $field_insert->setDebug(self::$debug); - $field_insert->setTable(rex_yform_manager_field::table()); + $field_insert->setTable(Field::table()); $field_insert->setValue('table_name', $table_name); foreach ($table_field as $field_name => $field_value) { $field_insert->setValue($field_name, $field_value); } if (!isset($table_field['prio'])) { - $field_insert->setValue('prio', rex_yform_manager_table::get($table_name)->getMaximumPrio() + 1); + $field_insert->setValue('prio', Table::get($table_name)->getMaximumPrio() + 1); } $field_insert->insert(); } else { // Update $field_update = rex_sql::factory(); $field_update->setDebug(self::$debug); - $field_update->setTable(rex_yform_manager_field::table()); + $field_update->setTable(Field::table()); $add_where = []; foreach ($fieldIdentifier as $field => $value) { @@ -238,7 +254,7 @@ public static function setTableField(string $table_name, array $table_field) $field_update->update(); } - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } /** @@ -248,9 +264,9 @@ public static function removeTablefield(string $table_name, string $field_name): { $f = rex_sql::factory(); $f->setDebug(self::$debug); - $f->setQuery('delete from ' . rex_yform_manager_field::table() . ' where table_name=:table_name and name=:name', [':table_name' => $table_name, ':name' => $field_name]); + $f->setQuery('delete from ' . Field::table() . ' where table_name=:table_name and name=:name', [':table_name' => $table_name, ':name' => $field_name]); - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } /** @@ -536,7 +552,7 @@ public static function migrateField(string $table_name, array $column): array */ public static function createMissingFieldColumns(array $field): void { - $table_name = rex_yform_manager_field::table(); + $table_name = Field::table(); if (!isset(self::$cacheColumnsByTable[$table_name])) { foreach (rex_sql::showColumns($table_name) as $column) { @@ -548,7 +564,7 @@ public static function createMissingFieldColumns(array $field): void if (!isset(self::$cacheColumnsByTable[$table_name][$fieldKey])) { $alter = rex_sql::factory(); $alter->setDebug(self::$debug); - $alter->setQuery('ALTER TABLE `' . rex_yform_manager_field::table() . '` ADD `' . $fieldKey . '` TEXT NOT NULL'); + $alter->setQuery('ALTER TABLE `' . Field::table() . '` ADD `' . $fieldKey . '` TEXT NOT NULL'); self::$cacheColumnsByTable[$table_name][$fieldKey] = [ 'name' => $fieldKey, 'type' => 'text', @@ -563,12 +579,12 @@ public static function createMissingFieldColumns(array $field): void /** * @throws rex_sql_exception */ - public static function generateTableAndFields(rex_yform_manager_table $table, bool $delete_old = false): void + public static function generateTableAndFields(Table $table, bool $delete_old = false): void { $tableName = $table->getTableName(); - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); - $table = rex_yform_manager_table::get($tableName); + $table = Table::get($tableName); if (!$table) { return; } @@ -641,7 +657,7 @@ public static function generateTableAndFields(rex_yform_manager_table $table, bo } } } - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } /** @@ -650,10 +666,10 @@ public static function generateTableAndFields(rex_yform_manager_table $table, bo */ public static function generateTablesAndFields(bool $delete_old = false): void { - rex_yform_manager_table::deleteCache(); - foreach (rex_yform_manager_table::getAll() as $table) { + Table::deleteCache(); + foreach (Table::getAll() as $table) { self::generateTableAndFields($table, $delete_old); } - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } } diff --git a/lib/manager/table/authorization.php b/lib/manager/table/authorization.php index 9a8286b62..bfa2459a8 100644 --- a/lib/manager/table/authorization.php +++ b/lib/manager/table/authorization.php @@ -1,14 +1,22 @@ */ + /** @var array|null */ public static ?array $tableAuthorizations = null; - public static function onAttribute(string $attribute, rex_yform_manager_table $userTable, ?rex_user $user = null): bool + public static function onAttribute(string $attribute, Table $userTable, ?rex_user $user = null): bool { if (null !== self::$tableAuthorizations) { if (array_key_exists($attribute, self::$tableAuthorizations[$userTable->getTableName()] ?? [])) { @@ -19,7 +27,7 @@ public static function onAttribute(string $attribute, rex_yform_manager_table $u self::$tableAuthorizations = []; - foreach (rex_yform_manager_table::getAll() as $table) { + foreach (Table::getAll() as $table) { if (self::canEdit($table, $user)) { self::$tableAuthorizations[$table->getTableName()][self::VIEW] = 1; self::$tableAuthorizations[$table->getTableName()][self::EDIT] = 1; @@ -37,7 +45,7 @@ public static function onAttribute(string $attribute, rex_yform_manager_table $u return self::onAttribute($attribute, $userTable, $user); } - private static function canView(rex_yform_manager_table $table, ?rex_user $user = null): bool + private static function canView(Table $table, ?rex_user $user = null): bool { if (!$user) { return false; @@ -47,13 +55,13 @@ private static function canView(rex_yform_manager_table $table, ?rex_user $user return true; } - /** @var rex_yform_manager_table_perm_view $complexPerm */ + /** @var View $complexPerm */ $complexPerm = $user->getComplexPerm('yform_manager_table_view'); return null !== $complexPerm && $complexPerm->hasPerm($table->getTableName()); } - private static function canEdit(rex_yform_manager_table $table, ?rex_user $user = null): bool + private static function canEdit(Table $table, ?rex_user $user = null): bool { if (!$user) { return false; @@ -63,7 +71,7 @@ private static function canEdit(rex_yform_manager_table $table, ?rex_user $user return true; } - /** @var rex_yform_manager_table_perm_edit $complexPerm */ + /** @var Edit $complexPerm */ $complexPerm = $user->getComplexPerm('yform_manager_table_edit'); return null !== $complexPerm && $complexPerm->hasPerm($table->getTableName()); diff --git a/lib/manager/table/perm/edit.php b/lib/manager/table/perm/edit.php index 0918d288f..ba1ad7a2c 100644 --- a/lib/manager/table/perm/edit.php +++ b/lib/manager/table/perm/edit.php @@ -1,9 +1,14 @@ getTableName()] = $table->getNameLocalized() . ' [' . $table->getTableName() . ']'; } diff --git a/lib/manager/table/perm/view.php b/lib/manager/table/perm/view.php index 02258ef0c..e267a2cdf 100644 --- a/lib/manager/table/perm/view.php +++ b/lib/manager/table/perm/view.php @@ -1,9 +1,14 @@ getTableName()] = $table->getNameLocalized() . ' [' . $table->getTableName() . ']'; } diff --git a/lib/rest/route.php b/lib/rest/route.php index 6e85f2055..77acab3f9 100644 --- a/lib/rest/route.php +++ b/lib/rest/route.php @@ -6,11 +6,11 @@ use rex_api_exception; use rex_i18n; use rex_sql_exception; -use rex_yform_manager_collection; -use rex_yform_manager_dataset; -use rex_yform_manager_field; -use rex_yform_manager_query; -use rex_yform_manager_table; +use Yakamara\YForm\Manager\Collection; +use Yakamara\YForm\Manager\Dataset; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Query; +use Yakamara\YForm\Manager\Table\Table; use function array_key_exists; use function call_user_func; @@ -26,10 +26,10 @@ class Route public $path = ''; public $type = ''; - /** @var rex_yform_manager_table */ + /** @var Table */ public $table; - /** @var rex_yform_manager_query */ + /** @var Query */ public $query; public $instance; @@ -115,7 +115,7 @@ public function handleRequest(array $paths, array $get) Rest::sendError('400', 'request-method-not-available'); } - /** @var rex_yform_manager_table $table */ + /** @var Table $table */ $table = $this->getTable(); $query = $this->getQuery(); @@ -128,9 +128,9 @@ public function handleRequest(array $paths, array $get) $instance = $table->createDataset(); $fields = $this->getFields('get', $instance); - /** @var rex_yform_manager_dataset $instance */ + /** @var Dataset $instance */ $instance = null; - /** @var rex_yform_manager_collection $instance */ + /** @var Collection $instance */ $instances = null; $attribute = null; $baseInstances = false; @@ -455,13 +455,13 @@ public function handleRequest(array $paths, array $get) /** * @throws rex_api_exception - * @return array + * @return array<\Yakamara\YForm\Manager\Field> */ public function getFields(string $type = 'get', $instance = null): array { $class = $this->getTypeFromInstance($instance); - $returnFields = ['id' => new rex_yform_manager_field([ + $returnFields = ['id' => new Field([ 'name' => 'id', 'type_id' => 'value', 'type_name' => 'integer', @@ -471,8 +471,8 @@ public function getFields(string $type = 'get', $instance = null): array return $returnFields; } - /** @var rex_yform_manager_table $table */ - /** @var rex_yform_manager_dataset $class */ + /** @var Table $table */ + /** @var Dataset $class */ $table = $class::table(); if (!is_object($table)) { @@ -494,12 +494,12 @@ public function getFields(string $type = 'get', $instance = null): array return $returnFields; } - public function getFilterQuery(rex_yform_manager_query $query, array $fields, array $get): rex_yform_manager_query + public function getFilterQuery(Query $query, array $fields, array $get): Query { if (isset($get['filter']) && is_array($get['filter'])) { foreach ($get['filter'] as $filterKey => $filterValue) { foreach ($fields as $fieldName => $field) { - /* @var rex_yform_manager_field $field */ + /* @var Field $field */ if ($fieldName == $filterKey) { if (method_exists('rex_yform_value_' . $field->getTypeName(), 'getSearchFilter')) { try { @@ -551,7 +551,7 @@ public function getInstanceData($instance, $paths, $onlyId = false, $parents = [ /** * @throws rex_api_exception */ - public function getInstanceAttributes(rex_yform_manager_dataset $instance, $parents = []): array + public function getInstanceAttributes(Dataset $instance, $parents = []): array { $data = []; @@ -606,7 +606,7 @@ private function filterFieldsByInclude(array $fields, array $parents = []): arra /** * @throws rex_api_exception */ - public function getInstanceRelationships(rex_yform_manager_dataset $instance, $parents = []): array + public function getInstanceRelationships(Dataset $instance, $parents = []): array { $paths[] = $instance->getId(); @@ -686,24 +686,24 @@ public function getTypeFromInstance($instance = null): string return $type; } - public function setQuery(rex_yform_manager_query $query): self + public function setQuery(Query $query): self { $this->query = $query; return $this; } - public function getQuery(): rex_yform_manager_query + public function getQuery(): Query { return $this->query; } - public function setTable(rex_yform_manager_table $table): self + public function setTable(Table $table): self { $this->table = $table; return $this; } - public function getTable(): rex_yform_manager_table + public function getTable(): Table { return $this->table; } diff --git a/lib/yform/value/be_link.php b/lib/yform/value/be_link.php index eaaab9d15..3a7e3ae41 100644 --- a/lib/yform/value/be_link.php +++ b/lib/yform/value/be_link.php @@ -78,12 +78,12 @@ public static function isArticleInUse(rex_extension_point $ep) $article = \rex_article::get($id); if ($article) { $sql = \rex_sql::factory(); - $sql->setQuery('SELECT * FROM `' . \rex_yform_manager_field::table() . '` LIMIT 0'); + $sql->setQuery('SELECT * FROM `' . \Yakamara\YForm\Manager\Field::table() . '` LIMIT 0'); $columns = $sql->getFieldnames(); $select = in_array('multiple', $columns) ? ', `multiple`' : ''; - $fields = $sql->getArray('SELECT `table_name`, `name`' . $select . ' FROM `' . \rex_yform_manager_field::table() . '` WHERE `type_id`="value" AND `type_name` IN("be_link")'); + $fields = $sql->getArray('SELECT `table_name`, `name`' . $select . ' FROM `' . \Yakamara\YForm\Manager\Field::table() . '` WHERE `type_id`="value" AND `type_name` IN("be_link")'); $fields = \rex_extension::registerPoint(new \rex_extension_point('YFORM_ARTICLE_IS_IN_USE', $fields)); if (count($fields)) { @@ -103,7 +103,7 @@ public static function isArticleInUse(rex_extension_point $ep) if (count($items)) { foreach ($items as $item) { $sqlData = \rex_sql::factory(); - $sqlData->setQuery('SELECT `name` FROM `' . \rex_yform_manager_table::table() . '` WHERE `table_name` = "' . $tableName . '"'); + $sqlData->setQuery('SELECT `name` FROM `' . \Yakamara\YForm\Manager\Table\Table::table() . '` WHERE `table_name` = "' . $tableName . '"'); $url = rex_yform_manager::url($tableName, $item['id']); $messages .= '
  • ' . $sqlData->getValue('name') . ' [id=' . $item['id'] . ']
  • '; } @@ -139,7 +139,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); return '' == $value ? $query : $query->whereListContains($field, $value); diff --git a/lib/yform/value/be_manager_relation.php b/lib/yform/value/be_manager_relation.php index e6af2a6c5..52c5805f8 100644 --- a/lib/yform/value/be_manager_relation.php +++ b/lib/yform/value/be_manager_relation.php @@ -170,7 +170,7 @@ public function enterObject() // ------------------------------------ INLINE, 1-n if (5 == $this->relation['relation_type']) { $warning = false; - $table = rex_yform_manager_table::get($this->relation['target_table']); + $table = \Yakamara\YForm\Manager\Table\Table::get($this->relation['target_table']); // ----- Find PrioFieldname if exists @@ -198,7 +198,7 @@ public function enterObject() // ----- Existing Relations - $relations = rex_yform_manager_dataset::query($this->relation['target_table']) + $relations = \Yakamara\YForm\Manager\Dataset::query($this->relation['target_table']) ->where($this->relation['target_field'], $this->params['main_id']); if ('' != $prioFieldName) { $relations->orderBy($prioFieldName); @@ -255,8 +255,8 @@ public function enterObject() $yform->setObjectparams('submit_btn_show', false); $yform->setObjectparams('csrf_protection', false); - $yform->canEdit(rex_yform_manager_table_authorization::onAttribute('EDIT', $table, rex::getUser())); - $yform->canView(rex_yform_manager_table_authorization::onAttribute('VIEW', $table, rex::getUser())); + $yform->canEdit(\Yakamara\YForm\Manager\Table\Authorization::onAttribute('EDIT', $table, rex::getUser())); + $yform->canView(\Yakamara\YForm\Manager\Table\Authorization::onAttribute('VIEW', $table, rex::getUser())); $form_elements = []; foreach ($yform->objparams['form_elements'] as $form_element) { @@ -296,8 +296,8 @@ public function enterObject() $yform->setObjectparams('submit_btn_show', false); $yform->setObjectparams('csrf_protection', false); - $yform->canEdit(rex_yform_manager_table_authorization::onAttribute('EDIT', $table, rex::getUser())); - $yform->canView(rex_yform_manager_table_authorization::onAttribute('VIEW', $table, rex::getUser())); + $yform->canEdit(\Yakamara\YForm\Manager\Table\Authorization::onAttribute('EDIT', $table, rex::getUser())); + $yform->canView(\Yakamara\YForm\Manager\Table\Authorization::onAttribute('VIEW', $table, rex::getUser())); $form_elements = []; @@ -356,7 +356,7 @@ public function postSave(): void if (5 == $this->relation['relation_type'] && $this->params['main_id'] > 0) { self::$yform_list_values = []; // delete cache - $currentRelationsQuery = rex_yform_manager_dataset::query($this->relation['target_table']) + $currentRelationsQuery = \Yakamara\YForm\Manager\Dataset::query($this->relation['target_table']) ->where($this->relation['target_field'], $this->params['main_id']) ->find(); @@ -364,7 +364,7 @@ public function postSave(): void foreach ($currentRelationsQuery as $currentRelation) { $currentRelations[$currentRelation->getId()] = $currentRelation; } - $table = rex_yform_manager_table::get($this->relation['target_table']); + $table = \Yakamara\YForm\Manager\Table\Table::get($this->relation['target_table']); $prioFieldName = ''; foreach ($table->getFields() as $field) { @@ -508,11 +508,11 @@ public function getDefinitions(): array 'db_type' => ['text', 'varchar(191)', 'int', 'int(10) unsigned'], 'formbuilder' => false, 'hooks' => [ - 'preCreate' => static function (rex_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 (rex_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'); }, ]; @@ -520,7 +520,7 @@ public function getDefinitions(): array public static function getListValue($params) { - /** @var rex_yform_manager_field $field */ + /** @var \Yakamara\YForm\Manager\Field $field */ $field = $params['params']['field']; switch ($field['type']) { @@ -597,7 +597,7 @@ public static function getListValues($table, $field, array $filter = []) { $filterHash = sha1(json_encode($filter)); if (!isset(self::$yform_list_values[$table][$field][$filterHash])) { - $tableObject = rex_yform_manager_table::get($table); + $tableObject = \Yakamara\YForm\Manager\Table\Table::get($table); self::$yform_list_values[$table][$field][$filterHash] = []; $db = rex_sql::factory(); // $db->setDebug(); @@ -704,14 +704,14 @@ private static function getFilterArray($rawFilter, $table, callable $getValueFor $value = $matches[1]; if (str_contains($value, '.')) { $value = explode('.', $value); - $relation = rex_yform_manager_table::get($table)->getRelation($value[0]); + $relation = \Yakamara\YForm\Manager\Table\Table::get($table)->getRelation($value[0]); $value[0] = $getValueForKey($value[0]); if ($value[0] && $relation) { $relationSql = rex_sql::factory(); // $relationSql->debugsql = true; $tables = '' . $relationSql->escapeIdentifier($relation['table']) . ' t0'; for ($i = 1; $i < count($value) - 1; ++$i) { - $relation = rex_yform_manager_table::get($relation['table'])->getRelation($value[$i]); + $relation = \Yakamara\YForm\Manager\Table\Table::get($relation['table'])->getRelation($value[$i]); $tables .= ' LEFT JOIN ' . $relationSql->escapeIdentifier($relation['table']) . ' t' . $i . ' ON t' . $i . '.id = t' . ($i - 1) . '.' . $relationSql->escapeIdentifier($value[$i]) . ''; } $relationSql->setQuery('SELECT t' . ($i - 1) . '.' . $relationSql->escapeIdentifier($value[$i]) . ' FROM ' . $tables . ' WHERE t0.id = ' . (int) $value[0]); @@ -815,7 +815,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; if (null !== $value && !is_scalar($value) && !(is_object($value) && method_exists($value, '__toString'))) { @@ -836,7 +836,7 @@ public static function getSearchFilter($params) $value = null; - /** @var rex_yform_manager_field $field */ + /** @var \Yakamara\YForm\Manager\Field $field */ $field = $params['field']; $sql = rex_sql::factory(); @@ -871,7 +871,7 @@ public static function getSearchFilter($params) private static function getRelationTableFieldsForTables($mainTable, $relationTable, $targetTable) { - $table = rex_yform_manager_table::get($relationTable); + $table = \Yakamara\YForm\Manager\Table\Table::get($relationTable); $source = $table->getRelationsTo($mainTable); $target = $table->getRelationsTo($targetTable); diff --git a/lib/yform/value/be_media.php b/lib/yform/value/be_media.php index ef34e5d4b..657a5824e 100644 --- a/lib/yform/value/be_media.php +++ b/lib/yform/value/be_media.php @@ -112,12 +112,12 @@ public static function isMediaInUse(rex_extension_point $ep) $warning = $ep->getSubject(); $sql = \rex_sql::factory(); - $sql->setQuery('SELECT * FROM `' . \rex_yform_manager_field::table() . '` LIMIT 0'); + $sql->setQuery('SELECT * FROM `' . \Yakamara\YForm\Manager\Field::table() . '` LIMIT 0'); $columns = $sql->getFieldnames(); $select = in_array('multiple', $columns) ? ', `multiple`' : ''; - $fields = $sql->getArray('SELECT `table_name`, `name`' . $select . ' FROM `' . \rex_yform_manager_field::table() . '` WHERE `type_id`="value" AND `type_name` IN("be_media")'); + $fields = $sql->getArray('SELECT `table_name`, `name`' . $select . ' FROM `' . \Yakamara\YForm\Manager\Field::table() . '` WHERE `type_id`="value" AND `type_name` IN("be_media")'); $fields = \rex_extension::registerPoint(new \rex_extension_point('YFORM_MEDIA_IS_IN_USE', $fields)); if (!count($fields)) { @@ -142,7 +142,7 @@ public static function isMediaInUse(rex_extension_point $ep) if (count($items)) { foreach ($items as $item) { $sqlData = \rex_sql::factory(); - $sqlData->setQuery('SELECT `name` FROM `' . \rex_yform_manager_table::table() . '` WHERE `table_name` = "' . $tableName . '"'); + $sqlData->setQuery('SELECT `name` FROM `' . \Yakamara\YForm\Manager\Table\Table::table() . '` WHERE `table_name` = "' . $tableName . '"'); $editUrl = rex_yform_manager::url($tableName, $item['id']); $messages .= '
  • ' . $sqlData->getValue('name') . ' [id=' . $item['id'] . ']
  • '; } diff --git a/lib/yform/value/checkbox.php b/lib/yform/value/checkbox.php index 11d97d0fe..98bc796fd 100644 --- a/lib/yform/value/checkbox.php +++ b/lib/yform/value/checkbox.php @@ -59,7 +59,7 @@ public function getDefinitions(): array 'db_type' => ['tinyint(1)'], 'famous' => true, 'hooks' => [ - 'preDefault' => static function (rex_yform_manager_field $field) { + 'preDefault' => static function (\Yakamara\YForm\Manager\Field $field) { return (1 == $field->getElement('default')) ? '1' : '0'; }, ], @@ -82,10 +82,10 @@ public static function getSearchField($params) ]); } - public static function getSearchFilter($params): rex_yform_manager_query + public static function getSearchFilter($params): \Yakamara\YForm\Manager\Query { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/choice.php b/lib/yform/value/choice.php index cb23bcd58..29cdb507e 100644 --- a/lib/yform/value/choice.php +++ b/lib/yform/value/choice.php @@ -253,7 +253,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/date.php b/lib/yform/value/date.php index dbb3fa729..93db34beb 100644 --- a/lib/yform/value/date.php +++ b/lib/yform/value/date.php @@ -180,7 +180,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/datetime.php b/lib/yform/value/datetime.php index 2e8686518..65c25110f 100644 --- a/lib/yform/value/datetime.php +++ b/lib/yform/value/datetime.php @@ -188,7 +188,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/index.php b/lib/yform/value/index.php index 5b14b26e2..6b7687ea4 100644 --- a/lib/yform/value/index.php +++ b/lib/yform/value/index.php @@ -109,7 +109,7 @@ private function addRelation(array &$relations, array $names) private function getRelationValues(array $relations) { - $table = rex_yform_manager_table::get($this->params['main_table']); + $table = \Yakamara\YForm\Manager\Table\Table::get($this->params['main_table']); $sql = rex_sql::factory(); $sql->setDebug($this->params['debug']); @@ -154,8 +154,8 @@ private function getRelationValues(array $relations) return $nextIndex; }; - $addFieldsAndJoins = static function (array $columns, rex_yform_manager_field $relation, $index) use (&$addFieldsAndJoins, $addJoin, &$fields, $sql) { - $table = rex_yform_manager_table::get($relation->getElement('table')); + $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'; if ($relation->getElement('relation_table') || in_array($relation->getElement('type'), [1, 3, 4, 5])) { @@ -183,7 +183,7 @@ private function getRelationValues(array $relations) continue; } - $relationTable = rex_yform_manager_table::get($relation->getElement('relation_table')); + $relationTable = \Yakamara\YForm\Manager\Table\Table::get($relation->getElement('relation_table')); $name = $columns['target']; $relation = $relationTable->getValueField($name); $relation['relation_table'] = true; @@ -213,7 +213,7 @@ private function getRelationValues(array $relations) } $fromTable = $relation->getElement('relation_table'); - $relationTable = rex_yform_manager_table::get($fromTable); + $relationTable = \Yakamara\YForm\Manager\Table\Table::get($fromTable); $relation = $relationTable->getValueField($columns['target']); $relation['relation_table'] = true; $type = 'relation_table'; diff --git a/lib/yform/value/integer.php b/lib/yform/value/integer.php index eeb35d65c..dac0108dd 100644 --- a/lib/yform/value/integer.php +++ b/lib/yform/value/integer.php @@ -72,12 +72,12 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); if ('(empty)' == $value) { - return $query->whereNested(static function (rex_yform_manager_query $query) use ($field) { + return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) { $query ->where($field, '') ->where($field, null) @@ -85,7 +85,7 @@ public static function getSearchFilter($params) }, 'OR'); } if ('!(empty)' == $value) { - return $query->whereNested(static function (rex_yform_manager_query $query) use ($field) { + return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) { $query ->where($field, '', '<>') ->where($field, null, '<>') diff --git a/lib/yform/value/number.php b/lib/yform/value/number.php index 26a4cf9e7..55396cdcc 100644 --- a/lib/yform/value/number.php +++ b/lib/yform/value/number.php @@ -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 (rex_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; diff --git a/lib/yform/value/text.php b/lib/yform/value/text.php index eb402c8a4..4f2c7b513 100644 --- a/lib/yform/value/text.php +++ b/lib/yform/value/text.php @@ -63,7 +63,7 @@ public function getDefinitions(): array 'db_type' => ['varchar(191)', 'text'], 'famous' => true, 'hooks' => [ - 'preDefault' => static function (rex_yform_manager_field $field) { + 'preDefault' => static function (\Yakamara\YForm\Manager\Field $field) { return $field->getElement('default'); }, ], @@ -78,12 +78,12 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var \Yakamara\YForm\Manager\Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); if ('(empty)' == $value) { - return $query->whereNested(static function (rex_yform_manager_query $query) use ($field) { + return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) { $query ->where($field, '') ->where($field, null) @@ -91,7 +91,7 @@ public static function getSearchFilter($params) }, 'OR'); } if ('!(empty)' == $value) { - return $query->whereNested(static function (rex_yform_manager_query $query) use ($field) { + return $query->whereNested(static function (\Yakamara\YForm\Manager\Query $query) use ($field) { $query ->where($field, '', '<>') ->where($field, null, '<>') diff --git a/lib/yform/value/upload.php b/lib/yform/value/upload.php index 3fdb45a53..02086ed4c 100644 --- a/lib/yform/value/upload.php +++ b/lib/yform/value/upload.php @@ -552,7 +552,7 @@ public static function getListValue($params) $return = $value; if (rex::isBackend() && $list) { - $field = new rex_yform_manager_field($params['params']['field']); + $field = new \Yakamara\YForm\Manager\Field($params['params']['field']); if ('' != $value) { $return = '' . rex_escape($value) . ''; } diff --git a/pages/manager.data_edit.php b/pages/manager.data_edit.php index ba59eb66d..00096c99b 100644 --- a/pages/manager.data_edit.php +++ b/pages/manager.data_edit.php @@ -1,20 +1,14 @@ www.yakamara.de - */ - -// echo rex_view::title(rex_i18n::msg('yform')); +use Yakamara\YForm\Manager\Manager; +use Yakamara\YForm\Manager\Table\Table; $table_name = rex_request('table_name', 'string'); -$table = rex_yform_manager_table::get($table_name); +$table = Table::get($table_name); if ($table && $table->isGranted('VIEW', rex::getUser())) { try { - $page = new rex_yform_manager(); + $page = new Manager(); $page->setTable($table); $page->setLinkVars(['page' => rex_be_controller::getCurrentPage(), 'table_name' => $table->getTableName()]); echo $page->getDataPage(); diff --git a/pages/manager.data_history.php b/pages/manager.data_history.php index 0edc7f0d4..4cf9657b1 100644 --- a/pages/manager.data_history.php +++ b/pages/manager.data_history.php @@ -15,7 +15,7 @@ $dataset = null; if ($datasetId) { - $dataset = rex_yform_manager_dataset::getRaw($datasetId, $this->table->getTableName()); + $dataset = \Yakamara\YForm\Manager\Dataset::getRaw($datasetId, $this->table->getTableName()); } else { $filterDataset = false; } @@ -214,9 +214,9 @@ $list->setColumnLabel('action', rex_i18n::msg('yform_history_action')); $list->setColumnFormat('action', 'custom', static function (array $params) { static $classes = [ - rex_yform_manager_dataset::ACTION_CREATE => 'success', - rex_yform_manager_dataset::ACTION_UPDATE => 'primary', - rex_yform_manager_dataset::ACTION_DELETE => 'danger', + \Yakamara\YForm\Manager\Dataset::ACTION_CREATE => 'success', + \Yakamara\YForm\Manager\Dataset::ACTION_UPDATE => 'primary', + \Yakamara\YForm\Manager\Dataset::ACTION_DELETE => 'danger', ]; $class = $classes[$params['subject']] ?? 'default'; return sprintf('%s', $class, rex_i18n::msg('yform_history_action_' . $params['subject'])); @@ -291,9 +291,9 @@ 'label' => 'Action', 'choices' => [ '' => rex_i18n::msg('yform_manager_actions_all'), - rex_yform_manager_dataset::ACTION_CREATE => rex_i18n::msg('yform_history_action_' . rex_yform_manager_dataset::ACTION_CREATE), - rex_yform_manager_dataset::ACTION_UPDATE => rex_i18n::msg('yform_history_action_' . rex_yform_manager_dataset::ACTION_UPDATE), - rex_yform_manager_dataset::ACTION_DELETE => rex_i18n::msg('yform_history_action_' . rex_yform_manager_dataset::ACTION_DELETE), + \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), ], ]); diff --git a/pages/manager.data_import.php b/pages/manager.data_import.php index bcc2ae593..b9cd7f376 100644 --- a/pages/manager.data_import.php +++ b/pages/manager.data_import.php @@ -131,7 +131,7 @@ foreach ($mc as $mcc) { rex_sql::factory() - ->setTable(rex_yform_manager_field::table()) + ->setTable(\Yakamara\YForm\Manager\Field::table()) ->setValue('table_name', $this->table->getTablename()) ->setValue('prio', 999) ->setValue('type_id', 'value') @@ -145,10 +145,10 @@ echo rex_view::info(rex_i18n::msg('yform_manager_import_field_added', $mcc)); } - rex_yform_manager_table_api::generateTablesAndFields(); + \Yakamara\YForm\Manager\Table\Api::generateTablesAndFields(); $fields = []; - foreach (rex_yform_manager_table::get($this->table->getTableName())->getFields() as $field) { + foreach (\Yakamara\YForm\Manager\Table\Table::get($this->table->getTableName())->getFields() as $field) { $fields[strtolower($field->getName())] = $field; } } else { @@ -252,7 +252,7 @@ echo rex_view::error(rex_i18n::msg('yform_manager_import_info_data_imported', $dcounter)); } - rex_yform_manager_table::deleteCache(); + \Yakamara\YForm\Manager\Table\Table::deleteCache(); } } diff --git a/pages/manager.table_edit.php b/pages/manager.table_edit.php index 131a06614..24fcede37 100644 --- a/pages/manager.table_edit.php +++ b/pages/manager.table_edit.php @@ -58,7 +58,7 @@ } else { try { $content = file_get_contents($yform->objparams['value_pool']['email']['importfile']); - rex_yform_manager_table_api::importTablesets($content); + \Yakamara\YForm\Manager\Table\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())); @@ -67,7 +67,7 @@ } elseif (('add' == $func || 'edit' == $func) && rex::getUser()->isAdmin()) { $table = null; if ('edit' == $func) { - $table = rex_yform_manager_table::getById($table_id); + $table = \Yakamara\YForm\Manager\Table\Table::getById($table_id); if (!$table) { $func = 'add'; } @@ -85,7 +85,7 @@ $yform->setHiddenField('start', rex_request('start', 'string')); $yform->setActionField('showtext', ['', rex_i18n::msg('yform_manager_table_entry_saved')]); - $yform->setObjectparams('main_table', rex_yform_manager_table::table()); + $yform->setObjectparams('main_table', \Yakamara\YForm\Manager\Table\Table::table()); $yform->setValueField('html', ['html' => '
    ']); $yform->setValueField('html', ['html' => '']); @@ -97,7 +97,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', [rex_yform_manager_table::table(), 'id=' . $table->getId()]); + $yform->setActionField('db', [\Yakamara\YForm\Manager\Table\Table::table(), 'id=' . $table->getId()]); $yform->setObjectparams('main_id', $table->getId()); $yform->setObjectparams('main_where', 'id=' . $table->getId()); $yform->setObjectparams('getdata', true); @@ -112,9 +112,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) rex_yform_manager_table::get($table); + return (bool) \Yakamara\YForm\Manager\Table\Table::get($table); }, '', rex_i18n::msg('yform_manager_table_exists')]); - $yform->setActionField('db', [rex_yform_manager_table::table()]); + $yform->setActionField('db', [\Yakamara\YForm\Manager\Table\Table::table()]); break; } @@ -147,7 +147,7 @@ $sortFields = ['id']; if ('edit' === $func) { $sortFieldsSql = rex_sql::factory(); - $sortFieldsSql->setQuery('SELECT f.name FROM `' . rex_yform_manager_field::table() . '` f LEFT JOIN `' . rex_yform_manager_table::table() . '` t ON f.table_name = t.table_name WHERE t.id = :id ORDER BY f.prio', [ + $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', [ 'id' => (int) $table_id, ]); while ($sortFieldsSql->hasNext()) { @@ -223,19 +223,19 @@ switch ($func) { case 'edit': $table_name = $yform->objparams['value_pool']['email']['table_name']; - $table = rex_yform_manager_table::get($table_name); + $table = \Yakamara\YForm\Manager\Table\Table::get($table_name); if ($table) { - rex_yform_manager_table_api::generateTableAndFields($table); + \Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table); } echo rex_view::info(rex_i18n::msg('yform_manager_table_updated')); break; case 'add': default: - rex_yform_manager_table::deleteCache(); + \Yakamara\YForm\Manager\Table\Table::deleteCache(); $table_name = $yform->objparams['value_pool']['sql']['table_name']; - $table = rex_yform_manager_table::get($table_name); + $table = \Yakamara\YForm\Manager\Table\Table::get($table_name); if ($table) { - rex_yform_manager_table_api::generateTableAndFields($table); + \Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table); echo rex_view::success(rex_i18n::msg('yform_manager_table_added')); } break; @@ -248,7 +248,7 @@ echo rex_view::error(rex_i18n::msg('csrf_token_invalid')); } else { $table_name = rex_request('table_name', 'string'); - rex_yform_manager_table_api::removeTable($table_name); + \Yakamara\YForm\Manager\Table\Api::removeTable($table_name); $func = ''; echo rex_view::success(rex_i18n::msg('yform_manager_table_deleted')); @@ -310,7 +310,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 `' . rex_yform_manager_table::table() . '`'; + $sql = 'select id, prio, name, table_name, status, hidden, import, export, search, mass_deletion, mass_edit, history from `' . \Yakamara\YForm\Manager\Table\Table::table() . '`'; $list = rex_list::factory($sql, 200, defaultSort: [ 'prio' => 'asc', diff --git a/pages/manager.table_field.php b/pages/manager.table_field.php index b79a1d63f..7a883ed95 100644 --- a/pages/manager.table_field.php +++ b/pages/manager.table_field.php @@ -10,7 +10,7 @@ echo rex_view::title(rex_i18n::msg('yform')); $table_name = rex_request('table_name', 'string'); -$table = rex_yform_manager_table::get($table_name); +$table = \Yakamara\YForm\Manager\Table\Table::get($table_name); if ($table) { try { diff --git a/pages/manager.table_migrate.php b/pages/manager.table_migrate.php index fcc145fbc..ab2751cbd 100644 --- a/pages/manager.table_migrate.php +++ b/pages/manager.table_migrate.php @@ -17,7 +17,7 @@ $yform_tables = []; $missing_tables = []; -foreach (rex_yform_manager_table::getAll() as $g_table) { +foreach (\Yakamara\YForm\Manager\Table\Table::getAll() as $g_table) { $yform_tables[] = $g_table->getTableName(); } @@ -40,7 +40,7 @@ $schema_overwrite = (int) $yform->objparams['value_pool']['sql']['schema_overwrite']; try { - rex_yform_manager_table_api::migrateTable($table_name, (0 == $schema_overwrite) ? false : true); // with convert id / auto_increment finder + \Yakamara\YForm\Manager\Table\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]); diff --git a/pages/manager.tableset_export.php b/pages/manager.tableset_export.php index f2d99faff..e7b815a5b 100644 --- a/pages/manager.tableset_export.php +++ b/pages/manager.tableset_export.php @@ -13,7 +13,7 @@ $page = rex_request('page', 'string', ''); $yform_tables = []; -foreach (rex_yform_manager_table::getAll() as $g_table) { +foreach (\Yakamara\YForm\Manager\Table\Table::getAll() as $g_table) { $table_name = $g_table->getTableName(); $yform_tables[$table_name] = $g_table->getNameLocalized() . ' [' . $table_name . ']'; } @@ -29,7 +29,7 @@ if ($yform->objparams['actions_executed']) { try { $table_names = rex_request('table_names'); - $fileContent = rex_yform_manager_table_api::exportTablesets($table_names); + $fileContent = \Yakamara\YForm\Manager\Table\Api::exportTablesets($table_names); $tablenames = implode('_', $table_names); if (mb_strlen($tablenames) > 100) { diff --git a/pages/manager.tableset_import.php b/pages/manager.tableset_import.php index f7b7322bc..b5f6da8d2 100644 --- a/pages/manager.tableset_import.php +++ b/pages/manager.tableset_import.php @@ -36,7 +36,7 @@ try { $filder = $yform->objparams['value_pool']['files']['importfile'][2]; $content = file_get_contents($filder); - rex_yform_manager_table_api::importTablesets($content); + \Yakamara\YForm\Manager\Table\Api::importTablesets($content); echo rex_view::success(rex_i18n::msg('yform_manager_tableset_import_success')); } catch (Exception $e) { echo rex_view::warning(rex_i18n::msg('yform_manager_tableset_import_failed', $e->getMessage())); diff --git a/rector.php b/rector.php index 3eb23ea4c..428b9005c 100644 --- a/rector.php +++ b/rector.php @@ -2,10 +2,13 @@ use Rector\Config\RectorConfig; use Rector\Renaming\Rector\Name\RenameClassRector; +use Rector\Transform\Rector\FuncCall\FuncCallToStaticCallRector; +use Rector\Transform\ValueObject\FuncCallToStaticCall; use Rector\ValueObject\PhpVersion; +use Yakamara\YForm\Manager\Manager; return RectorConfig::configure() - ->withPaths(['docs', 'fragments', 'lib', 'module', 'pages', 'ytemplates', 'boot.php']) + ->withPaths(['docs', 'fragments', 'lib', 'module', 'pages', 'ytemplates', 'boot.php', 'tests']) ->withParallel() ->withPhpVersion(PhpVersion::PHP_83) ->withConfiguredRule( @@ -20,5 +23,20 @@ 'rex_var_yform_data' => 'Yakamara\YForm\RexVar\Data', 'rex_var_yform_table_data' => 'Yakamara\YForm\RexVar\TableData', 'rex_yform_email_template' => 'Yakamara\YForm\Email\Template', + 'rex_yform_manager_table' => 'Yakamara\YForm\Manager\Table\Table', + 'rex_yform_manager_table_authorization' => 'Yakamara\YForm\Manager\Table\Authorization', + 'rex_yform_manager_table_api' => 'Yakamara\YForm\Manager\Table\Api', + 'rex_yform_manager_table_perm_edit' => 'Yakamara\YForm\Manager\Table\Perm\Edit', + 'rex_yform_manager_table_perm_view' => 'Yakamara\YForm\Manager\Table\Perm\View', + 'rex_yform_manager_collection' => 'Yakamara\YForm\Manager\Collection', + 'rex_yform_manager_dataset' => 'Yakamara\YForm\Manager\Dataset', + 'rex_yform_manager_field' => 'Yakamara\YForm\Manager\Field', + 'rex_yform_manager_manager' => 'Yakamara\YForm\Manager\Manager', + 'rex_yform_manager_query' => 'Yakamara\YForm\Manager\Query', + 'rex_yform_manager_search' => 'Yakamara\YForm\Manager\Search', ], - ); + ) + ->withConfiguredRule(FuncCallToStaticCallRector::class, [ + new FuncCallToStaticCall('rex_yform_manager_checkField', Manager::class, 'checkField'), + ]) +; diff --git a/tests/rex_yform_yorm_test.php b/tests/rex_yform_yorm_test.php index 3e26951eb..d0eb787e9 100644 --- a/tests/rex_yform_yorm_test.php +++ b/tests/rex_yform_yorm_test.php @@ -20,7 +20,7 @@ class rex_yform_yorm_test extends TestCase { public static function setUpTable($tableName) { - $table = rex_yform_manager_table_api::setTable( + $table = \Yakamara\YForm\Manager\Table\Api::setTable( [ 'table_name' => $tableName, 'name' => 'Name of Table - ' . $tableName, @@ -39,7 +39,7 @@ public static function setUpTable($tableName) return $table; } - public static function setUpTableField(rex_yform_manager_table $table, $field) + public static function setUpTableField(\Yakamara\YForm\Manager\Table\Table $table, $field) { $field['type_id'] ??= 'value'; $field['type_name'] ??= 'text'; @@ -49,8 +49,8 @@ public static function setUpTableField(rex_yform_manager_table $table, $field) $field['search'] = $field['list_hidden'] ?? 0; $field['prio'] = $field['list_hidden'] ?? 99999; - rex_yform_manager_table_api::setTableField($table->getTableName(), $field); - rex_yform_manager_table_api::generateTableAndFields($table); + \Yakamara\YForm\Manager\Table\Api::setTableField($table->getTableName(), $field); + \Yakamara\YForm\Manager\Table\Api::generateTableAndFields($table); } public function testTableAPI() @@ -78,7 +78,7 @@ public function testTableAPI() // prüfen ob es angelegt ist. - $fields = rex_yform_manager_table::get($tableName)->getFields(); + $fields = \Yakamara\YForm\Manager\Table\Table::get($tableName)->getFields(); static::assertEquals( count($fields), 1, @@ -92,7 +92,7 @@ public function testTableAPI() // TODO: prüfen ob field gelöscht werden kann // YORM - Datensatz anlegen - $dataset = rex_yform_manager_dataset::create($tableName); + $dataset = \Yakamara\YForm\Manager\Dataset::create($tableName); $dataset->setValue($fieldName, $fieldValue); static::assertTrue($dataset->save(), 'dataset creation failed (rex_yform_manager_dataset::create)'); @@ -110,7 +110,7 @@ public function testTableAPI() // YORM - Datensatz auslesen $datasetId = $dataset->getId(); - $dataset = rex_yform_manager_dataset::get($datasetId, $tableName); + $dataset = \Yakamara\YForm\Manager\Dataset::get($datasetId, $tableName); static::assertNotNull($dataset, 'dataset not found - get via ID failed'); // YORM - Datensatz bearbeiten @@ -118,7 +118,7 @@ public function testTableAPI() $dataset ->setValue($fieldName, $fieldValueEdit) ->save(); - $dataset = rex_yform_manager_dataset::get($datasetId, $tableName); + $dataset = \Yakamara\YForm\Manager\Dataset::get($datasetId, $tableName); static::assertEquals( $dataset->getValue($fieldName), $fieldValueEdit, @@ -129,7 +129,7 @@ public function testTableAPI() if ($dataset) { static::assertTrue($dataset->delete(), 'dataset delete failed (rex_yform_manager_dataset::delete)'); - $dataset = rex_yform_manager_dataset::get($datasetId, $tableName); + $dataset = \Yakamara\YForm\Manager\Dataset::get($datasetId, $tableName); static::assertFalse($dataset->exists(), 'dataset delete failed - YOrm delete failed'); } @@ -187,23 +187,23 @@ public function testTableAPI() 'size' => 10, ]); - $cat1 = rex_yform_manager_dataset::create($tableNameCategories) + $cat1 = \Yakamara\YForm\Manager\Dataset::create($tableNameCategories) ->setValue($fieldName, 'Category 1'); $cat1->save(); - $cat2 = rex_yform_manager_dataset::create($tableNameCategories) + $cat2 = \Yakamara\YForm\Manager\Dataset::create($tableNameCategories) ->setValue($fieldName, 'Category 2'); $cat2->save(); - $cat3 = rex_yform_manager_dataset::create($tableNameCategories) + $cat3 = \Yakamara\YForm\Manager\Dataset::create($tableNameCategories) ->setValue($fieldName, 'Category 3'); $cat3->save(); - rex_yform_manager_dataset::create($tableName) + \Yakamara\YForm\Manager\Dataset::create($tableName) ->setValue($fieldName, 'Mein Neuer Wert') ->save(); - rex_yform_manager_dataset::create($tableName) + \Yakamara\YForm\Manager\Dataset::create($tableName) ->setValue($fieldName, 'Mein Neuer Wert mit 2 Kategorien') ->setValue('categories', [ $cat1->getId(), @@ -213,9 +213,9 @@ public function testTableAPI() } } - rex_yform_manager_table_api::removeTable($tableName); + \Yakamara\YForm\Manager\Table\Api::removeTable($tableName); - $table = rex_yform_manager_table::get($tableName); + $table = \Yakamara\YForm\Manager\Table\Table::get($tableName); static::assertNull($table, 'table schema removing failed'); @@ -231,19 +231,19 @@ public function testTableAPI() 'DROP Table ' . $tableNameRelation, ); rex_sql::factory()->setQuery( - 'delete from ' . rex_yform_manager_table::table() . ' where table_name LIKE :table_name ', + 'delete from ' . \Yakamara\YForm\Manager\Table\Table::table() . ' where table_name LIKE :table_name ', [ ':table_name' => $prefix . '%', ], ); rex_sql::factory()->setQuery( - 'delete from ' . rex_yform_manager_field::table() . ' where table_name LIKE :table_name ', + 'delete from ' . \Yakamara\YForm\Manager\Field::table() . ' where table_name LIKE :table_name ', [ ':table_name' => $prefix . '%', ], ); - rex_yform_manager_table::deleteCache(); + \Yakamara\YForm\Manager\Table\Table::deleteCache(); } catch (Exception $e) { } } diff --git a/ytemplates/bootstrap/value.be_manager_relation.tpl.php b/ytemplates/bootstrap/value.be_manager_relation.tpl.php index e25210856..f52747cfe 100644 --- a/ytemplates/bootstrap/value.be_manager_relation.tpl.php +++ b/ytemplates/bootstrap/value.be_manager_relation.tpl.php @@ -71,7 +71,7 @@ $args['link'] = $link; $args['fieldName'] = $this->getRelationSourceTableName() . '.' . $this->getName(); $args['valueName'] = $valueName; - $_csrf_key = rex_yform_manager_table::get($this->relation['target_table'])->getCSRFKey(); + $_csrf_key = \Yakamara\YForm\Manager\Table\Table::get($this->relation['target_table'])->getCSRFKey(); $args += rex_csrf_token::factory($_csrf_key)->getUrlParams(); $value = implode(',', $this->getValue()); echo \Yakamara\YForm\RexVar\TableData::getSingleWidget($id, $name, $value, $args); @@ -83,7 +83,7 @@ $args['fieldName'] = $this->getRelationSourceTableName() . '.' . $this->getName(); $args['size'] = $this->getRelationSize(); $args['attributes'] = $this->getAttributeArray([], ['required', 'readonly']); - $_csrf_key = rex_yform_manager_table::get($this->relation['target_table'])->getCSRFKey(); + $_csrf_key = \Yakamara\YForm\Manager\Table\Table::get($this->relation['target_table'])->getCSRFKey(); $args += rex_csrf_token::factory($_csrf_key)->getUrlParams(); $value = implode(',', $this->getValue()); echo \Yakamara\YForm\RexVar\TableData::getMultipleWidget($id, $name, $value, $args); From 13cb06bd889c1ca5e040164406a0363c10b4f310 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sat, 7 Sep 2024 22:29:38 +0200 Subject: [PATCH 07/12] CS --- pages/email.php | 7 ------ pages/manager.data_export.php | 7 +++--- pages/manager.data_history.php | 22 +++++++++------- pages/manager.data_import.php | 27 ++++++++------------ pages/manager.table_edit.php | 42 +++++++++++++++---------------- pages/manager.table_field.php | 12 +++------ pages/manager.table_migrate.php | 17 ++++++------- pages/manager.tableset_export.php | 15 +++++------ pages/manager.tableset_import.php | 12 +++------ pages/rest.access.php | 12 +++------ pages/rest.token.php | 15 +++++------ pages/setup.php | 9 +++---- 12 files changed, 82 insertions(+), 115 deletions(-) diff --git a/pages/email.php b/pages/email.php index bc374e90d..3fc5b846a 100644 --- a/pages/email.php +++ b/pages/email.php @@ -3,13 +3,6 @@ use Yakamara\YForm\Email\Template; use Yakamara\YForm\YForm; -/** - * yform. - * - * @author jan.kristinus[at]redaxo[dot]org Jan Kristinus - * @author www.yakamara.de - */ - $_csrf_key = 'yform_email'; echo rex_view::title(rex_i18n::msg('yform_email_templates')); diff --git a/pages/manager.data_export.php b/pages/manager.data_export.php index 3a8eae4bb..6e45b8503 100644 --- a/pages/manager.data_export.php +++ b/pages/manager.data_export.php @@ -1,9 +1,8 @@ table->getTableName()); + $dataset = Dataset::getRaw($datasetId, $this->table->getTableName()); } else { $filterDataset = false; } @@ -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('%s', $class, rex_i18n::msg('yform_history_action_' . $params['subject'])); @@ -264,7 +268,7 @@ $options = '' . rex_i18n::msg('yform_history_delete') . ': ' . $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); @@ -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), ], ]); diff --git a/pages/manager.data_import.php b/pages/manager.data_import.php index b9cd7f376..cd9c6d7bd 100644 --- a/pages/manager.data_import.php +++ b/pages/manager.data_import.php @@ -1,13 +1,11 @@ www.yakamara.de - * - * @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 ??= ''; @@ -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); @@ -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') @@ -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 { @@ -232,10 +229,8 @@ 'data_errors' => $errorcounter, ], )); - }); - - } catch (\Throwable $e) { + } catch (Throwable $e) { $error_message = $e->getMessage(); } @@ -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(); } } diff --git a/pages/manager.table_edit.php b/pages/manager.table_edit.php index 24fcede37..4ccb34bf7 100644 --- a/pages/manager.table_edit.php +++ b/pages/manager.table_edit.php @@ -1,11 +1,9 @@ www.yakamara.de - */ +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'; @@ -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); @@ -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())); @@ -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); @@ -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' => '
    ']); $yform->setValueField('html', ['html' => '']); @@ -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); @@ -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; } @@ -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()) { @@ -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; @@ -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')); @@ -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', diff --git a/pages/manager.table_field.php b/pages/manager.table_field.php index 7a883ed95..521aaa4a6 100644 --- a/pages/manager.table_field.php +++ b/pages/manager.table_field.php @@ -1,20 +1,16 @@ www.yakamara.de - */ +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(); diff --git a/pages/manager.table_migrate.php b/pages/manager.table_migrate.php index ab2751cbd..679db6fd3 100644 --- a/pages/manager.table_migrate.php +++ b/pages/manager.table_migrate.php @@ -1,11 +1,8 @@ www.yakamara.de - */ +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'; @@ -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(); } @@ -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); @@ -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]); diff --git a/pages/manager.tableset_export.php b/pages/manager.tableset_export.php index e7b815a5b..04dd0cf82 100644 --- a/pages/manager.tableset_export.php +++ b/pages/manager.tableset_export.php @@ -1,11 +1,8 @@ www.yakamara.de - */ +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'; @@ -13,12 +10,12 @@ $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); @@ -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) { diff --git a/pages/manager.tableset_import.php b/pages/manager.tableset_import.php index b5f6da8d2..ddfa2c6d8 100644 --- a/pages/manager.tableset_import.php +++ b/pages/manager.tableset_import.php @@ -1,18 +1,14 @@ www.yakamara.de - */ +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\YForm; echo rex_view::title(rex_i18n::msg('yform')); $_csrf_key = 'tableset_import'; $page = rex_request('page', 'string', ''); -$yform = new \Yakamara\YForm\YForm(); +$yform = new YForm(); $yform->setHiddenField('page', $page); $yform->setObjectparams('real_field_names', true); $yform->setObjectparams('form_name', $_csrf_key); @@ -36,7 +32,7 @@ try { $filder = $yform->objparams['value_pool']['files']['importfile'][2]; $content = file_get_contents($filder); - \Yakamara\YForm\Manager\Table\Api::importTablesets($content); + Api::importTablesets($content); echo rex_view::success(rex_i18n::msg('yform_manager_tableset_import_success')); } catch (Exception $e) { echo rex_view::warning(rex_i18n::msg('yform_manager_tableset_import_failed', $e->getMessage())); diff --git a/pages/rest.access.php b/pages/rest.access.php index c83fdd097..a78deaeac 100644 --- a/pages/rest.access.php +++ b/pages/rest.access.php @@ -1,11 +1,7 @@ www.yakamara.de - */ +use Yakamara\YForm\Rest\AuthToken; +use Yakamara\YForm\YForm; $_csrf_key = 'yform_rest_token_access'; @@ -34,7 +30,7 @@ $form_data[] = 'datetime|datetime_created|translate:yform_rest_token_access_datetime_created'; $form_data[] = 'text|url|translate:yform_rest_token_url'; - $yform = \Yakamara\YForm\YForm::factory(); + $yform = YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/rest/access'); $yform->setFormData(implode("\n", $form_data)); @@ -154,7 +150,7 @@ $list->setColumnParams('token_id', ['page' => 'yform/rest/token', 'func' => 'edit', 'data_id' => '###rest_id###']); $list->setColumnFormat('token_id', 'custom', static function ($params) { - $token = \Yakamara\YForm\Rest\AuthToken::get($params['subject']); + $token = AuthToken::get($params['subject']); if ($token) { return '' . $token['name'] . ''; } diff --git a/pages/rest.token.php b/pages/rest.token.php index 703871505..b54c341e2 100644 --- a/pages/rest.token.php +++ b/pages/rest.token.php @@ -1,11 +1,8 @@ www.yakamara.de - */ +use Yakamara\YForm\Rest\AuthToken; +use Yakamara\YForm\Rest\Rest; +use Yakamara\YForm\YForm; $_csrf_key = 'yform_rest_token'; @@ -21,7 +18,7 @@ $show_list = true; $routes = []; -foreach (\Yakamara\YForm\Rest\Rest::getRoutes() as $route) { +foreach (Rest::getRoutes() as $route) { $routes[] = $route->getPath(); } @@ -46,7 +43,7 @@ $form_data[] = 'integer|amount|translate:yform_rest_token_amount'; $form_data[] = 'choice|paths|translate:yform_rest_token_token_paths|' . implode(',', $routes) . '||1'; - $yform = \Yakamara\YForm\YForm::factory(); + $yform = YForm::factory(); $yform->setObjectparams('form_action', 'index.php?page=yform/rest/token'); $yform->setObjectparams('form_name', 'yform-rest-token-form'); @@ -189,7 +186,7 @@ $return = $maxHits; if ('none' != $list->getValue('interval')) { - $currentHits = \Yakamara\YForm\Rest\AuthToken::getCurrentIntervalAmount($list->getValue('interval'), $list->getValue('id')); + $currentHits = AuthToken::getCurrentIntervalAmount($list->getValue('interval'), $list->getValue('id')); $return = $currentHits . ' / ' . $maxHits . ' / ' . $list->getValue('interval') . ''; } diff --git a/pages/setup.php b/pages/setup.php index 6a3c6affc..e6eef9ede 100644 --- a/pages/setup.php +++ b/pages/setup.php @@ -1,9 +1,8 @@ i18n('yform')); @@ -69,5 +68,5 @@ $fragment = new rex_fragment(); $fragment->setVar('title', $this->i18n('description_type_heading'), false); -$fragment->setVar('body', \Yakamara\YForm\YForm::showHelp(), false); +$fragment->setVar('body', YForm::showHelp(), false); echo $fragment->parse('core/page/section.php'); From 7a13d04c09d9d66109ff736e8b363b2dd3042eb1 Mon Sep 17 00:00:00 2001 From: Jan Kristinus Date: Sun, 8 Sep 2024 22:28:22 +0200 Subject: [PATCH 08/12] Choices namespaced --- boot.php | 11 +- .../ChoiceList.php} | 28 ++- lib/Choice/GroupView.php | 31 ++++ .../ListView.php} | 12 +- .../View.php} | 12 +- lib/radio.php | 171 ------------------ .../Choice/rex_yform_choice_group_view.php | 29 --- lib/yform/value/choice.php | 16 +- rector.php | 4 + .../bootstrap/value.choice.check.tpl.php | 18 +- .../bootstrap/value.choice.select.tpl.php | 18 +- 11 files changed, 106 insertions(+), 244 deletions(-) rename lib/{yform/value/Choice/rex_yform_choice_list.php => Choice/ChoiceList.php} (89%) create mode 100644 lib/Choice/GroupView.php rename lib/{yform/value/Choice/rex_yform_choice_list_view.php => Choice/ListView.php} (66%) rename lib/{yform/value/Choice/rex_yform_choice_view.php => Choice/View.php} (90%) delete mode 100644 lib/radio.php delete mode 100644 lib/yform/value/Choice/rex_yform_choice_group_view.php diff --git a/boot.php b/boot.php index f98c0a340..a27a17341 100644 --- a/boot.php +++ b/boot.php @@ -5,10 +5,9 @@ use Yakamara\YForm\Rest\Rest; use Yakamara\YForm\YForm; -/** - * @var rex_addon $this - * @psalm-scope-this rex_addon - */ +/** @var rex_addon $this */ + +// Aliases are deprecated and will be removed in the next major version class_alias('Yakamara\YForm\YForm', 'rex_yform'); class_alias('Yakamara\YForm\Rest\Rest', 'rex_yform_rest'); @@ -30,6 +29,10 @@ class_alias('Yakamara\YForm\Manager\Field', 'rex_yform_manager_field'); class_alias('Yakamara\YForm\Manager\Manager', 'rex_yform_manager_manager'); class_alias('Yakamara\YForm\Manager\Query', 'rex_yform_manager_query'); class_alias('Yakamara\YForm\Manager\Search', 'rex_yform_manager_search'); +class_alias('Yakamara\YForm\Choice\GroupView', 'rex_yform_choice_group_view'); +class_alias('Yakamara\YForm\Choice\ChoiceList', 'rex_yform_choice_list'); +class_alias('Yakamara\YForm\Choice\ListView', 'rex_yform_choice_list_view'); +class_alias('Yakamara\YForm\Choice\View', 'rex_yform_choice_view'); YForm::addTemplatePath(rex_path::addon('yform', 'ytemplates')); diff --git a/lib/yform/value/Choice/rex_yform_choice_list.php b/lib/Choice/ChoiceList.php similarity index 89% rename from lib/yform/value/Choice/rex_yform_choice_list.php rename to lib/Choice/ChoiceList.php index 02760e7b9..4b4a6c193 100644 --- a/lib/yform/value/Choice/rex_yform_choice_list.php +++ b/lib/Choice/ChoiceList.php @@ -1,11 +1,19 @@ $view) { - if ($view instanceof rex_yform_choice_group_view && 0 === count($view->getChoices())) { + if ($view instanceof GroupView && 0 === count($view->getChoices())) { unset($preferredViews[$index]); } } foreach ($otherViews as $index => $view) { - if ($view instanceof rex_yform_choice_group_view && 0 === count($view->getChoices())) { + if ($view instanceof GroupView && 0 === count($view->getChoices())) { unset($otherViews[$index]); } } - return new rex_yform_choice_list_view($otherViews, $preferredViews); + return new ListView($otherViews, $preferredViews); } public function getDefaultValues(array $defaultChoices = []) diff --git a/lib/Choice/GroupView.php b/lib/Choice/GroupView.php new file mode 100644 index 000000000..f7cf8718d --- /dev/null +++ b/lib/Choice/GroupView.php @@ -0,0 +1,31 @@ + $choices the choice views in the group + */ + public function __construct(string $label, array $choices = []) + { + $this->label = $label; + $this->choices = $choices; + } + + public function getChoices(): array + { + return $this->choices; + } + + public function getLabel(): string + { + return $this->label; + } +} diff --git a/lib/yform/value/Choice/rex_yform_choice_list_view.php b/lib/Choice/ListView.php similarity index 66% rename from lib/yform/value/Choice/rex_yform_choice_list_view.php rename to lib/Choice/ListView.php index b1adcb3c7..2d483143f 100644 --- a/lib/yform/value/Choice/rex_yform_choice_list_view.php +++ b/lib/Choice/ListView.php @@ -1,6 +1,8 @@ |array<\Yakamara\YForm\Choice\View> $choices The choice views + * @param array<\Yakamara\YForm\Choice\GroupView>|array<\Yakamara\YForm\Choice\View> $preferredChoices the preferred choice views */ public function __construct(array $choices = [], array $preferredChoices = []) { @@ -28,10 +30,10 @@ public function hasPlaceholder() { if ($this->preferredChoices) { $firstChoice = reset($this->preferredChoices); - return $firstChoice instanceof rex_yform_choice_view && '' === $firstChoice->value; + return $firstChoice instanceof View && '' === $firstChoice->value; } $firstChoice = reset($this->choices); - return $firstChoice instanceof rex_yform_choice_view && '' === $firstChoice->value; + return $firstChoice instanceof View && '' === $firstChoice->value; } public function getChoices() diff --git a/lib/yform/value/Choice/rex_yform_choice_view.php b/lib/Choice/View.php similarity index 90% rename from lib/yform/value/Choice/rex_yform_choice_view.php rename to lib/Choice/View.php index 9458f84d1..3bb37e02c 100644 --- a/lib/yform/value/Choice/rex_yform_choice_view.php +++ b/lib/Choice/View.php @@ -1,6 +1,14 @@ getAttributes()); + return rex_string::buildAttributes($this->getAttributes()); } public function getLabel() diff --git a/lib/radio.php b/lib/radio.php deleted file mode 100644 index 6c7152266..000000000 --- a/lib/radio.php +++ /dev/null @@ -1,171 +0,0 @@ -www.yakamara.de - */ - -class rex_radio -{ - public $attributes; - public $options; - public $option_selected; - - public function __construct() - { - $this->init(); - } - - public function init() - { - $this->attributes = []; - $this->resetSelected(); - $this->setName('standard'); - $this->setDisabled(false); - } - - public function setAttribute($name, $value) - { - $this->attributes[$name] = $value; - } - - public function delAttribute($name) - { - if ($this->hasAttribute($name)) { - unset($this->attributes[$name]); - return true; - } - return false; - } - - public function hasAttribute($name) - { - return isset($this->attributes[$name]); - } - - public function getAttribute($name, $default = '') - { - if ($this->hasAttribute($name)) { - return $this->attributes[$name]; - } - return $default; - } - - public function setDisabled($disabled = true) - { - if ($disabled) { - $this->setAttribute('disabled', 'disabled'); - } else { - $this->delAttribute('disabled'); - } - } - - public function setName($name) - { - $this->setAttribute('name', $name); - } - - public function setId($id) - { - $this->setAttribute('id', $id); - } - - /** - * select style - * Es ist moeglich sowohl eine Styleklasse als auch einen Style zu uebergeben. - * - * Aufrufbeispiel: - * $sel_media->setStyle('class="inp100"'); - * und/oder - * $sel_media->setStyle("width:150px;"); - */ - public function setStyle($style) - { - if (str_contains($style, 'class=')) { - if (preg_match('/class=["\']?([^"\']*)["\']?/i', $style, $matches)) { - $this->setAttribute('class', $matches[1]); - } - } else { - $this->setAttribute('style', $style); - } - } - - public function setSize($size) - { - $this->setAttribute('size', $size); - } - - public function setSelected($selected) - { - $this->option_selected = rex_escape($selected); - } - - public function resetSelected() - { - $this->option_selected = ''; - } - - public function addOption($name, $value, $attributes = []) - { - $this->options[] = ['name' => $name, 'value' => $value, 'attributes' => $attributes]; - } - - public function get() - { - $attr = ''; - foreach ($this->attributes as $name => $value) { - $attr .= ' ' . $name . '="' . $value . '"'; - } - - $ausgabe = "\n"; - $ausgabe .= '
    '; - - if (is_array($this->options)) { - $ausgabe .= $this->_outOptions(); - } - - $ausgabe .= '
    ' . "\n"; - - return $ausgabe; - } - - public function show() - { - echo $this->get(); - } - - private function _outOptions() - { - $return = ''; - - $selected = ''; - foreach ($this->options as $option) { - if ('' == $selected) { - $selected = $option['value']; - } - - if ($this->option_selected == $option['value']) { - $selected = $option['value']; - } - } - - $id = $this->getAttribute('id'); - $counter = 0; - foreach ($this->options as $option) { - ++$counter; - $oid = $id . '-' . $counter; - $return .= '

    '; - $return .= '' . $option['name'] . '' . "\n"; - $return .= '

    '; - } - - return $return; - } -} diff --git a/lib/yform/value/Choice/rex_yform_choice_group_view.php b/lib/yform/value/Choice/rex_yform_choice_group_view.php deleted file mode 100644 index 9aeafc9aa..000000000 --- a/lib/yform/value/Choice/rex_yform_choice_group_view.php +++ /dev/null @@ -1,29 +0,0 @@ -label = $label; - $this->choices = $choices; - } - - public function getChoices() - { - return $this->choices; - } - - public function getLabel() - { - return $this->label; - } -} diff --git a/lib/yform/value/choice.php b/lib/yform/value/choice.php index 29cdb507e..a5e1e6fca 100644 --- a/lib/yform/value/choice.php +++ b/lib/yform/value/choice.php @@ -1,10 +1,8 @@ www.yakamara.de - */ + +use Yakamara\YForm\Choice\ChoiceList; +use Yakamara\YForm\Choice\GroupView; +use Yakamara\YForm\Manager\Query; class rex_yform_value_choice extends rex_yform_value_abstract { @@ -88,7 +86,7 @@ public function enterObject() $getChoices = static function ($choices, $options) use (&$getChoices) { foreach ($choices as $choice) { if ('rex_yform_choice_group_view' == $choice::class) { - /** @var rex_yform_choice_group_view $choice */ + /** @var GroupView $choice */ $options = $getChoices($choice->choices, $options); } else { /* @var rex_yform_choice_view $choice */ @@ -253,7 +251,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = $params['value']; - /** @var \Yakamara\YForm\Manager\Query $query */ + /** @var Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); @@ -321,7 +319,7 @@ private static function createChoiceList($elements) } $choicesElement = $elements['choices']; - $choiceList = new rex_yform_choice_list($options); + $choiceList = new ChoiceList($options); if (is_string($choicesElement) && 'SELECT' == rex_sql::getQueryType($choicesElement)) { $sql = rex_sql::factory(); diff --git a/rector.php b/rector.php index 428b9005c..fcdefc9cb 100644 --- a/rector.php +++ b/rector.php @@ -34,6 +34,10 @@ 'rex_yform_manager_manager' => 'Yakamara\YForm\Manager\Manager', 'rex_yform_manager_query' => 'Yakamara\YForm\Manager\Query', 'rex_yform_manager_search' => 'Yakamara\YForm\Manager\Search', + 'rex_yform_choice_group_view' => 'Yakamara\YForm\Choice\GroupView', + 'rex_yform_choice_list' => 'Yakamara\YForm\Choice\ChoiceList', + 'rex_yform_choice_list_view' => 'Yakamara\YForm\Choice\ListView', + 'rex_yform_choice_view' => 'Yakamara\YForm\Choice\View', ], ) ->withConfiguredRule(FuncCallToStaticCallRector::class, [ diff --git a/ytemplates/bootstrap/value.choice.check.tpl.php b/ytemplates/bootstrap/value.choice.check.tpl.php index 469c87e61..4f54a1d90 100644 --- a/ytemplates/bootstrap/value.choice.check.tpl.php +++ b/ytemplates/bootstrap/value.choice.check.tpl.php @@ -1,12 +1,16 @@ getElement('notice')) { $notices[] = rex_i18n::translate($this->getElement('notice'), false); @@ -42,7 +46,7 @@ ?> - >