From 11c161af4e1e348fc801deffd2667f8e5ba33582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Zapletal?= Date: Mon, 25 Mar 2024 16:41:41 -0600 Subject: [PATCH] Added DB columns keys map --- src/Collection/ReadBuilder/ReadBuilder.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Collection/ReadBuilder/ReadBuilder.php b/src/Collection/ReadBuilder/ReadBuilder.php index 5a7c16e..7b4630e 100644 --- a/src/Collection/ReadBuilder/ReadBuilder.php +++ b/src/Collection/ReadBuilder/ReadBuilder.php @@ -10,16 +10,21 @@ use Megio\Collection\ReadBuilder\Column\Base\ShowOnlyOn; use Megio\Collection\ReadBuilder\Column\BlobColumn; use Megio\Collection\ReadBuilder\Column\DateTimeIntervalColumn; +use Megio\Collection\ReadBuilder\Column\EmailColumn; use Megio\Collection\ReadBuilder\Column\JsonColumn; use Megio\Collection\ReadBuilder\Column\Base\IColumn; use Megio\Collection\ReadBuilder\Column\BooleanColumn; use Megio\Collection\ReadBuilder\Column\DateColumn; use Megio\Collection\ReadBuilder\Column\DateTimeColumn; use Megio\Collection\ReadBuilder\Column\NumericColumn; +use Megio\Collection\ReadBuilder\Column\PhoneColumn; use Megio\Collection\ReadBuilder\Column\StringColumn; use Megio\Collection\ReadBuilder\Column\TimeColumn; use Megio\Collection\ReadBuilder\Column\UnknownColumn; +use Megio\Collection\ReadBuilder\Column\UrlColumn; +use Megio\Collection\ReadBuilder\Column\VideoLinkColumn; use Megio\Helper\ArrayMove; +use Nette\Utils\Strings; class ReadBuilder implements IRecipeBuilder { @@ -194,6 +199,20 @@ protected function addIdColumnIfNotExists(): void protected function createColumnInstance(string $type, string $key, bool $visible): IColumn { + $keysMap = [ + 'email' => new EmailColumn(key: $key, name: $key, visible: $visible), + 'phone' => new PhoneColumn(key: $key, name: $key, visible: $visible), + 'url' => new UrlColumn(key: $key, name: $key, visible: $visible), + 'video' => new VideoLinkColumn(key: $key, name: $key, visible: $visible), + ]; + + $columnByKey = null; + foreach ($keysMap as $colKey => $column) { + if (Strings::contains($key, $colKey)) { + $columnByKey = $column; + } + } + return match ($type) { Types::ASCII_STRING, Types::BIGINT, @@ -201,7 +220,7 @@ protected function createColumnInstance(string $type, string $key, bool $visible Types::DECIMAL, Types::GUID, Types::STRING, - Types::TEXT => new StringColumn(key: $key, name: $key, visible: $visible), + Types::TEXT => $columnByKey ?: new StringColumn(key: $key, name: $key, visible: $visible), Types::BLOB => new BlobColumn(key: $key, name: $key, visible: $visible),