From c3aa2730deb92d1f7fbe768381cd8b36512d235d Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 23 Apr 2020 07:02:18 +0000 Subject: [PATCH] Improved definition style --- src/Database/DBView.php | 6 +++++- static/dbview.config.php | 15 +++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/Database/DBView.php b/src/Database/DBView.php index f23ab152ee..cd1d22e1e1 100644 --- a/src/Database/DBView.php +++ b/src/Database/DBView.php @@ -109,7 +109,11 @@ class DBView $sql_rows = []; foreach ($structure["fields"] AS $fieldname => $origin) { - $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`"; + if (is_string($origin)) { + $sql_rows[] = $origin . " AS `" . DBA::escape($fieldname) . "`"; + } elseif (is_array($origin) && (sizeof($origin) == 2)) { + $sql_rows[] = "`" . DBA::escape($origin[0]) . "`.`" . DBA::escape($origin[1]) . "` AS `" . DBA::escape($fieldname) . "`"; + } } $sql = sprintf("DROP VIEW IF EXISTS `%s`", DBA::escape($name)); diff --git a/static/dbview.config.php b/static/dbview.config.php index 6bc327697a..165ae2fa1b 100755 --- a/static/dbview.config.php +++ b/static/dbview.config.php @@ -24,8 +24,7 @@ * Syntax (braces indicate optionale values): * "" => [ * "fields" => [ - * "" => "`table`.`field`", - * "" => "`other-table`.`field`", + * "" => ["table", "field"], * "" => "SQL expression", * ... * ], @@ -39,12 +38,12 @@ return [ "tag-view" => [ - "fields" => ["uri-id" => "`post-tag`.`uri-id`", - "uri" => "`item-uri`.`uri`", - "guid" => "`item-uri`.`guid`", - "type" => "`post-tag`.`type`", - "tid" => "`post-tag`.`tid`", - "cid" => "`post-tag`.`cid`", + "fields" => ["uri-id" => ["post-tag", "uri-id"], + "uri" => ["item-uri", "uri"], + "guid" => ["item-uri", "guid"], + "type" => ["post-tag", "type"], + "tid" => ["post-tag", "tid"], + "cid" => ["post-tag", "cid"], "name" => "CASE `cid` WHEN 0 THEN `tag`.`name` ELSE `contact`.`name` END", "url" => "CASE `cid` WHEN 0 THEN `tag`.`url` ELSE `contact`.`url` END"], "query" => "FROM `post-tag` -- 2.39.5