From a87048bb1bed10767700b7f69a865dc70265346e Mon Sep 17 00:00:00 2001 From: Daniel Tiringer <53534182+danielTiringer@users.noreply.github.com> Date: Wed, 27 Oct 2021 15:59:14 +0000 Subject: [PATCH] Extract RecentFavoriteTable html to twig (#17157) Extract HTML from libraries/classes/RecentFavoriteTable.php to Twig templates Related to #14801 Signed-off-by: Daniel Tiringer --- libraries/classes/RecentFavoriteTable.php | 70 ++++++++----------- templates/recent_favorite_table_favorite.twig | 15 ++++ .../recent_favorite_table_no_tables.twig | 7 ++ templates/recent_favorite_table_recent.twig | 7 ++ 4 files changed, 58 insertions(+), 41 deletions(-) create mode 100644 templates/recent_favorite_table_favorite.twig create mode 100644 templates/recent_favorite_table_no_tables.twig create mode 100644 templates/recent_favorite_table_recent.twig diff --git a/libraries/classes/RecentFavoriteTable.php b/libraries/classes/RecentFavoriteTable.php index 0e9031ed34..f85ec9aa1f 100644 --- a/libraries/classes/RecentFavoriteTable.php +++ b/libraries/classes/RecentFavoriteTable.php @@ -7,8 +7,6 @@ declare(strict_types=1); namespace PhpMyAdmin; -use PhpMyAdmin\Html\Generator; - use function __; use function array_key_exists; use function array_merge; @@ -16,7 +14,6 @@ use function array_pop; use function array_unique; use function array_unshift; use function count; -use function htmlspecialchars; use function json_decode; use function json_encode; use function max; @@ -33,6 +30,9 @@ use const SORT_REGULAR; */ class RecentFavoriteTable { + /** @var Template */ + public $template; + /** * Reference to session variable containing recently used or favorite tables. * @@ -60,10 +60,13 @@ class RecentFavoriteTable /** * Creates a new instance of RecentFavoriteTable * - * @param string $type the table type + * @param Template $template Template object + * @param string $type the table type */ - private function __construct(string $type) + private function __construct(Template $template, string $type) { + $this->template = $template; + global $dbi; $this->relation = new Relation($dbi); @@ -86,7 +89,8 @@ class RecentFavoriteTable public static function getInstance(string $type): RecentFavoriteTable { if (! array_key_exists($type, self::$instances)) { - self::$instances[$type] = new RecentFavoriteTable($type); + $template = new Template(); + self::$instances[$type] = new RecentFavoriteTable($template, $type); } return self::$instances[$type]; @@ -196,59 +200,43 @@ class RecentFavoriteTable { if (count($this->tables)) { if ($this->tableType === 'recent') { - $html = ''; + $tables = []; foreach ($this->tables as $table) { - $html .= ''; + ]; } - return $html; + return $this->template->render('recent_favorite_table_recent', ['tables' => $tables]); } - $html = ''; + $tables = []; foreach ($this->tables as $table) { - $html .= ''; + 'md5' => md5($table['db'] . '.' . $table['table']), + ]; + + $tables[] = [ + 'remove_parameters' => $removeParameters, + 'table_parameters' => $tableParameters, + ]; } - return $html; + return $this->template->render('recent_favorite_table_favorite', ['tables' => $tables]); } - return ''; + return $this->template->render('recent_favorite_table_no_tables', [ + 'is_recent' => $this->tableType === 'recent', + ]); } public function getHtml(): string diff --git a/templates/recent_favorite_table_favorite.twig b/templates/recent_favorite_table_favorite.twig new file mode 100644 index 0000000000..f9f35805c9 --- /dev/null +++ b/templates/recent_favorite_table_favorite.twig @@ -0,0 +1,15 @@ +{% for table in tables %} + +{% endfor %} \ No newline at end of file diff --git a/templates/recent_favorite_table_no_tables.twig b/templates/recent_favorite_table_no_tables.twig new file mode 100644 index 0000000000..210d32381b --- /dev/null +++ b/templates/recent_favorite_table_no_tables.twig @@ -0,0 +1,7 @@ + diff --git a/templates/recent_favorite_table_recent.twig b/templates/recent_favorite_table_recent.twig new file mode 100644 index 0000000000..b507a21648 --- /dev/null +++ b/templates/recent_favorite_table_recent.twig @@ -0,0 +1,7 @@ +{% for table in tables %} + +{% endfor %} \ No newline at end of file