Skip to content

Commit

Permalink
Added DB columns keys map
Browse files Browse the repository at this point in the history
  • Loading branch information
jzaplet committed Mar 25, 2024
1 parent 5bec6e6 commit 11c161a
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/Collection/ReadBuilder/ReadBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -194,14 +199,28 @@ 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,
Types::BINARY,
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),

Expand Down

0 comments on commit 11c161a

Please sign in to comment.