From ecb04a331b5196bde44a74212925326ff1a92075 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20=C5=81ojewski?= Date: Thu, 28 Jun 2018 20:16:43 +0200 Subject: [PATCH] autocomplete for tables --- js/settings.js | 1 + lib/Controller/SettingsController.php | 3 ++- lib/Platform/AbstractPlatform.php | 13 +++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/js/settings.js b/js/settings.js index 87a64d5..47b1061 100644 --- a/js/settings.js +++ b/js/settings.js @@ -41,6 +41,7 @@ user_sql.adminSettingsUI = function () { $(ids).autocomplete({ source: function (request, response) { var post = $(form_id).serializeArray(); + post.push({name: "input", value: request["term"]}); $.post(OC.generateUrl(path), post, response, "json"); }, minLength: 0, diff --git a/lib/Controller/SettingsController.php b/lib/Controller/SettingsController.php index 7a95d6c..8c4a9fb 100644 --- a/lib/Controller/SettingsController.php +++ b/lib/Controller/SettingsController.php @@ -266,7 +266,8 @@ class SettingsController extends Controller try { $connection = $this->getConnection(); $platform = PlatformFactory::getPlatform($connection); - $tables = $platform->getTables(); + $input = $this->request->getParam("input"); + $tables = $platform->getTables($input); $this->logger->debug( "Returning tableAutocomplete(): count(" . count($tables) . ")", diff --git a/lib/Platform/AbstractPlatform.php b/lib/Platform/AbstractPlatform.php index 63156ff..38d8f61 100644 --- a/lib/Platform/AbstractPlatform.php +++ b/lib/Platform/AbstractPlatform.php @@ -49,12 +49,13 @@ abstract class AbstractPlatform /** * Get all the tables defined in the database. * - * @param bool $schemaPrefix Show schema name in the results. + * @param string $phrase Show only tables containing given phrase. + * @param bool $schemaPrefix Show schema name in the results. * * @return array Array with table names. * @throws DBALException On a database exception. */ - public function getTables($schemaPrefix = false) + public function getTables($phrase = "", $schemaPrefix = false) { $platform = $this->connection->getDatabasePlatform(); @@ -68,13 +69,17 @@ abstract class AbstractPlatform $result = $this->connection->executeQuery($queryTables); while ($row = $result->fetch()) { $name = $this->getTableName($row, $schemaPrefix); - $tables[] = $name; + if (preg_match("/.*$phrase.*/i", $name)) { + $tables[] = $name; + } } $result = $this->connection->executeQuery($queryViews); while ($row = $result->fetch()) { $name = $this->getViewName($row, $schemaPrefix); - $tables[] = $name; + if (preg_match("/.*$phrase.*/i", $name)) { + $tables[] = $name; + } } return $tables;