From c21932b68a6a291a412881600ad9b22517736d6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Wed, 18 Oct 2023 17:25:32 +0200 Subject: [PATCH] Feat: Implement destination autocompletion by date --- composer.json | 1 + composer.lock | 59 +++++++++++++++++++++++- config/packages/doctrine.yaml | 4 +- src/Repository/DestinationRepository.php | 9 ++-- 4 files changed, 67 insertions(+), 6 deletions(-) diff --git a/composer.json b/composer.json index 3b9414d..87b49f8 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ "ext-ctype": "*", "ext-iconv": "*", "ext-simplexml": "*", + "beberlei/doctrineextensions": "^1.3", "doctrine/doctrine-bundle": "^2.10", "doctrine/doctrine-migrations-bundle": "^3.2", "doctrine/orm": "^2.15", diff --git a/composer.lock b/composer.lock index aa27e7d..97ecc29 100644 --- a/composer.lock +++ b/composer.lock @@ -4,8 +4,65 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "51c0d10a5e4bd074ddab5fe5717af560", + "content-hash": "9018bf9f3712da46a5f6d428cd540cb0", "packages": [ + { + "name": "beberlei/doctrineextensions", + "version": "v1.3.0", + "source": { + "type": "git", + "url": "https://github.com/beberlei/DoctrineExtensions.git", + "reference": "008f162f191584a6c37c03a803f718802ba9dd9a" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/beberlei/DoctrineExtensions/zipball/008f162f191584a6c37c03a803f718802ba9dd9a", + "reference": "008f162f191584a6c37c03a803f718802ba9dd9a", + "shasum": "" + }, + "require": { + "doctrine/orm": "^2.7", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.14", + "nesbot/carbon": "*", + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0", + "symfony/yaml": "^4.2 || ^5.0", + "zf1/zend-date": "^1.12", + "zf1/zend-registry": "^1.12" + }, + "type": "library", + "autoload": { + "psr-4": { + "DoctrineExtensions\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Benjamin Eberlei", + "email": "kontakt@beberlei.de" + }, + { + "name": "Steve Lacey", + "email": "steve@steve.ly" + } + ], + "description": "A set of extensions to Doctrine 2 that add support for additional query functions available in MySQL, Oracle, PostgreSQL and SQLite.", + "keywords": [ + "database", + "doctrine", + "orm" + ], + "support": { + "source": "https://github.com/beberlei/DoctrineExtensions/tree/v1.3.0" + }, + "time": "2020-11-29T07:37:23+00:00" + }, { "name": "doctrine/cache", "version": "2.2.0", diff --git a/config/packages/doctrine.yaml b/config/packages/doctrine.yaml index 88671ee..bf4e01c 100644 --- a/config/packages/doctrine.yaml +++ b/config/packages/doctrine.yaml @@ -18,7 +18,9 @@ doctrine: dir: '%kernel.project_dir%/src/Entity' prefix: 'App\Entity' alias: App - + dql: + string_functions: + DATE_FORMAT: DoctrineExtensions\Query\Mysql\DateFormat when@test: doctrine: dbal: diff --git a/src/Repository/DestinationRepository.php b/src/Repository/DestinationRepository.php index 6701e38..7265baf 100644 --- a/src/Repository/DestinationRepository.php +++ b/src/Repository/DestinationRepository.php @@ -30,11 +30,12 @@ class DestinationRepository extends ServiceEntityRepository $dates = $qb ->where($qb->expr()->orX( - $qb->expr()->like('destination.product', ':product'), - $qb->expr()->like('destination.hotel', ':hotel') + $qb->expr()->like('destination.product', ':search'), + $qb->expr()->like('destination.hotel', ':search'), + $qb->expr()->like('DATE_FORMAT(destination.dateFrom, \'%d.%m.%y\')', ':search'), + $qb->expr()->like('DATE_FORMAT(destination.dateTo, \'%d.%m.%y\')', ':search') )) - ->setParameter('product', '%'.$this->escapeLikeWildcards($search).'%') - ->setParameter('hotel', '%'.$this->escapeLikeWildcards($search).'%') + ->setParameter('search', '%'.$this->escapeLikeWildcards($search).'%') ->orderBy('destination.dateFrom', 'ASC') ->addOrderBy('destination.product', 'ASC') ->getQuery()