diff --git a/boot.php b/boot.php index 9eeeb7103..f1a5f6d66 100644 --- a/boot.php +++ b/boot.php @@ -1,11 +1,40 @@ setProperty('pages', $pages); } -rex_extension::register('MEDIA_IS_IN_USE', 'rex_yform_value_be_media::isMediaInUse'); -rex_extension::register('PACKAGES_INCLUDED', 'rex_yform_value_be_link::isArticleInUse'); +rex_extension::register('MEDIA_IS_IN_USE', '\Yakamara\YForm\Value\BackendMedia::isMediaInUse'); +rex_extension::register('PACKAGES_INCLUDED', '\Yakamara\YForm\Value\BackendLink::isArticleInUse'); rex_extension::register('YFORM_SAVED', static function (rex_extension_point $ep) { if ($ep->getSubject() instanceof Exception) { return; } - $table = rex_yform_manager_table::get($ep->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/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/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 176caea0f..a95095dc0 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())); @@ -99,19 +99,19 @@ static function ($params) { if (isset($params['list']->getParams()['table_name'])) { $target_table = $params['list']->getParams()['table_name']; $target_field = $tablefield[0]; - $values = rex_yform_value_be_manager_relation::getListValues($target_table, $target_field); + $values = \Yakamara\YForm\Value\BackendManagerRelation::getListValues($target_table, $target_field); $value = $values[$params['list']->getValue('id')]; } } 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])) { $target_table = $fields[$field_name]->getElement('table'); $target_field = $fields[$field_name]->getElement('field'); - $values = rex_yform_value_be_manager_relation::getListValues( + $values = \Yakamara\YForm\Value\BackendManagerRelation::getListValues( $target_table, $target_field, ); diff --git a/lib/yform/base_abstract.php b/lib/AbstractBase.php similarity index 93% rename from lib/yform/base_abstract.php rename to lib/AbstractBase.php index 270c9e1cc..1ccda211c 100644 --- a/lib/yform/base_abstract.php +++ b/lib/AbstractBase.php @@ -1,13 +1,8 @@ www.yakamara.de - */ - -abstract class rex_yform_base_abstract +namespace Yakamara\YForm; + +abstract class AbstractBase { public $id; public $params = []; diff --git a/lib/Action/AbstractAction.php b/lib/Action/AbstractAction.php new file mode 100644 index 000000000..978660bd3 --- /dev/null +++ b/lib/Action/AbstractAction.php @@ -0,0 +1,15 @@ +www.yakamara.de - */ - -class rex_yform_action_callback extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use function call_user_func; +use function in_array; + +class Callback extends AbstractAction { public static $callback_actions = [ 'pre', diff --git a/lib/yform/action/copy_value.php b/lib/Action/CopyValue.php similarity index 70% rename from lib/yform/action/copy_value.php rename to lib/Action/CopyValue.php index aecd041f1..3b2346c10 100644 --- a/lib/yform/action/copy_value.php +++ b/lib/Action/CopyValue.php @@ -1,13 +1,8 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Action; -class rex_yform_action_copy_value extends rex_yform_action_abstract +class CopyValue extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/create_table.php b/lib/Action/CreateTable.php similarity index 84% rename from lib/yform/action/create_table.php rename to lib/Action/CreateTable.php index 3412e4bdb..1d0b5670d 100644 --- a/lib/yform/action/create_table.php +++ b/lib/Action/CreateTable.php @@ -1,13 +1,12 @@ www.yakamara.de - */ - -class rex_yform_action_create_table extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use rex; +use rex_sql; +use function in_array; + +class CreateTable extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/db.php b/lib/Action/Db.php similarity index 79% rename from lib/yform/action/db.php rename to lib/Action/Db.php index 260689593..df6df0471 100644 --- a/lib/yform/action/db.php +++ b/lib/Action/Db.php @@ -1,14 +1,16 @@ www.yakamara.de - */ -class rex_yform_action_db extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use Exception; +use rex; +use rex_extension; +use rex_extension_point; +use rex_sql; +use function call_user_func; +use function count; + +class Db extends AbstractAction { public function executeAction(): void { @@ -68,8 +70,6 @@ public function executeAction(): void $action = 'insert'; $id = $sql->getLastId(); $this->params['main_id'] = $id; - /** @deprecated since 3.4.1 use id (lowercase) instead */ - $this->params['value_pool']['email']['ID'] = $id; $this->params['value_pool']['email']['id'] = $id; } } catch (Exception $e) { @@ -103,22 +103,6 @@ public function executeAction(): void 'yform' => true, ], )); - - /** - * @deprecated since 3.4.1 use EP YFORM_SAVED instead - */ - rex_extension::registerPoint(new rex_extension_point( - 'REX_YFORM_SAVED', - $sql, - [ - 'form' => $this, - 'sql' => $sql, - 'table' => $main_table, - 'action' => $action, - 'id' => $this->params['main_id'], - 'yform' => true, - ], - )); } } diff --git a/lib/yform/action/db_query.php b/lib/Action/DbQuery.php similarity index 85% rename from lib/yform/action/db_query.php rename to lib/Action/DbQuery.php index 8765151b5..652809dc5 100644 --- a/lib/yform/action/db_query.php +++ b/lib/Action/DbQuery.php @@ -1,13 +1,11 @@ www.yakamara.de - */ - -class rex_yform_action_db_query extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use Exception; +use rex_sql; + +class DbQuery extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/email.php b/lib/Action/Email.php similarity index 89% rename from lib/yform/action/email.php rename to lib/Action/Email.php index b848c05af..012bbdb37 100644 --- a/lib/yform/action/email.php +++ b/lib/Action/Email.php @@ -1,13 +1,12 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Action; -class rex_yform_action_email extends rex_yform_action_abstract +use rex_mailer; + +use function is_array; + +class Email extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/encrypt_value.php b/lib/Action/EncryptValue.php similarity index 74% rename from lib/yform/action/encrypt_value.php rename to lib/Action/EncryptValue.php index f35081503..2adeb0445 100644 --- a/lib/yform/action/encrypt_value.php +++ b/lib/Action/EncryptValue.php @@ -1,20 +1,18 @@ www.yakamara.de - */ - -class rex_yform_action_encrypt_value extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use function function_exists; +use function in_array; + +class EncryptValue extends AbstractAction { public function executeAction(): void { $f = $this->getElement(3); // the function if (!function_exists($f)) { $f = 'md5'; - } // default func = md5 + } // Labels to get $l = explode(',', $this->getElement(2)); @@ -28,7 +26,6 @@ public function executeAction(): void return; } - // $this->params["value_pool"]["sql"] = Array for database $k = ''; foreach ($this->params['value_pool']['sql'] as $key => $value) { if (in_array($key, $l)) { diff --git a/lib/yform/action/html.php b/lib/Action/Html.php similarity index 53% rename from lib/yform/action/html.php rename to lib/Action/Html.php index 7a2975e06..af62ae342 100644 --- a/lib/yform/action/html.php +++ b/lib/Action/Html.php @@ -1,13 +1,8 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Action; -class rex_yform_action_html extends rex_yform_action_abstract +class Html extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/manage_db.php b/lib/Action/ManageDb.php similarity index 70% rename from lib/yform/action/manage_db.php rename to lib/Action/ManageDb.php index d9c54f5a7..ea88187e3 100644 --- a/lib/yform/action/manage_db.php +++ b/lib/Action/ManageDb.php @@ -1,34 +1,16 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Action; -class rex_yform_action_manage_db extends rex_yform_action_abstract +use rex_sql; + +class ManageDb extends AbstractAction { public function executeAction(): void { - // START - Spezialfall "be_em_relation" - /* - $be_em_table_field = ""; - if($this->params["value_pool"]["sql"]["type_name"] == "be_em_relation") - { - $be_em_table_field = $this->params["value_pool"]["sql"]["f1"]; - $this->params["value_pool"]["sql"]["f1"] = $this->params["value_pool"]["sql"]["f3"]."_".$this->params["value_pool"]["sql"]["f1"]; - } - */ - // ENDE - Spezialfall - - // ********************************* TABLE A - - // $this->params["debug"]= TRUE; $sql = rex_sql::factory(); $sql->setDebug($this->params['debug']); - $main_table = ''; if ('' != $this->getElement(2)) { $main_table = $this->getElement(2); } else { @@ -76,15 +58,12 @@ public function executeAction(): void if ('' != $where) { $sql->setWhere($where); $sql->update(); - $flag = 'update'; } else { $sql->insert(); - $flag = 'insert'; $id = $sql->getLastId(); $this->params['value_pool']['email']['ID'] = $id; $this->params['main_id'] = $id; - // $this->params["value_pool"]["sql"]["ID"] = $id; if (0 == $id) { $this->params['form_show'] = true; $this->params['hasWarnings'] = true; diff --git a/lib/yform/action/php.php b/lib/Action/Php.php similarity index 82% rename from lib/yform/action/php.php rename to lib/Action/Php.php index 8679242b3..8f085f6cf 100644 --- a/lib/yform/action/php.php +++ b/lib/Action/Php.php @@ -1,6 +1,8 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Action; -class rex_yform_action_readtable extends rex_yform_action_abstract +use rex_sql; + +use function count; + +class ReadTable extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/redirect.php b/lib/Action/Redirect.php similarity index 86% rename from lib/yform/action/redirect.php rename to lib/Action/Redirect.php index f783f7309..04ca935a2 100644 --- a/lib/yform/action/redirect.php +++ b/lib/Action/Redirect.php @@ -1,13 +1,11 @@ www.yakamara.de - */ - -class rex_yform_action_redirect extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use function count; +use function is_array; + +class Redirect extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/showtext.php b/lib/Action/ShowText.php similarity index 78% rename from lib/yform/action/showtext.php rename to lib/Action/ShowText.php index aa14a313a..a976e05da 100644 --- a/lib/yform/action/showtext.php +++ b/lib/Action/ShowText.php @@ -1,13 +1,12 @@ www.yakamara.de - */ - -class rex_yform_action_showtext extends rex_yform_action_abstract +namespace Yakamara\YForm\Action; + +use rex_i18n; + +use function is_scalar; + +class ShowText extends AbstractAction { public function executeAction(): void { diff --git a/lib/yform/action/tpl2email.php b/lib/Action/Tpl2Email.php similarity index 75% rename from lib/yform/action/tpl2email.php rename to lib/Action/Tpl2Email.php index c0a80356c..86840c53f 100644 --- a/lib/yform/action/tpl2email.php +++ b/lib/Action/Tpl2Email.php @@ -1,18 +1,21 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Action; -class rex_yform_action_tpl2email extends rex_yform_action_abstract +use rex; +use rex_path; +use Yakamara\YForm\Email\Template; + +use function is_array; + +use const FILTER_VALIDATE_EMAIL; + +class Tpl2Email extends AbstractAction { public function executeAction(): void { $template_name = $this->getElement(2); - if ($etpl = rex_yform_email_template::getTemplate($template_name)) { + if ($etpl = Template::getTemplate($template_name)) { $email_to = rex::getErrorEmail(); if (filter_var($this->getElement(3), FILTER_VALIDATE_EMAIL)) { @@ -29,19 +32,11 @@ public function executeAction(): void $email_to_name = $this->getElement(4); $warning_message = $this->getElement(5); - // BC - if ('' == $this->getElement(3) && filter_var($this->getElement(4), FILTER_VALIDATE_EMAIL)) { - $email_to = $this->getElement(4); - $email_to_name = $this->getElement(5); - $warning_message = $this->getElement(6); - } - // End BC - if ($this->params['debug']) { dump($etpl); } - $etpl = rex_yform_email_template::replaceVars($etpl, $this->params['value_pool']['email']); + $etpl = Template::replaceVars($etpl, $this->params['value_pool']['email']); $etpl['mail_to'] = $email_to; $etpl['mail_to_name'] = $email_to_name; @@ -66,7 +61,7 @@ public function executeAction(): void dump($etpl); } - if (!rex_yform_email_template::sendMail($etpl, $template_name)) { + if (!Template::sendMail($etpl, $template_name)) { if ($this->params['debug']) { dump('email could not be sent'); } @@ -83,7 +78,6 @@ public function executeAction(): void if ($this->params['debug']) { dump('Template: "' . rex_escape($template_name) . '" not found'); } - } public function getDescription(): string 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/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/list.php b/lib/List/List.php similarity index 95% rename from lib/list.php rename to lib/List/List.php index ed4918041..14e508519 100644 --- a/lib/list.php +++ b/lib/List/List.php @@ -1,21 +1,40 @@ |callable(self):string */ + /** @psalm-var array|callable(\Yakamara\YForm\List\YList):string */ private $rowAttributes; // --------- Column Attributes @@ -80,12 +99,12 @@ class rex_yform_list 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) { @@ -171,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 @@ -193,9 +212,8 @@ public function init() } // ---------------------- setters/getters - /** - * @return rex_yform_manager_query + * @return Query */ public function getQuery() { @@ -203,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; @@ -339,11 +357,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 +371,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 +546,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 +997,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 +1139,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 @@ getTableName(), $fieldName, ['id' => $valueId]); + $listValues = BackendManagerRelation::getListValues($table->getTableName(), $fieldName, ['id' => $valueId]); if (isset($listValues[$valueId])) { $options[] = ['id' => $valueId, 'name' => rex_formatter::truncate($listValues[$valueId] . ' id=[' . $valueId . ']', ['length' => 50])]; $values[] = $valueId; @@ -65,7 +78,7 @@ protected function getOutput() $value = self::getMultipleWidget($id, 'REX_INPUT_VALUE[' . $id . ']', $value, $args); } else { $valueName = ''; - $listValues = rex_yform_value_be_manager_relation::getListValues($table->getTableName(), $fieldName, ['id' => $value]); + $listValues = BackendManagerRelation::getListValues($table->getTableName(), $fieldName, ['id' => $value]); if (isset($listValues[$value])) { $valueName = rex_formatter::truncate($listValues[$value], ['length' => 50]); } @@ -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/lib/yform/validate/abstract.php b/lib/Validate/AbstractValidate.php similarity index 82% rename from lib/yform/validate/abstract.php rename to lib/Validate/AbstractValidate.php index 378635596..97be992da 100644 --- a/lib/yform/validate/abstract.php +++ b/lib/Validate/AbstractValidate.php @@ -1,13 +1,11 @@ www.yakamara.de - */ - -abstract class rex_yform_validate_abstract extends rex_yform_base_abstract +namespace Yakamara\YForm\Validate; + +use rex_addon; +use Yakamara\YForm\AbstractBase; + +abstract class AbstractValidate extends AbstractBase { public $validateObjects = []; diff --git a/lib/yform/validate/compare.php b/lib/Validate/Compare.php similarity index 93% rename from lib/yform/validate/compare.php rename to lib/Validate/Compare.php index 9c013f110..d57d68b78 100644 --- a/lib/yform/validate/compare.php +++ b/lib/Validate/Compare.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Validate; -class rex_yform_validate_compare extends rex_yform_validate_abstract +use rex_i18n; + +class Compare extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/compare_value.php b/lib/Validate/CompareValue.php similarity index 92% rename from lib/yform/validate/compare_value.php rename to lib/Validate/CompareValue.php index b82de3891..657312920 100644 --- a/lib/yform/validate/compare_value.php +++ b/lib/Validate/CompareValue.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Validate; -class rex_yform_validate_compare_value extends rex_yform_validate_abstract +use rex_i18n; + +class CompareValue extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/customfunction.php b/lib/Validate/CustomFunction.php similarity index 94% rename from lib/yform/validate/customfunction.php rename to lib/Validate/CustomFunction.php index ef7cd1009..3b3830435 100644 --- a/lib/yform/validate/customfunction.php +++ b/lib/Validate/CustomFunction.php @@ -1,13 +1,16 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Validate; -class rex_yform_validate_customfunction extends rex_yform_validate_abstract +use rex_i18n; + +use function call_user_func; +use function count; +use function is_array; +use function is_callable; +use function is_string; + +class CustomFunction extends AbstractValidate { public function customfunction_execute() { diff --git a/lib/yform/validate/in_names.php b/lib/Validate/InNames.php similarity index 85% rename from lib/yform/validate/in_names.php rename to lib/Validate/InNames.php index e6735d4ce..38292a53f 100644 --- a/lib/yform/validate/in_names.php +++ b/lib/Validate/InNames.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_validate_in_names extends rex_yform_validate_abstract +namespace Yakamara\YForm\Validate; + +use function in_array; + +class InNames extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/in_table.php b/lib/Validate/InTable.php similarity index 90% rename from lib/yform/validate/in_table.php rename to lib/Validate/InTable.php index e81841f8e..87165e755 100644 --- a/lib/yform/validate/in_table.php +++ b/lib/Validate/InTable.php @@ -1,13 +1,14 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Validate; -class rex_yform_validate_in_table extends rex_yform_validate_abstract +use rex_sql; + +use function count; +use function in_array; +use function is_array; + +class InTable extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/intfromto.php b/lib/Validate/IntFromTo.php similarity index 87% rename from lib/yform/validate/intfromto.php rename to lib/Validate/IntFromTo.php index df9619cf7..f5dd86e74 100644 --- a/lib/yform/validate/intfromto.php +++ b/lib/Validate/IntFromTo.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_validate_intfromto extends rex_yform_validate_abstract +namespace Yakamara\YForm\Validate; + +use rex_i18n; + +class IntFromTo extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/empty.php b/lib/Validate/IsEmpty.php similarity index 88% rename from lib/yform/validate/empty.php rename to lib/Validate/IsEmpty.php index a568077ac..3a92fddd4 100644 --- a/lib/yform/validate/empty.php +++ b/lib/Validate/IsEmpty.php @@ -1,13 +1,12 @@ www.yakamara.de - */ - -class rex_yform_validate_empty extends rex_yform_validate_abstract +namespace Yakamara\YForm\Validate; + +use rex_i18n; + +use function in_array; + +class IsEmpty extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/password_policy.php b/lib/Validate/PasswordPolicy.php similarity index 91% rename from lib/yform/validate/password_policy.php rename to lib/Validate/PasswordPolicy.php index b2dc98b0b..04f5a20f1 100644 --- a/lib/yform/validate/password_policy.php +++ b/lib/Validate/PasswordPolicy.php @@ -1,6 +1,14 @@ www.yakamara.de - */ - -class rex_yform_validate_preg_match extends rex_yform_validate_abstract +namespace Yakamara\YForm\Validate; + +use rex_i18n; + +use function count; + +class PregMatch extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/size.php b/lib/Validate/Size.php similarity index 85% rename from lib/yform/validate/size.php rename to lib/Validate/Size.php index 5ec90e62c..67d96ffbc 100644 --- a/lib/yform/validate/size.php +++ b/lib/Validate/Size.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_validate_size extends rex_yform_validate_abstract +namespace Yakamara\YForm\Validate; + +use rex_i18n; + +class Size extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/size_range.php b/lib/Validate/SizeRange.php similarity index 88% rename from lib/yform/validate/size_range.php rename to lib/Validate/SizeRange.php index 1c93a5245..9e07ab30b 100644 --- a/lib/yform/validate/size_range.php +++ b/lib/Validate/SizeRange.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Validate; -class rex_yform_validate_size_range extends rex_yform_validate_abstract +use rex_i18n; + +class SizeRange extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/type.php b/lib/Validate/Type.php similarity index 97% rename from lib/yform/validate/type.php rename to lib/Validate/Type.php index 371aec750..965d099e5 100644 --- a/lib/yform/validate/type.php +++ b/lib/Validate/Type.php @@ -1,13 +1,15 @@ www.yakamara.de - */ - -class rex_yform_validate_type extends rex_yform_validate_abstract +namespace Yakamara\YForm\Validate; + +use DateTime; +use rex_i18n; + +use function function_exists; + +use const JSON_ERROR_NONE; + +class Type extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/validate/unique.inc.php b/lib/Validate/Unique.php similarity index 93% rename from lib/yform/validate/unique.inc.php rename to lib/Validate/Unique.php index b64a7e653..43dc13037 100644 --- a/lib/yform/validate/unique.inc.php +++ b/lib/Validate/Unique.php @@ -1,13 +1,15 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Validate; -class rex_yform_validate_unique extends rex_yform_validate_abstract +use rex_i18n; +use rex_sql; + +use function count; +use function in_array; +use function is_array; + +class Unique extends AbstractValidate { public function enterObject() { diff --git a/lib/yform/value/abstract.php b/lib/Value/AbstractValue.php similarity index 95% rename from lib/yform/value/abstract.php rename to lib/Value/AbstractValue.php index 278a619f6..0f59ab0b2 100644 --- a/lib/yform/value/abstract.php +++ b/lib/Value/AbstractValue.php @@ -1,13 +1,15 @@ www.yakamara.de - */ - -abstract class rex_yform_value_abstract extends rex_yform_base_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; +use Yakamara\YForm\AbstractBase; +use Yakamara\YForm\YForm; + +use function in_array; +use function is_array; + +abstract class AbstractValue extends AbstractBase { public $element_values = []; @@ -252,11 +254,6 @@ public function getDatabaseFieldTypes() $definitions = $this->getDefinitions(); $db_types = []; - // deprecated - if (isset($definitions['dbtype'])) { - $definitions['db_type'] = [$definitions['dbtype']]; - } - if (!isset($definitions['db_type'])) { $definitions['db_type'] = []; } elseif (!is_array($definitions['db_type'])) { @@ -312,7 +309,7 @@ public function canView(bool $viewable = true) public function isEditable() { - /** @var rex_yform $yform */ + /** @var YForm $yform */ $yform = $this->params['this']; if (!$yform->isEditable()) { return false; @@ -326,7 +323,7 @@ public function isEditable() public function isViewable() { - /** @var rex_yform $yform */ + /** @var YForm $yform */ $yform = $this->params['this']; if (!$yform->isViewable()) { return false; diff --git a/lib/yform/value/article.php b/lib/Value/Article.php similarity index 65% rename from lib/yform/value/article.php rename to lib/Value/Article.php index 1153697df..94210ed84 100644 --- a/lib/yform/value/article.php +++ b/lib/Value/Article.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_article extends rex_yform_value_abstract +use rex_article_content; + +class Article extends AbstractValue { public function enterObject() { diff --git a/lib/yform/value/be_link.php b/lib/Value/BackendLink.php similarity index 78% rename from lib/yform/value/be_link.php rename to lib/Value/BackendLink.php index eaaab9d15..73161a65a 100644 --- a/lib/yform/value/be_link.php +++ b/lib/Value/BackendLink.php @@ -1,13 +1,22 @@ www.yakamara.de - */ - -class rex_yform_value_be_link extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_api_function; +use rex_extension; +use rex_extension_point; +use rex_i18n; +use rex_sql; +use rex_view; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Query; +use Yakamara\YForm\Manager\Table\Table; + +use function array_slice; +use function count; +use function in_array; + +class BackendLink extends AbstractValue { public function enterObject() { @@ -72,19 +81,19 @@ public static function getListValue($params) public static function isArticleInUse(rex_extension_point $ep) { - $rexApiCall = rex_request(\rex_api_function::REQ_CALL_PARAM, 'string', ''); + $rexApiCall = rex_request(rex_api_function::REQ_CALL_PARAM, 'string', ''); if ('category_delete' == $rexApiCall || 'article_delete' == $rexApiCall) { $id = ('category_delete' == $rexApiCall) ? rex_request('category-id', 'int', 0) : rex_request('article_id', 'int', 0); $article = \rex_article::get($id); if ($article) { - $sql = \rex_sql::factory(); - $sql->setQuery('SELECT * FROM `' . \rex_yform_manager_field::table() . '` LIMIT 0'); + $sql = rex_sql::factory(); + $sql->setQuery('SELECT * FROM `' . 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 = \rex_extension::registerPoint(new \rex_extension_point('YFORM_ARTICLE_IS_IN_USE', $fields)); + $fields = $sql->getArray('SELECT `table_name`, `name`' . $select . ' FROM `' . 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)) { $tables = []; @@ -102,8 +111,8 @@ public static function isArticleInUse(rex_extension_point $ep) $items = $sql->getArray('SELECT `id` FROM ' . $tableName . ' WHERE ' . implode(' OR ', $conditions)); 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 = rex_sql::factory(); + $sqlData->setQuery('SELECT `name` FROM `' . Table::table() . '` WHERE `table_name` = "' . $tableName . '"'); $url = rex_yform_manager::url($tableName, $item['id']); $messages .= '
  • ' . $sqlData->getValue('name') . ' [id=' . $item['id'] . ']
  • '; } @@ -111,13 +120,13 @@ public static function isArticleInUse(rex_extension_point $ep) } if ('' != $messages) { - $_REQUEST[\rex_api_function::REQ_CALL_PARAM] = ''; + $_REQUEST[rex_api_function::REQ_CALL_PARAM] = ''; - \rex_extension::register('PAGE_TITLE_SHOWN', static function (rex_extension_point $ep) use ($article, $messages) { - $warning = $article->isStartArticle() ? \rex_i18n::msg('yform_structure_category_could_not_be_deleted') : \rex_i18n::msg('yform_structure_article_could_not_be_deleted'); + rex_extension::register('PAGE_TITLE_SHOWN', static function (rex_extension_point $ep) use ($article, $messages) { + $warning = $article->isStartArticle() ? rex_i18n::msg('yform_structure_category_could_not_be_deleted') : rex_i18n::msg('yform_structure_article_could_not_be_deleted'); $warning .= '
      ' . $messages . '
    '; $subject = $ep->getSubject(); - $ep->setSubject(\rex_view::error($warning) . $subject); + $ep->setSubject(rex_view::error($warning) . $subject); }); } } @@ -139,7 +148,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var 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/Value/BackendManagerRelation.php similarity index 95% rename from lib/yform/value/be_manager_relation.php rename to lib/Value/BackendManagerRelation.php index e6af2a6c5..2aba38caa 100644 --- a/lib/yform/value/be_manager_relation.php +++ b/lib/Value/BackendManagerRelation.php @@ -1,13 +1,12 @@ www.yakamara.de - */ - -class rex_yform_value_be_manager_relation extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex; +use rex_i18n; +use rex_sql; + +class BackendManagerRelation extends \Yakamara\YForm\Value\AbstractValue { public static $yform_list_values = []; @@ -170,7 +169,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 +197,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 +254,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 +295,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 +355,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 +363,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 +507,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 +519,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 +596,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 +703,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 +814,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 +835,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 +870,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/Value/BackendMedia.php similarity index 85% rename from lib/yform/value/be_media.php rename to lib/Value/BackendMedia.php index ef34e5d4b..3a6025ed8 100644 --- a/lib/yform/value/be_media.php +++ b/lib/Value/BackendMedia.php @@ -1,13 +1,22 @@ www.yakamara.de - */ - -class rex_yform_value_be_media extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_extension; +use rex_extension_point; +use rex_i18n; +use rex_media; +use rex_sql; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Manager; +use Yakamara\YForm\Manager\Table\Table; + +use function array_slice; +use function count; +use function in_array; +use function is_string; + +class BackendMedia extends AbstractValue { public function enterObject() { @@ -98,12 +107,12 @@ public static function getListValue($params) public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function isMediaInUse(rex_extension_point $ep) @@ -111,14 +120,14 @@ public static function isMediaInUse(rex_extension_point $ep) $params = $ep->getParams(); $warning = $ep->getSubject(); - $sql = \rex_sql::factory(); - $sql->setQuery('SELECT * FROM `' . \rex_yform_manager_field::table() . '` LIMIT 0'); + $sql = rex_sql::factory(); + $sql->setQuery('SELECT * FROM `' . 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 = \rex_extension::registerPoint(new \rex_extension_point('YFORM_MEDIA_IS_IN_USE', $fields)); + $fields = $sql->getArray('SELECT `table_name`, `name`' . $select . ' FROM `' . 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)) { return $warning; @@ -141,9 +150,9 @@ public static function isMediaInUse(rex_extension_point $ep) $items = $sql->getArray('SELECT `id` FROM ' . $tableName . ' WHERE ' . implode(' OR ', $conditions)); 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 . '"'); - $editUrl = rex_yform_manager::url($tableName, $item['id']); + $sqlData = rex_sql::factory(); + $sqlData->setQuery('SELECT `name` FROM `' . Table::table() . '` WHERE `table_name` = "' . $tableName . '"'); + $editUrl = Manager::url($tableName, $item['id']); $messages .= '
  • ' . $sqlData->getValue('name') . ' [id=' . $item['id'] . ']
  • '; } } diff --git a/lib/yform/value/be_table.php b/lib/Value/BackendTable.php similarity index 95% rename from lib/yform/value/be_table.php rename to lib/Value/BackendTable.php index 9a63bf378..2f4e5c84b 100644 --- a/lib/yform/value/be_table.php +++ b/lib/Value/BackendTable.php @@ -1,6 +1,14 @@ $col) { // Use ;; for separating choice columns instead of , - $values = explode('|', trim(trim(str_replace(';;', ',', rex_yform::unhtmlentities($col))), '|')); + $values = explode('|', trim(trim(str_replace(';;', ',', YForm::unhtmlentities($col))), '|')); if (1 == count($values)) { $values = ['text', 'text_' . $index, $values[0]]; } @@ -79,8 +87,8 @@ public function enterObject() $this->fieldData = $data; - $yfparams = rex_yform::factory()->objparams; - $yfparams['this'] = rex_yform::factory(); + $yfparams = YForm::factory()->objparams; + $yfparams['this'] = YForm::factory(); /* TODO * error class von validierung ans Eingabefeld übergeben diff --git a/lib/yform/value/be_user.php b/lib/Value/BackendUser.php similarity index 93% rename from lib/yform/value/be_user.php rename to lib/Value/BackendUser.php index be91d5062..531a80fab 100644 --- a/lib/yform/value/be_user.php +++ b/lib/Value/BackendUser.php @@ -1,13 +1,11 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_be_user extends rex_yform_value_abstract +use rex; +use rex_i18n; + +class BackendUser extends AbstractValue { public function enterObject() { diff --git a/lib/yform/value/checkbox.php b/lib/Value/Checkbox.php similarity index 90% rename from lib/yform/value/checkbox.php rename to lib/Value/Checkbox.php index 11d97d0fe..02ea5e413 100644 --- a/lib/yform/value/checkbox.php +++ b/lib/Value/Checkbox.php @@ -1,13 +1,14 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_checkbox extends rex_yform_value_abstract +use rex_i18n; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Query; + +use function count; + +class Checkbox extends AbstractValue { public function enterObject() { @@ -59,7 +60,7 @@ public function getDefinitions(): array 'db_type' => ['tinyint(1)'], 'famous' => true, 'hooks' => [ - 'preDefault' => static function (rex_yform_manager_field $field) { + 'preDefault' => static function (Field $field) { return (1 == $field->getElement('default')) ? '1' : '0'; }, ], @@ -82,10 +83,10 @@ public static function getSearchField($params) ]); } - public static function getSearchFilter($params): rex_yform_manager_query + public static function getSearchFilter($params): Query { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/choice.php b/lib/Value/Choice.php similarity index 96% rename from lib/yform/value/choice.php rename to lib/Value/Choice.php index cb23bcd58..ead0d1dd0 100644 --- a/lib/yform/value/choice.php +++ b/lib/Value/Choice.php @@ -1,12 +1,23 @@ www.yakamara.de - */ - -class rex_yform_value_choice extends rex_yform_value_abstract + +namespace Yakamara\YForm\Value; + +use InvalidArgumentException; +use rex_i18n; +use rex_sql; +use Yakamara\YForm\Choice\ChoiceList; +use Yakamara\YForm\Choice\GroupView; +use Yakamara\YForm\Choice\View; +use Yakamara\YForm\Manager\Query; + +use function call_user_func; +use function count; +use function in_array; +use function is_array; +use function is_callable; +use function is_string; + +class Choice extends AbstractValue { public static $yform_list_values = []; @@ -88,10 +99,10 @@ 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 */ + /* @var View $choice */ $options[$choice->getValue()] = $choice->getLabel(); } } @@ -253,7 +264,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); @@ -321,7 +332,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/lib/yform/value/csrf.php b/lib/Value/Csrf.php similarity index 91% rename from lib/yform/value/csrf.php rename to lib/Value/Csrf.php index 04297cb29..6d6a5d80c 100644 --- a/lib/yform/value/csrf.php +++ b/lib/Value/Csrf.php @@ -1,13 +1,12 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_csrf extends rex_yform_value_abstract +use rex; +use rex_csrf_token; +use rex_i18n; + +class Csrf extends AbstractValue { public function preValidateAction(): void { diff --git a/lib/yform/value/date.php b/lib/Value/Date.php similarity index 97% rename from lib/yform/value/date.php rename to lib/Value/Date.php index dbb3fa729..acc60a069 100644 --- a/lib/yform/value/date.php +++ b/lib/Value/Date.php @@ -1,13 +1,17 @@ www.yakamara.de - */ - -class rex_yform_value_date extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use DateTime; +use rex_i18n; +use Yakamara\YForm\Manager\Query; + +use function in_array; +use function is_array; + +use const STR_PAD_LEFT; + +class Date extends AbstractValue { public const VALUE_DATE_DEFAULT_FORMAT = 'Y-m-d'; public const VALUE_DATE_FORMATS = ['d.m.Y' => 'd.m.Y', 'Y-m-d' => 'Y-m-d', 'd-m-Y' => 'd-m-Y', 'm-d-Y' => 'm-d-Y', 'Y' => 'Y', 'm' => 'm', 'm-Y' => 'm-Y', 'Y-m' => 'Y-m']; @@ -89,13 +93,13 @@ public function enterObject() if ('+' == mb_substr($this->getElement('year_end'), 0, 1)) { $add_years = (int) mb_substr($this->getElement('year_end'), 1); - $yearEnd = date('Y') + $add_years; + $yearEnd = (int) date('Y') + $add_years; } else { $yearEnd = (int) $this->getElement('year_end'); } if ($yearEnd < $yearStart) { - $yearEnd = date('Y') + 10; + $yearEnd = (int) date('Y') + 10; } if (!$this->isEditable()) { @@ -180,7 +184,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/datestamp.php b/lib/Value/DateStamp.php similarity index 82% rename from lib/yform/value/datestamp.php rename to lib/Value/DateStamp.php index 4358b8893..85d7a4dad 100644 --- a/lib/yform/value/datestamp.php +++ b/lib/Value/DateStamp.php @@ -1,13 +1,13 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_datestamp extends rex_yform_value_abstract +use DateTime; +use rex; +use rex_i18n; +use rex_sql; + +class DateStamp extends AbstractValue { private string $value_datestamp_currentValue = ''; @@ -65,7 +65,7 @@ public function enterObject() ['value.datestamp-view.tpl.php', 'value.datetime-view.tpl.php', 'value.date-view.tpl.php', 'value.view.tpl.php'], [ 'type' => 'text', - 'value' => ('' != $this->value_datestamp_currentValue) ? rex_yform_value_datetime::datetime_getFormattedDatetime($this->getElement('format'), $this->value_datestamp_currentValue) : '', + 'value' => ('' != $this->value_datestamp_currentValue) ? \Yakamara\YForm\Value\DateTime::datetime_getFormattedDatetime($this->getElement('format'), $this->value_datestamp_currentValue) : '', 'notice' => $notice, ], ); @@ -74,7 +74,7 @@ public function enterObject() ['value.datestamp-view.tpl.php', 'value.datetime-view.tpl.php', 'value.date-view.tpl.php', 'value.view.tpl.php'], [ 'type' => 'text', - 'value' => rex_yform_value_datetime::datetime_getFormattedDatetime($this->getElement('format'), $this->value_datestamp_currentValue), + 'value' => \Yakamara\YForm\Value\DateTime::datetime_getFormattedDatetime($this->getElement('format'), $this->value_datestamp_currentValue), ], ); } @@ -96,7 +96,7 @@ public function getDefinitions(): array 'values' => [ 'name' => ['type' => 'name', 'label' => rex_i18n::msg('yform_values_defaults_name')], 'label' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_defaults_label')], - 'format' => ['type' => 'choice', 'label' => rex_i18n::msg('yform_values_datetime_format'), 'choices' => rex_yform_value_datetime::VALUE_DATETIME_FORMATS, 'default' => rex_yform_value_datetime::VALUE_DATETIME_DEFAULT_FORMAT, 'notice' => rex_i18n::msg('yform_values_format_show_notice')], + 'format' => ['type' => 'choice', 'label' => rex_i18n::msg('yform_values_datetime_format'), 'choices' => \Yakamara\YForm\Value\DateTime::VALUE_DATETIME_FORMATS, 'default' => \Yakamara\YForm\Value\DateTime::VALUE_DATETIME_DEFAULT_FORMAT, 'notice' => rex_i18n::msg('yform_values_format_show_notice')], 'no_db' => ['type' => 'no_db', 'label' => rex_i18n::msg('yform_values_defaults_table'), 'default' => 0], 'only_empty' => ['type' => 'choice', 'label' => rex_i18n::msg('yform_values_datestamp_only_empty'), 'default' => '0', 'choices' => 'translate:yform_always=0,translate:yform_onlyifempty=1,translate:yform_never=2'], 'modify_default' => ['type' => 'text', 'label' => rex_i18n::msg('yform_values_date_modify_default'), 'notice' => rex_i18n::msg('yform_values_date_modify_default_notics')], @@ -109,16 +109,16 @@ public function getDefinitions(): array public static function getListValue($params) { - return rex_yform_value_datetime::getListValue($params); + return \Yakamara\YForm\Value\DateTime::getListValue($params); } public static function getSearchField($params) { - rex_yform_value_datetime::getSearchField($params); + \Yakamara\YForm\Value\DateTime::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_datetime::getSearchFilter($params); + return \Yakamara\YForm\Value\DateTime::getSearchFilter($params); } } diff --git a/lib/yform/value/datetime.php b/lib/Value/DateTime.php similarity index 95% rename from lib/yform/value/datetime.php rename to lib/Value/DateTime.php index 2e8686518..1edd60728 100644 --- a/lib/yform/value/datetime.php +++ b/lib/Value/DateTime.php @@ -1,13 +1,16 @@ www.yakamara.de - */ - -class rex_yform_value_datetime extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; +use rex_sql; +use Yakamara\YForm\Manager\Query; + +use function count; +use function in_array; +use function is_array; + +class DateTime extends AbstractValue { public const VALUE_DATETIME_DEFAULT_FORMAT = 'Y-m-d H:i:s'; public const VALUE_DATETIME_FORMATS = ['d.m.Y H:i:s' => 'd.m.Y H:i:s', 'Y-m-d H:i:s' => 'Y-m-d H:i:s', 'd-m-Y H:i:s' => 'd-m-Y H:i:s', 'm-d-Y H:i:s' => 'm-d-Y H:i:s', 'm-Y H:i:s' => 'm-Y H:i:s', 'Y-m H:i:s' => 'Y-m H:i:s', 'd-m H:i:s' => 'd-m H:i:s', 'm-d H:i:s' => 'm-d H:i:s', 'Y' => 'Y', 'Y-m' => 'Y-m']; @@ -20,7 +23,7 @@ public function preValidateAction(): void $value = date(rex_sql::FORMAT_DATETIME); } if ('' != $this->getElement('modify_default')) { - $dt = new DateTime(); + $dt = new \DateTime(); if (false !== $dt->modify($this->getElement('modify_default'))) { $value = $dt->format(rex_sql::FORMAT_DATETIME); } @@ -99,7 +102,7 @@ public function enterObject() if ('+' == mb_substr($this->getElement('year_end'), 0, 1)) { $add_years = (int) mb_substr($this->getElement('year_end'), 1); - $yearEnd = date('Y') + $add_years; + $yearEnd = (int) date('Y') + $add_years; } elseif ('' != $this->getElement('year_end')) { $yearEnd = (int) $this->getElement('year_end'); } else { @@ -138,7 +141,7 @@ public function enterObject() public static function datetime_getFormattedDatetime($format, $date) { $format = (in_array($format, self::VALUE_DATETIME_FORMATS, true)) ? $format : self::VALUE_DATETIME_DEFAULT_FORMAT; - $DTdate = DateTime::createFromFormat('Y-m-d H:i:s', $date); + $DTdate = \DateTime::createFromFormat('Y-m-d H:i:s', $date); return (!$date || !$DTdate || $date != $DTdate->format('Y-m-d H:i:s')) ? '[' . $date . ']' : $DTdate->format($format); } @@ -188,7 +191,7 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var Query $query */ $query = $params['query']; $field = $query->getTableAlias() . '.' . $params['field']->getName(); diff --git a/lib/yform/value/email.php b/lib/Value/Email.php similarity index 87% rename from lib/yform/value/email.php rename to lib/Value/Email.php index 1e04d24d0..30781ac00 100644 --- a/lib/yform/value/email.php +++ b/lib/Value/Email.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_email extends rex_yform_value_abstract +use rex_i18n; + +class Email extends AbstractValue { public function enterObject() { @@ -64,16 +61,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/value/emptyname.php b/lib/Value/EmptyName.php similarity index 82% rename from lib/yform/value/emptyname.php rename to lib/Value/EmptyName.php index d933d9d73..ce3a7e8ba 100644 --- a/lib/yform/value/emptyname.php +++ b/lib/Value/EmptyName.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_emptyname extends rex_yform_value_abstract +use rex_i18n; + +class EmptyName extends AbstractValue { public function enterObject() { @@ -54,16 +51,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/value/fieldset.php b/lib/Value/Fieldset.php similarity index 87% rename from lib/yform/value/fieldset.php rename to lib/Value/Fieldset.php index 34bab36c6..f5092bae2 100644 --- a/lib/yform/value/fieldset.php +++ b/lib/Value/Fieldset.php @@ -1,13 +1,13 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_fieldset extends rex_yform_value_abstract +use rex_i18n; + +use function in_array; +use function is_array; + +class Fieldset extends AbstractValue { public static $fieldset_options = ['onlyclose' => 'onlyclose', 'onlycloseall' => 'onlycloseall', 'onlyopen' => 'onlyopen', 'closeandopen' => 'closeandopen']; @@ -27,12 +27,6 @@ public function enterObject() $attributes = $this->getElement('attributes'); $attributes = json_decode($attributes, true); - // deprecated - // BC yform < Version 4 - if ('' != $this->getElement('attributes') && !is_array($attributes)) { - $attributes['class'] = $this->getElement('attributes'); - } - $this->setElement('attributes', $attributes); switch ($option) { diff --git a/lib/yform/value/generate_key.php b/lib/Value/GenerateKey.php similarity index 91% rename from lib/yform/value/generate_key.php rename to lib/Value/GenerateKey.php index 2dd960587..2e57b165e 100644 --- a/lib/yform/value/generate_key.php +++ b/lib/Value/GenerateKey.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_value_generate_key extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; + +class GenerateKey extends \Yakamara\YForm\Value\AbstractValue { public function preValidateAction(): void { diff --git a/lib/yform/value/google_geocode.php b/lib/Value/GoogleGeoCode.php similarity index 97% rename from lib/yform/value/google_geocode.php rename to lib/Value/GoogleGeoCode.php index ac1ad5c0b..78d3a81f2 100644 --- a/lib/yform/value/google_geocode.php +++ b/lib/Value/GoogleGeoCode.php @@ -1,6 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_hashvalue extends rex_yform_value_abstract +use rex_i18n; + +use function function_exists; + +class HashValue extends AbstractValue { public function postFormAction(): void { @@ -59,16 +58,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/value/hidden.php b/lib/Value/Hidden.php similarity index 88% rename from lib/yform/value/hidden.php rename to lib/Value/Hidden.php index a848d40fb..3c4b93410 100644 --- a/lib/yform/value/hidden.php +++ b/lib/Value/Hidden.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_hidden extends rex_yform_value_abstract +use function in_array; + +class Hidden extends AbstractValue { public function setValue($value) { diff --git a/lib/yform/value/html.php b/lib/Value/Html.php similarity index 86% rename from lib/yform/value/html.php rename to lib/Value/Html.php index a095e25e2..4cdc342c0 100644 --- a/lib/yform/value/html.php +++ b/lib/Value/Html.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_value_html extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; + +class Html extends AbstractValue { public function enterObject() { diff --git a/lib/yform/value/ip.php b/lib/Value/IP.php similarity index 80% rename from lib/yform/value/ip.php rename to lib/Value/IP.php index ca9e0b77e..f7835644f 100644 --- a/lib/yform/value/ip.php +++ b/lib/Value/IP.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_value_ip extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; + +class IP extends AbstractValue { public function enterObject() { @@ -44,16 +41,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/value/index.php b/lib/Value/Index.php similarity index 93% rename from lib/yform/value/index.php rename to lib/Value/Index.php index 5b14b26e2..2e3b71afc 100644 --- a/lib/yform/value/index.php +++ b/lib/Value/Index.php @@ -1,13 +1,19 @@ www.yakamara.de - */ - -class rex_yform_value_index extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use LogicException; +use rex_i18n; +use rex_sql; +use RuntimeException; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Table\Table; + +use function call_user_func; +use function count; +use function in_array; + +class Index extends AbstractValue { public function postFormAction(): void { @@ -109,7 +115,7 @@ private function addRelation(array &$relations, array $names) private function getRelationValues(array $relations) { - $table = rex_yform_manager_table::get($this->params['main_table']); + $table = Table::get($this->params['main_table']); $sql = rex_sql::factory(); $sql->setDebug($this->params['debug']); @@ -154,8 +160,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, Field $relation, $index) use (&$addFieldsAndJoins, $addJoin, &$fields, $sql) { + $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 +189,7 @@ private function getRelationValues(array $relations) continue; } - $relationTable = rex_yform_manager_table::get($relation->getElement('relation_table')); + $relationTable = Table::get($relation->getElement('relation_table')); $name = $columns['target']; $relation = $relationTable->getValueField($name); $relation['relation_table'] = true; @@ -213,7 +219,7 @@ private function getRelationValues(array $relations) } $fromTable = $relation->getElement('relation_table'); - $relationTable = rex_yform_manager_table::get($fromTable); + $relationTable = 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/Value/Integer.php similarity index 89% rename from lib/yform/value/integer.php rename to lib/Value/Integer.php index eeb35d65c..b1661b2b5 100644 --- a/lib/yform/value/integer.php +++ b/lib/Value/Integer.php @@ -1,13 +1,11 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_integer extends rex_yform_value_abstract +use rex_i18n; +use Yakamara\YForm\Manager\Query; + +class Integer extends AbstractValue { public function enterObject() { @@ -72,12 +70,12 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = $params['value']; - /** @var rex_yform_manager_query $query */ + /** @var 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 (Query $query) use ($field) { $query ->where($field, '') ->where($field, null) @@ -85,7 +83,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 (Query $query) use ($field) { $query ->where($field, '', '<>') ->where($field, null, '<>') diff --git a/lib/yform/value/number.php b/lib/Value/Number.php similarity index 90% rename from lib/yform/value/number.php rename to lib/Value/Number.php index 26a4cf9e7..030be2b08 100644 --- a/lib/yform/value/number.php +++ b/lib/Value/Number.php @@ -1,13 +1,11 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_number extends rex_yform_value_abstract +use rex_i18n; +use Yakamara\YForm\Manager\Field; + +class Number extends AbstractValue { public function enterObject() { @@ -79,7 +77,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 (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; @@ -91,16 +89,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_integer::getSearchField($params); + Integer::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_integer::getSearchFilter($params); + return Integer::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_integer::getListValue($params); + return Integer::getListValue($params); } } diff --git a/lib/yform/value/objparams.php b/lib/Value/ObjParams.php similarity index 89% rename from lib/yform/value/objparams.php rename to lib/Value/ObjParams.php index 8a52b66aa..9e05f118e 100644 --- a/lib/yform/value/objparams.php +++ b/lib/Value/ObjParams.php @@ -1,13 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_objparams extends rex_yform_value_abstract +use function count; + +class ObjParams extends AbstractValue { public function init() { diff --git a/lib/yform/value/password.php b/lib/Value/Password.php similarity index 87% rename from lib/yform/value/password.php rename to lib/Value/Password.php index 717973e05..47ab16a26 100644 --- a/lib/yform/value/password.php +++ b/lib/Value/Password.php @@ -1,10 +1,10 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_php extends rex_yform_value_abstract +use rex_i18n; + +class Php extends AbstractValue { public function enterObject() { @@ -54,11 +51,6 @@ public static function getListValue($params) $php = $params['params']['field']['php']; $list = true; - // BC - if ('' == $php) { - $php = $label; - } - ob_start(); eval('?>' . $php); $out = ob_get_clean(); diff --git a/lib/yform/value/prio.php b/lib/Value/Prio.php similarity index 96% rename from lib/yform/value/prio.php rename to lib/Value/Prio.php index 3a591d863..4f6825772 100644 --- a/lib/yform/value/prio.php +++ b/lib/Value/Prio.php @@ -1,13 +1,13 @@ www.yakamara.de - */ - -class rex_yform_value_prio extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; +use rex_sql; + +use function is_array; + +class Prio extends AbstractValue { private $preEditScopeWhere; private $debug = false; diff --git a/lib/yform/value/resetbutton.php b/lib/Value/ResetButton.php similarity index 64% rename from lib/yform/value/resetbutton.php rename to lib/Value/ResetButton.php index ce78ed7d2..509ccb748 100644 --- a/lib/yform/value/resetbutton.php +++ b/lib/Value/ResetButton.php @@ -1,13 +1,8 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_resetbutton extends rex_yform_value_abstract +class ResetButton extends AbstractValue { public function enterObject() { diff --git a/lib/yform/value/showvalue.php b/lib/Value/ShowValue.php similarity index 79% rename from lib/yform/value/showvalue.php rename to lib/Value/ShowValue.php index d2d282cb8..40b46048a 100644 --- a/lib/yform/value/showvalue.php +++ b/lib/Value/ShowValue.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_value_showvalue extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; + +class ShowValue extends AbstractValue { public function enterObject() { @@ -45,16 +42,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/value/signature.php b/lib/Value/Signature.php similarity index 90% rename from lib/yform/value/signature.php rename to lib/Value/Signature.php index fbabe35cd..05286b027 100644 --- a/lib/yform/value/signature.php +++ b/lib/Value/Signature.php @@ -1,13 +1,10 @@ www.yakamara.de - */ - -class rex_yform_value_signature extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; + +class Signature extends AbstractValue { public function enterObject() { diff --git a/lib/yform/value/submit.php b/lib/Value/Submit.php similarity index 94% rename from lib/yform/value/submit.php rename to lib/Value/Submit.php index 861e451a2..c3e68d922 100644 --- a/lib/yform/value/submit.php +++ b/lib/Value/Submit.php @@ -1,13 +1,13 @@ www.yakamara.de - */ - -class rex_yform_value_submit extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; + +use function count; +use function in_array; + +class Submit extends AbstractValue { public function init() { diff --git a/lib/yform/value/text.php b/lib/Value/Text.php similarity index 89% rename from lib/yform/value/text.php rename to lib/Value/Text.php index eb402c8a4..9e1959046 100644 --- a/lib/yform/value/text.php +++ b/lib/Value/Text.php @@ -1,13 +1,12 @@ www.yakamara.de - */ - -class rex_yform_value_text extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use rex_i18n; +use Yakamara\YForm\Manager\Field; +use Yakamara\YForm\Manager\Query; + +class Text extends AbstractValue { public function enterObject() { @@ -63,7 +62,7 @@ public function getDefinitions(): array 'db_type' => ['varchar(191)', 'text'], 'famous' => true, 'hooks' => [ - 'preDefault' => static function (rex_yform_manager_field $field) { + 'preDefault' => static function (Field $field) { return $field->getElement('default'); }, ], @@ -78,12 +77,12 @@ public static function getSearchField($params) public static function getSearchFilter($params) { $value = trim($params['value']); - /** @var rex_yform_manager_query $query */ + /** @var 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 (Query $query) use ($field) { $query ->where($field, '') ->where($field, null) @@ -91,7 +90,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 (Query $query) use ($field) { $query ->where($field, '', '<>') ->where($field, null, '<>') diff --git a/lib/yform/value/textarea.php b/lib/Value/Textarea.php similarity index 88% rename from lib/yform/value/textarea.php rename to lib/Value/Textarea.php index a1c3cc2e8..fda51d392 100644 --- a/lib/yform/value/textarea.php +++ b/lib/Value/Textarea.php @@ -1,13 +1,12 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_textarea extends rex_yform_value_abstract +use rex_i18n; + +use function is_string; + +class Textarea extends AbstractValue { public function enterObject() { @@ -69,16 +68,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/value/time.php b/lib/Value/Time.php similarity index 94% rename from lib/yform/value/time.php rename to lib/Value/Time.php index 56ced75f7..c9b2f4d95 100644 --- a/lib/yform/value/time.php +++ b/lib/Value/Time.php @@ -1,13 +1,13 @@ www.yakamara.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_time extends rex_yform_value_abstract +use rex_i18n; + +use function in_array; +use function is_array; + +class Time extends AbstractValue { public const VALUE_TIME_DEFAULT_FORMAT = 'H:i:s'; public const VALUE_TIME_FORMATS = ['H:i:s' => 'H:i:s', 'H:i' => 'H:i', 'H' => 'H', 'G:i' => 'G:i', 'g:i a' => 'g:i a', 'g:i:s a' => 'g:i:s a', 'h:i a' => 'h:i a', 'h:i:s a' => 'h:i:s a']; @@ -120,11 +120,11 @@ public static function getListValue($params) public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } } diff --git a/lib/yform/value/upload.php b/lib/Value/Upload.php similarity index 96% rename from lib/yform/value/upload.php rename to lib/Value/Upload.php index 3fdb45a53..d9ffa6495 100644 --- a/lib/yform/value/upload.php +++ b/lib/Value/Upload.php @@ -1,13 +1,40 @@ www.yakamara.de - */ - -class rex_yform_value_upload extends rex_yform_value_abstract +namespace Yakamara\YForm\Value; + +use InvalidArgumentException; +use rex; +use rex_dir; +use rex_i18n; +use rex_list; +use rex_login; +use rex_path; +use rex_request; +use rex_type; +use rex_url; +use Yakamara\YForm\Manager\Field; +use ZipArchive; + +use function array_key_exists; +use function call_user_func; +use function count; +use function gettype; +use function in_array; +use function is_array; +use function is_scalar; +use function is_string; + +use const PATHINFO_EXTENSION; +use const UPLOAD_ERR_CANT_WRITE; +use const UPLOAD_ERR_EXTENSION; +use const UPLOAD_ERR_FORM_SIZE; +use const UPLOAD_ERR_INI_SIZE; +use const UPLOAD_ERR_NO_FILE; +use const UPLOAD_ERR_NO_TMP_DIR; +use const UPLOAD_ERR_OK; +use const UPLOAD_ERR_PARTIAL; + +class Upload extends AbstractValue { public string $_upload_sessionKey = ''; @@ -531,12 +558,12 @@ public static function upload_checkExtensions(array $FILE, array $configuration) public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) @@ -552,7 +579,7 @@ public static function getListValue($params) $return = $value; if (rex::isBackend() && $list) { - $field = new rex_yform_manager_field($params['params']['field']); + $field = new Field($params['params']['field']); if ('' != $value) { $return = '' . rex_escape($value) . ''; } diff --git a/lib/yform/value/uuid.php b/lib/Value/Uuid.php similarity index 87% rename from lib/yform/value/uuid.php rename to lib/Value/Uuid.php index bb759dc3b..261f3fb89 100644 --- a/lib/yform/value/uuid.php +++ b/lib/Value/Uuid.php @@ -1,13 +1,13 @@ www.alexplus.de - */ +namespace Yakamara\YForm\Value; -class rex_yform_value_uuid extends rex_yform_value_abstract +use rex_i18n; + +use function chr; +use function ord; + +class Uuid extends AbstractValue { public function preValidateAction(): void { @@ -72,16 +72,16 @@ public function getDefinitions(): array public static function getSearchField($params) { - rex_yform_value_text::getSearchField($params); + Text::getSearchField($params); } public static function getSearchFilter($params) { - return rex_yform_value_text::getSearchFilter($params); + return Text::getSearchFilter($params); } public static function getListValue($params) { - return rex_yform_value_text::getListValue($params); + return Text::getListValue($params); } } diff --git a/lib/yform/yform.php b/lib/YForm.php similarity index 96% rename from lib/yform/yform.php rename to lib/YForm.php index c0e7d8417..1ce29b6ad 100644 --- a/lib/yform/yform.php +++ b/lib/YForm.php @@ -7,7 +7,31 @@ * @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 Yakamara\YForm\Validate\AbstractValidate; +use Yakamara\YForm\Value\AbstractValue; + +use function array_key_exists; +use function count; +use function in_array; +use function is_array; + +use const E_USER_WARNING; + +class YForm { use rex_factory_trait; @@ -283,7 +307,7 @@ public function executeFields(): self // 1. setValue direct via REQUEST foreach ($this->objparams['values'] as $ValueObject) { - /* @var rex_yform_value_abstract $ValueObject */ + /* @var AbstractValue $ValueObject */ $ValueObject->setValue($this->getFieldValue($ValueObject->getName(), [$ValueObject->getId()])); } @@ -308,7 +332,7 @@ public function executeFields(): self if (1 != $this->objparams['send'] && '' != $this->objparams['main_where']) { foreach ($this->objparams['values'] as $i => $valueObject) { - /** @var rex_yform_value_abstract $valueObject */ + /** @var AbstractValue $valueObject */ if ($valueObject->getName()) { if (isset($this->objparams['sql_object'])) { $this->setFieldValue($valueObject->getName(), [$i], @$this->objparams['sql_object']->getValue($valueObject->getName())); @@ -321,7 +345,7 @@ public function executeFields(): self // 3. setValue direct via data Object if (isset($this->objparams['data']) && is_array($this->objparams['data']) && count($this->objparams['data']) > 0) { foreach ($this->objparams['values'] as $valueObject) { - /** @var rex_yform_value_abstract $valueObject */ + /** @var AbstractValue $valueObject */ if (isset($this->objparams['data'][$valueObject->getName()])) { $valueObject->setValue($this->objparams['data'][$valueObject->getName()]); } @@ -340,9 +364,9 @@ public function executeFields(): self // ----- validate form - /* @var rex_yform_base_abstract $Object */ - /* @var rex_yform_validate_abstract $ValidateObject */ - /* @var rex_yform_value_abstract $valueObject */ + /* @var AbstractBase $Object */ + /* @var AbstractValidate $ValidateObject */ + /* @var AbstractValue $valueObject */ foreach ($this->objparams['fields'] as $types) { foreach ($types as $Object) { @@ -421,7 +445,7 @@ public function initializeFields(): self } if (class_exists($class)) { - /** @var rex_yform_base_abstract $Object */ + /** @var AbstractBase $Object */ $Object = new $class(); $Object->loadParams($this->objparams, $element); $Object->setId($i); @@ -450,8 +474,6 @@ public function executeActions() { if ($this->isEditable()) { if ($this->objparams['main_id'] > 0) { - /** @deprecated use 'id' instead of 'ID' */ - $this->objparams['value_pool']['email']['ID'] = $this->objparams['main_id']; $this->objparams['value_pool']['email']['id'] = $this->objparams['main_id']; } @@ -733,7 +755,7 @@ public static function showHelp(): string if (2 == count($exploded)) { $name = $exploded[1]; if ('abstract' != $name) { - /** @var rex_yform_base_abstract $class */ + /** @var AbstractBase $class */ $class = new $class(); $desc = trim($class->getDescription()); $definitions = $class->getDefinitions(); @@ -790,7 +812,7 @@ public static function getTypeArray(): array if (2 == count($exploded)) { $name = $exploded[1]; if ('abstract' != $name) { - /** @var rex_yform_base_abstract $class */ + /** @var AbstractBase $class */ $class = new $class(); $d = $class->getDefinitions(); if (count($d) > 0) { diff --git a/lib/manager/collection.php b/lib/manager/collection.php index fc3379c5f..b8f78230a 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 SplFixedArray; +use Yakamara\YForm\AbstractBase; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\Value\AbstractValue; +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(): rex_yform + public function getForm(): YForm { - $yform = new rex_yform(); + $yform = new YForm(); $yform->setDebug(self::$debug); $yform->objparams['form_name'] = 'yform-manager-multi-edit'; $yform->objparams['form_class'] .= ' yform-manager-multi-edit'; @@ -445,10 +462,10 @@ public function getForm(): rex_yform continue; } - /** @var class-string $class */ + /** @var class-string<\Yakamara\YForm\AbstractBase> $class */ $class = 'rex_yform_' . $field->getType() . '_' . $field->getTypeName(); - /** @var rex_yform_base_abstract $cl */ + /** @var AbstractBase $cl */ $cl = new $class(); $definitions = $cl->getDefinitions(); @@ -529,9 +546,9 @@ public function getForm(): rex_yform } /** - * @param null|callable(rex_yform):void $afterFieldsExecuted + * @param callable(\Yakamara\YForm\YForm):void|null $afterFieldsExecuted */ - public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string + public function executeForm(YForm $yform, ?callable $afterFieldsExecuted = null): string { $yform->executeFields(); @@ -541,7 +558,7 @@ public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = n if (1 == $yform->objparams['send'] && !$yform->objparams['warning_messages']) { $ignoreFields = []; - /** @var rex_yform_value_abstract $field */ + /** @var AbstractValue $field */ foreach ($yform->objparams['values'] as $field) { $key = $field->getElement('__multi_edit_checkbox'); if ($key && !$field->getValue()) { diff --git a/lib/manager/dataset.php b/lib/manager/dataset.php index aca1e6233..6a232d2b9 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) { @@ -121,15 +142,12 @@ public static function getRaw(int $id, ?string $table = null): self }); } - /** - * @return rex_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 +155,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 +197,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 +219,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 +232,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 +244,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 +361,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 +377,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 +464,7 @@ public function save(): bool } /** - * @return string[] + * @return array */ public function getMessages(): array { @@ -485,14 +503,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(): rex_yform + public function getForm(): YForm { $yform = $this->createForm(); $this->setFormMainId($yform); @@ -501,18 +519,18 @@ public function getForm(): rex_yform } /** - * @param null|callable(rex_yform):void $afterFieldsExecuted + * @param callable(\Yakamara\YForm\YForm):void|null $afterFieldsExecuted */ - public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = null): string + public function executeForm(YForm $yform, ?callable $afterFieldsExecuted = null): string { $exists = $this->exists(); $oldData = $this->getData(); if ($exists) { - /** @var rex_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 rex_yform $yform */ + /** @var YForm $yform */ $yform = rex_extension::registerPoint(new rex_extension_point('YFORM_DATA_ADD', $yform, ['table' => $this->getTable(), 'data' => $this])); } @@ -529,7 +547,7 @@ public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = n return; } - /** @var rex_yform_action_db $dbAction */ + /** @var Db $dbAction */ $dbAction = $ep->getParam('form'); if ($dbAction->getParam('manager_dataset') !== $this) { return; @@ -538,7 +556,7 @@ public function executeForm(rex_yform $yform, ?callable $afterFieldsExecuted = n $this->id = ((int) $dbAction->getParam('main_id')) ?: null; if ($this->id) { self::addInstance($this->id, $this); - rex_yform_value_be_manager_relation::clearCache($this->table); + BackendManagerRelation::clearCache($this->table); } }, rex_extension::EARLY); } @@ -672,7 +690,7 @@ public function __set(string $key, $value): void $this->setValue($key, $value); } - private function getInternalForm(): rex_yform + private function getInternalForm(): YForm { $dummy = new static($this->table, 0); @@ -685,17 +703,17 @@ private function getInternalForm(): rex_yform return $yform; } - private function createForm(): rex_yform + private function createForm(): YForm { - $yform = new rex_yform(); + $yform = new YForm(); $fields = $this->getFields(); $yform->setDebug(self::$debug); foreach ($fields as $field) { - /** @var class-string $class */ + /** @var class-string<\Yakamara\YForm\AbstractBase> $class */ $class = 'rex_yform_' . $field->getType() . '_' . $field->getTypeName(); - /** @var rex_yform_base_abstract $cl */ + /** @var AbstractBase $cl */ $cl = new $class(); $definitions = $cl->getDefinitions(); @@ -721,7 +739,7 @@ private function createForm(): rex_yform return $yform; } - private function setFormMainId(rex_yform $yform): void + private function setFormMainId(YForm $yform): void { if ($this->exists()) { $where = 'id = ' . (int) $this->id; @@ -733,7 +751,7 @@ private function setFormMainId(rex_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..ac926de29 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 Throwable; +use Yakamara\YForm\AbstractBase; +use Yakamara\YForm\Manager\Table\Api; +use Yakamara\YForm\Manager\Table\Authorization; +use Yakamara\YForm\Manager\Table\Table; +use Yakamara\YForm\Value\AbstractValue; +use Yakamara\YForm\Value\BackendManagerRelation; +use Yakamara\YForm\Value\Submit; +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) @@ -135,7 +154,7 @@ public function getDataPage() - 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); @@ -303,7 +322,7 @@ public function getDataPage() foreach ($this->table->getFields() as $field) { $class = 'rex_yform_' . $field->getType() . '_' . $field->getTypeName(); - /** @var rex_yform_base_abstract $cl */ + /** @var AbstractBase $cl */ $cl = new $class(); $definitions = $cl->getDefinitions(); @@ -377,8 +396,8 @@ public function getDataPage() $sql_db = rex_sql::factory(); $form = ''; $sql_db->transactional(static function () use (&$form, &$yform, $data, $func) { - $afterFieldsExecuted = static function (rex_yform $yform) { - /** @var rex_yform_value_abstract $valueObject */ + $afterFieldsExecuted = static function (YForm $yform) { + /** @var AbstractValue $valueObject */ foreach ($yform->objparams['values'] as $valueObject) { if ('submit' == $valueObject->getName()) { if (2 == $valueObject->getValue()) { // apply @@ -390,14 +409,14 @@ public function getDataPage() }; if ('clone' == $func) { - $afterFieldsExecuted = static function (rex_yform $yform) use ($afterFieldsExecuted) { + $afterFieldsExecuted = static function (YForm $yform) use ($afterFieldsExecuted) { $yform->objparams['form_hiddenfields']['func'] = 'add'; unset($yform->objparams['form_hiddenfields']['data_id']); // In den Feldern Anpassungen vornehmen foreach ($yform->objparams['values'] as $k => $v) { // Submit-Buttons von "Edit" auf "Add" zurückstellen - if ($v instanceof rex_yform_value_submit) { + if ($v instanceof Submit) { $yform->objparams['form_output'][$k] = str_replace( [rex_i18n::msg('yform_save') . 'getElement('type')) { + if ($v instanceof BackendManagerRelation && 5 == $v->getElement('type')) { $fieldName = preg_quote($v->getFieldName()); $pattern = '//'; $yform->objparams['form_output'][$k] = preg_replace($pattern, '', $yform->objparams['form_output'][$k]); } } - if (is_callable($afterFieldsExecuted)) { + if (\is_callable($afterFieldsExecuted)) { $afterFieldsExecuted($yform); } }; @@ -431,7 +450,7 @@ public function getDataPage() case 'edit': $submit_type = 1; // normal, 2=apply foreach ($yform->objparams['values'] as $valueObject) { - /** @var rex_yform_value_abstract $valueObject */ + /** @var AbstractValue $valueObject */ if ('submit' == $valueObject->getName()) { if (2 == $valueObject->getValue()) { // apply $submit_type = 2; @@ -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 = rex_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 rex_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 a40459990..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(): rex_yform + public function getYForm(): YForm { - $yform = new rex_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/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/rest/auth/auth.php b/lib/rest/AuthToken.php similarity index 90% rename from lib/rest/auth/auth.php rename to lib/rest/AuthToken.php index d9a56a9cd..6810d810f 100644 --- a/lib/rest/auth/auth.php +++ b/lib/rest/AuthToken.php @@ -1,6 +1,14 @@ 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..77acab3f9 100644 --- a/lib/rest/route.php +++ b/lib/rest/route.php @@ -1,15 +1,35 @@ 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,15 +107,15 @@ 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 */ + /** @var Table $table */ $table = $this->getTable(); $query = $this->getQuery(); @@ -108,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; @@ -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,19 +449,19 @@ 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<\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', @@ -452,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)) { @@ -475,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 { @@ -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 @@ -532,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 = []; @@ -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 { @@ -587,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(); @@ -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, []); } } @@ -667,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/action/abstract.php b/lib/yform/action/abstract.php deleted file mode 100644 index dfac1b286..000000000 --- a/lib/yform/action/abstract.php +++ /dev/null @@ -1,18 +0,0 @@ -www.yakamara.de - */ - -abstract class rex_yform_action_abstract extends rex_yform_base_abstract -{ - public $action = []; - - protected function getElementMappingOffset() - { - return 1; - } -} diff --git a/lib/yform/action/createdb.php b/lib/yform/action/createdb.php deleted file mode 100644 index 916bffe55..000000000 --- a/lib/yform/action/createdb.php +++ /dev/null @@ -1,50 +0,0 @@ -www.yakamara.de - */ - -class rex_yform_action_createdb extends rex_yform_action_abstract -{ - public function executeAction(): void - { - $table_name = $this->getElement(2); - $table_exists = false; - - $tables = rex_sql::factory()->getArray('show tables'); - foreach ($tables as $table) { - if (current($table) == $table_name) { - $table_exists = true; - break; - } - } - - if (!$table_exists) { - rex_sql::factory()->setQuery('CREATE TABLE `' . $table_name . '` (`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;'); - } - - $cols = []; - foreach (rex_sql::factory()->getArray('show columns from ' . $table_name) as $k => $v) { - $cols[] = $v['Field']; - } - - foreach ($this->params['value_pool']['sql'] as $key => $value) { - if (!in_array($key, $cols)) { - rex_sql::factory()->setQuery('ALTER TABLE `' . $table_name . '` ADD `' . $key . '` TEXT NOT NULL;'); - } - } - } - - public function getDescription(): string - { - return 'action|createdb|tablename'; - } - - public function isDeprecated(): bool - { - return true; - } -} 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/pages/email.php b/pages/email.php index 1dac02ff8..3fc5b846a 100644 --- a/pages/email.php +++ b/pages/email.php @@ -1,11 +1,7 @@ www.yakamara.de - */ +use Yakamara\YForm\Email\Template; +use Yakamara\YForm\YForm; $_csrf_key = 'yform_email'; @@ -22,9 +18,9 @@ $template = null; if ($template_key) { - $template = rex_yform_email_template::getTemplate($template_key); + $template = Template::getTemplate($template_key); } elseif ($template_id) { - $template = rex_yform_email_template::getTemplateById($template_id); + $template = Template::getTemplateById($template_id); } $template_id = null; @@ -68,7 +64,7 @@ $form_data[] = 'datestamp|updatedate||||0'; - $yform = rex_yform::factory(); + $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_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_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 = [ - rex_yform_manager_dataset::ACTION_CREATE => 'success', - rex_yform_manager_dataset::ACTION_UPDATE => 'primary', - rex_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 rex_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'), - 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), + 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 bcc2ae593..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(rex_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)); } - rex_yform_manager_table_api::generateTablesAndFields(); + Api::generateTablesAndFields(); $fields = []; - foreach (rex_yform_manager_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)); } - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } } diff --git a/pages/manager.table_edit.php b/pages/manager.table_edit.php index 66fb690dc..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 rex_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']); - rex_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 = rex_yform_manager_table::getById($table_id); + $table = Table::getById($table_id); if (!$table) { $func = 'add'; } } - $yform = new rex_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', rex_yform_manager_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', [rex_yform_manager_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) rex_yform_manager_table::get($table); + return (bool) Table::get($table); }, '', rex_i18n::msg('yform_manager_table_exists')]); - $yform->setActionField('db', [rex_yform_manager_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 `' . 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 `' . 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 = rex_yform_manager_table::get($table_name); + $table = Table::get($table_name); if ($table) { - rex_yform_manager_table_api::generateTableAndFields($table); + Api::generateTableAndFields($table); } echo rex_view::info(rex_i18n::msg('yform_manager_table_updated')); break; case 'add': default: - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); $table_name = $yform->objparams['value_pool']['sql']['table_name']; - $table = rex_yform_manager_table::get($table_name); + $table = Table::get($table_name); if ($table) { - rex_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'); - rex_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 `' . rex_yform_manager_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 b79a1d63f..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 = rex_yform_manager_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 4b835023d..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 (rex_yform_manager_table::getAll() as $g_table) { +foreach (Table::getAll() as $g_table) { $yform_tables[] = $g_table->getTableName(); } @@ -27,7 +24,7 @@ } } -$yform = new rex_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 { - rex_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 rex_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 2575adaa4..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 (rex_yform_manager_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 rex_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 = rex_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 450d5375e..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 rex_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); - rex_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 cb9c892fa..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 = rex_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 = rex_yform_rest_auth_token::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 efba4a7ac..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 (rex_yform_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 = rex_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 = rex_yform_rest_auth_token::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 f0c2e2df8..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', rex_yform::showHelp(), false); +$fragment->setVar('body', YForm::showHelp(), false); echo $fragment->parse('core/page/section.php'); diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 15f426d69..352f49880 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -17,7 +17,7 @@ - tests + tests diff --git a/rector.php b/rector.php new file mode 100644 index 000000000..9a30a6102 --- /dev/null +++ b/rector.php @@ -0,0 +1,119 @@ +withPaths(['docs', 'fragments', 'lib', 'module', 'pages', 'ytemplates', 'boot.php', 'tests']) + ->withParallel() + ->withPhpVersion(PhpVersion::PHP_83) + ->withConfiguredRule( + 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', + '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', + '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', + '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', + + 'rex_yform_base_abstract' => 'Yakamara\YForm\AbstractBase', + + 'rex_yform_action_abstract' => 'Yakamara\YForm\Action\AbstractAction', + 'rex_yform_action_callback' => 'Yakamara\YForm\Action\Callback', + 'rex_yform_action_copy_value' => 'Yakamara\YForm\Action\CopyValue', + 'rex_yform_action_create_table' => 'Yakamara\YForm\Action\CreateTable', + 'rex_yform_action_db_query' => 'Yakamara\YForm\Action\DbQuery', + 'rex_yform_action_db' => 'Yakamara\YForm\Action\Db', + 'rex_yform_action_email' => 'Yakamara\YForm\Action\Email', + 'rex_yform_action_encrypt_value' => 'Yakamara\YForm\Action\EncryptValue', + 'rex_yform_action_html' => 'Yakamara\YForm\Action\Html', + 'rex_yform_action_manage_db' => 'Yakamara\YForm\Action\ManageDb', + 'rex_yform_action_php' => 'Yakamara\YForm\Action\Php', + 'rex_yform_action_readtable' => 'Yakamara\YForm\Action\ReadTable', + 'rex_yform_action_redirect' => 'Yakamara\YForm\Action\Redirect', + 'rex_yform_action_showtext' => 'Yakamara\YForm\Action\ShowText', + 'rex_yform_action_tpl2email' => 'Yakamara\YForm\Action\Tpl2Email', + + 'rex_yform_validate_abstract' => 'Yakamara\YForm\Validate\AbstractValidate', + 'rex_yform_validate_compare_value' => 'Yakamara\YForm\Validate\CompareValue', + 'rex_yform_validate_compare' => 'Yakamara\YForm\Validate\Compare', + 'rex_yform_validate_customfunction' => 'Yakamara\YForm\Validate\CustomFunction', + 'rex_yform_validate_empty' => 'Yakamara\YForm\Validate\IsEmpty', + 'rex_yform_validate_in_names' => 'Yakamara\YForm\Validate\InNames', + 'rex_yform_validate_in_table' => 'Yakamara\YForm\Validate\InTable', + 'rex_yform_validate_intfromto' => 'Yakamara\YForm\Validate\IntFromTo', + 'rex_yform_validate_password_policy' => 'Yakamara\YForm\Validate\PasswordPolicy', + 'rex_yform_validate_preg_match' => 'Yakamara\YForm\Validate\PregMatch', + 'rex_yform_validate_size_range' => 'Yakamara\YForm\Validate\SizeRange', + 'rex_yform_validate_size' => 'Yakamara\YForm\Validate\Size', + 'rex_yform_validate_type' => 'Yakamara\YForm\Validate\Type', + 'rex_yform_validate_unique' => 'Yakamara\YForm\Validate\Unique', + + 'rex_yform_value_abstract' => 'Yakamara\YForm\Value\AbstractValue', + 'rex_yform_value_article' => 'Yakamara\YForm\Value\Article', + 'rex_yform_value_be_link' => 'Yakamara\YForm\Value\BackendLink', + 'rex_yform_value_be_manager_relation' => 'Yakamara\YForm\Value\BackendManagerRelation', + 'rex_yform_value_be_media' => 'Yakamara\YForm\Value\BackendMedia', + 'rex_yform_value_be_table' => 'Yakamara\YForm\Value\BackendTable', + 'rex_yform_value_be_user' => 'Yakamara\YForm\Value\BackendUser', + 'rex_yform_value_checkbox' => 'Yakamara\YForm\Value\Checkbox', + 'rex_yform_value_choice' => 'Yakamara\YForm\Value\Choice', + 'rex_yform_value_csrf' => 'Yakamara\YForm\Value\Csrf', + 'rex_yform_value_date' => 'Yakamara\YForm\Value\Date', + 'rex_yform_value_datestamp' => 'Yakamara\YForm\Value\DateStamp', + 'rex_yform_value_datetime' => 'Yakamara\YForm\Value\DateTime', + 'rex_yform_value_email' => 'Yakamara\YForm\Value\Email', + 'rex_yform_value_emptyname' => 'Yakamara\YForm\Value\EmptyName', + 'rex_yform_value_fieldset' => 'Yakamara\YForm\Value\Fieldset', + 'rex_yform_value_generate_key' => 'Yakamara\YForm\Value\GenerateKey', + 'rex_yform_value_google_geocode' => 'Yakamara\YForm\Value\GoogleGeoCode', + 'rex_yform_value_hashvalue' => 'Yakamara\YForm\Value\HashValue', + 'rex_yform_value_hidden' => 'Yakamara\YForm\Value\Hidden', + 'rex_yform_value_html' => 'Yakamara\YForm\Value\Html', + 'rex_yform_value_index' => 'Yakamara\YForm\Value\Index', + 'rex_yform_value_integer' => 'Yakamara\YForm\Value\Integer', + 'rex_yform_value_ip' => 'Yakamara\YForm\Value\IP', + 'rex_yform_value_number' => 'Yakamara\YForm\Value\Number', + 'rex_yform_value_objparams' => 'Yakamara\YForm\Value\ObjParams', + 'rex_yform_value_password' => 'Yakamara\YForm\Value\Password', + 'rex_yform_value_php' => 'Yakamara\YForm\Value\Php', + 'rex_yform_value_prio' => 'Yakamara\YForm\Value\Prio', + 'rex_yform_value_resetbutton' => 'Yakamara\YForm\Value\ResetButton', + 'rex_yform_value_showvalue' => 'Yakamara\YForm\Value\ShowValue', + 'rex_yform_value_signature' => 'Yakamara\YForm\Value\Signature', + 'rex_yform_value_submit' => 'Yakamara\YForm\Value\Submit', + 'rex_yform_value_text' => 'Yakamara\YForm\Value\Text', + 'rex_yform_value_textarea' => 'Yakamara\YForm\Value\Textarea', + 'rex_yform_value_time' => 'Yakamara\YForm\Value\Time', + 'rex_yform_value_upload' => 'Yakamara\YForm\Value\Upload', + 'rex_yform_value_uuid' => 'Yakamara\YForm\Value\Uuid', + + ], + ) + ->withConfiguredRule(FuncCallToStaticCallRector::class, [ + new FuncCallToStaticCall('rex_yform_manager_checkField', Manager::class, 'checkField'), + ]) +; diff --git a/tests/rex_yform_yorm_test.php b/tests/Manager/Table/ApiTest.php similarity index 83% rename from tests/rex_yform_yorm_test.php rename to tests/Manager/Table/ApiTest.php index 3e26951eb..faa8436fb 100644 --- a/tests/rex_yform_yorm_test.php +++ b/tests/Manager/Table/ApiTest.php @@ -1,26 +1,23 @@ $tableName, 'name' => 'Name of Table - ' . $tableName, @@ -39,7 +36,7 @@ public static function setUpTable($tableName) return $table; } - public static function setUpTableField(rex_yform_manager_table $table, $field) + public static function setUpTableField(Table $table, $field) { $field['type_id'] ??= 'value'; $field['type_name'] ??= 'text'; @@ -49,8 +46,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); + Api::setTableField($table->getTableName(), $field); + Api::generateTableAndFields($table); } public function testTableAPI() @@ -63,8 +60,8 @@ public function testTableAPI() $table = self::setUpTable($tableName); static::assertEquals( $table::class, - 'rex_yform_manager_table', - 'table creation failed. (rex_yform_manager_table_api::setTable)', + 'Yakamara\YForm\Manager\Table\Table', + 'table creation failed. (\Yakamara\YForm\Manager\Table\Api::setTable)', ); if ($table) { @@ -78,7 +75,7 @@ public function testTableAPI() // prüfen ob es angelegt ist. - $fields = rex_yform_manager_table::get($tableName)->getFields(); + $fields = Table::get($tableName)->getFields(); static::assertEquals( count($fields), 1, @@ -92,7 +89,7 @@ public function testTableAPI() // TODO: prüfen ob field gelöscht werden kann // YORM - Datensatz anlegen - $dataset = rex_yform_manager_dataset::create($tableName); + $dataset = Dataset::create($tableName); $dataset->setValue($fieldName, $fieldValue); static::assertTrue($dataset->save(), 'dataset creation failed (rex_yform_manager_dataset::create)'); @@ -110,7 +107,7 @@ public function testTableAPI() // YORM - Datensatz auslesen $datasetId = $dataset->getId(); - $dataset = rex_yform_manager_dataset::get($datasetId, $tableName); + $dataset = Dataset::get($datasetId, $tableName); static::assertNotNull($dataset, 'dataset not found - get via ID failed'); // YORM - Datensatz bearbeiten @@ -118,7 +115,7 @@ public function testTableAPI() $dataset ->setValue($fieldName, $fieldValueEdit) ->save(); - $dataset = rex_yform_manager_dataset::get($datasetId, $tableName); + $dataset = Dataset::get($datasetId, $tableName); static::assertEquals( $dataset->getValue($fieldName), $fieldValueEdit, @@ -129,7 +126,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 = Dataset::get($datasetId, $tableName); static::assertFalse($dataset->exists(), 'dataset delete failed - YOrm delete failed'); } @@ -187,23 +184,23 @@ public function testTableAPI() 'size' => 10, ]); - $cat1 = rex_yform_manager_dataset::create($tableNameCategories) + $cat1 = Dataset::create($tableNameCategories) ->setValue($fieldName, 'Category 1'); $cat1->save(); - $cat2 = rex_yform_manager_dataset::create($tableNameCategories) + $cat2 = Dataset::create($tableNameCategories) ->setValue($fieldName, 'Category 2'); $cat2->save(); - $cat3 = rex_yform_manager_dataset::create($tableNameCategories) + $cat3 = Dataset::create($tableNameCategories) ->setValue($fieldName, 'Category 3'); $cat3->save(); - rex_yform_manager_dataset::create($tableName) + Dataset::create($tableName) ->setValue($fieldName, 'Mein Neuer Wert') ->save(); - rex_yform_manager_dataset::create($tableName) + Dataset::create($tableName) ->setValue($fieldName, 'Mein Neuer Wert mit 2 Kategorien') ->setValue('categories', [ $cat1->getId(), @@ -213,9 +210,9 @@ public function testTableAPI() } } - rex_yform_manager_table_api::removeTable($tableName); + Api::removeTable($tableName); - $table = rex_yform_manager_table::get($tableName); + $table = Table::get($tableName); static::assertNull($table, 'table schema removing failed'); @@ -231,19 +228,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 ' . 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 ' . Field::table() . ' where table_name LIKE :table_name ', [ ':table_name' => $prefix . '%', ], ); - rex_yform_manager_table::deleteCache(); + Table::deleteCache(); } catch (Exception $e) { } } diff --git a/ytemplates/bootstrap/value.article.tpl.php b/ytemplates/bootstrap/value.article.tpl.php index f8d9027d3..fee01def0 100644 --- a/ytemplates/bootstrap/value.article.tpl.php +++ b/ytemplates/bootstrap/value.article.tpl.php @@ -1,11 +1,11 @@ getHTMLClass() . ' ' . $this->getWarningClass()); ?>
    diff --git a/ytemplates/bootstrap/value.be_link.tpl.php b/ytemplates/bootstrap/value.be_link.tpl.php index b08d25bfc..c8f762e00 100644 --- a/ytemplates/bootstrap/value.be_link.tpl.php +++ b/ytemplates/bootstrap/value.be_link.tpl.php @@ -1,10 +1,8 @@ getRelationType()) { - echo \rex_var_yform_table_data::getRelationWidget($id, $this->getFieldName(), $this->getValue(), $link, $this->params['main_id']); + echo TableData::getRelationWidget($id, $this->getFieldName(), $this->getValue(), $link, $this->params['main_id']); } elseif (2 == $this->getRelationType()) { $name = $this->getFieldName(); $args = []; $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 = 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 TableData::getSingleWidget($id, $name, $value, $args); } else { $name = $this->getFieldName(); $args = []; @@ -83,10 +83,10 @@ $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 = 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 TableData::getMultipleWidget($id, $name, $value, $args); } ?> diff --git a/ytemplates/bootstrap/value.be_media.tpl.php b/ytemplates/bootstrap/value.be_media.tpl.php index d559b85a0..dd44d73f3 100644 --- a/ytemplates/bootstrap/value.be_media.tpl.php +++ b/ytemplates/bootstrap/value.be_media.tpl.php @@ -1,10 +1,8 @@ params['form_output'] = []; $field->params['this']->setObjectparams('form_name', $this->getParam('form_name') . '][' . $this->getId() . '][' . $i); diff --git a/ytemplates/bootstrap/value.be_table.tpl.php b/ytemplates/bootstrap/value.be_table.tpl.php index 8b488f7ee..3813dbccd 100644 --- a/ytemplates/bootstrap/value.be_table.tpl.php +++ b/ytemplates/bootstrap/value.be_table.tpl.php @@ -1,10 +1,9 @@ params['form_output'] = []; $field->params['this']->setObjectparams('form_name', $this->getParam('form_name') . '][' . $this->getId() . '][' . $data_index); diff --git a/ytemplates/bootstrap/value.checkbox.tpl.php b/ytemplates/bootstrap/value.checkbox.tpl.php index 29ca2195a..1133fec41 100644 --- a/ytemplates/bootstrap/value.checkbox.tpl.php +++ b/ytemplates/bootstrap/value.checkbox.tpl.php @@ -1,10 +1,8 @@ getValue() ?? ''; $notices = []; diff --git a/ytemplates/bootstrap/value.checkbox_group.tpl.php b/ytemplates/bootstrap/value.checkbox_group.tpl.php index 7ad007324..83b14b970 100644 --- a/ytemplates/bootstrap/value.checkbox_group.tpl.php +++ b/ytemplates/bootstrap/value.checkbox_group.tpl.php @@ -1,10 +1,8 @@ getElement('notice')) { $notices[] = rex_i18n::translate($this->getElement('notice'), false); @@ -42,7 +46,7 @@ ?> - >