From 243510a34e7a54c9921d387ec814ff04bd545d44 Mon Sep 17 00:00:00 2001 From: ghonijee Date: Sat, 6 Nov 2021 06:29:37 +0700 Subject: [PATCH 1/4] update: string filter like by config --- src/FilterClass/QueryClass/StringFilter.php | 26 +++++++++++---------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/FilterClass/QueryClass/StringFilter.php b/src/FilterClass/QueryClass/StringFilter.php index f5edfce..2c09a97 100644 --- a/src/FilterClass/QueryClass/StringFilter.php +++ b/src/FilterClass/QueryClass/StringFilter.php @@ -9,12 +9,14 @@ class StringFilter protected $query; protected $filterData; protected $conjungtion; + protected $contains; public function __construct($query, $filterData, $conjungtion) { $this->query = $query; $this->filterData = $filterData; $this->conjungtion = $conjungtion; + $this->contains = config('dx-adapter.request.like') ?: "like"; } public static function build($query, $filterData, $conjungtion) @@ -43,16 +45,16 @@ protected function notCondition() { switch ($this->filterData->condition) { case 'contains': - $this->query->orWhere($this->filterData->field, 'not like', "%{$this->filterData->value}%"); + $this->query->orWhere($this->filterData->field, "not $this->contains", "%{$this->filterData->value}%"); break; case 'notcontains': - $this->query->orWhere($this->filterData->field, 'like', "%{$this->filterData->value}%"); + $this->query->orWhere($this->filterData->field, "$this->contains", "%{$this->filterData->value}%"); break; case 'startswith': - $this->query->orWhere($this->filterData->field, 'not like', "{$this->filterData->value}%"); + $this->query->orWhere($this->filterData->field, "not $this->contains", "{$this->filterData->value}%"); break; case 'endswith': - $this->query->orWhere($this->filterData->field, 'not like', "%{$this->filterData->value}"); + $this->query->orWhere($this->filterData->field, "not $this->contains", "%{$this->filterData->value}"); break; case '=': $this->query->whereNot($this->filterData->field, $this->filterData->value); @@ -67,16 +69,16 @@ protected function orCondition() { switch ($this->filterData->condition) { case 'contains': - $this->query->orWhere($this->filterData->field, 'like', "%{$this->filterData->value}%"); + $this->query->orWhere($this->filterData->field, "$this->contains", "%{$this->filterData->value}%"); break; case 'notcontains': - $this->query->orWhere($this->filterData->field, 'not like', "%{$this->filterData->value}%"); + $this->query->orWhere($this->filterData->field, "not $this->contains", "%{$this->filterData->value}%"); break; case 'startswith': - $this->query->orWhere($this->filterData->field, 'like', "{$this->filterData->value}%"); + $this->query->orWhere($this->filterData->field, "$this->contains", "{$this->filterData->value}%"); break; case 'endswith': - $this->query->orWhere($this->filterData->field, 'like', "%{$this->filterData->value}"); + $this->query->orWhere($this->filterData->field, "$this->contains", "%{$this->filterData->value}"); break; case '=': $this->query->orWhere($this->filterData->field, $this->filterData->value); @@ -90,16 +92,16 @@ protected function andCondition() { switch ($this->filterData->condition) { case 'contains': - $this->query->where($this->filterData->field, 'like', "%{$this->filterData->value}%"); + $this->query->where($this->filterData->field, "$this->contains", "%{$this->filterData->value}%"); break; case 'notcontains': - $this->query->where($this->filterData->field, 'not like', "%{$this->filterData->value}%"); + $this->query->where($this->filterData->field, "not $this->contains", "%{$this->filterData->value}%"); break; case 'startswith': - $this->query->where($this->filterData->field, 'like', "{$this->filterData->value}%"); + $this->query->where($this->filterData->field, "$this->contains", "{$this->filterData->value}%"); break; case 'endswith': - $this->query->where($this->filterData->field, 'like', "%{$this->filterData->value}"); + $this->query->where($this->filterData->field, "$this->contains", "%{$this->filterData->value}"); break; case '=': $this->query->where($this->filterData->field, $this->filterData->value); From 82388c032450803bc25243d476ea5f30c423ee90 Mon Sep 17 00:00:00 2001 From: ghonijee Date: Sun, 7 Nov 2021 20:33:38 +0700 Subject: [PATCH 2/4] update: add documentation link --- README.md | 3 +++ config/dx-adapter.php | 2 +- src/FilterClass/QueryClass/StringFilter.php | 2 +- tests/TestCase.php | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 96106b3..8a9008e 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ [![Total Downloads](https://img.shields.io/packagist/dt/ghonijee/query-adapter.svg?style=flat-square)](https://packagist.org/packages/ghonijee/query-adapter) [![Actions Status](https://github.com/ghonijee/laravel-query-adapter/actions/workflows/main.yml/badge.svg)](https://github.com/ghonijee/laravel-query-adapter/actions) +## Documenatation +Full Documentation [!Query Adapter Docs](https://query-adapter.netlify.app/docs/). This site documentation is under development. + ## Installation You can install the package via composer: diff --git a/config/dx-adapter.php b/config/dx-adapter.php index b0751d6..d2a0681 100644 --- a/config/dx-adapter.php +++ b/config/dx-adapter.php @@ -12,6 +12,6 @@ 'take' => 'take', ], 'query' => [ - 'contains' => 'LIKE' + 'contains' => 'like' ] ]; diff --git a/src/FilterClass/QueryClass/StringFilter.php b/src/FilterClass/QueryClass/StringFilter.php index 2c09a97..b610713 100644 --- a/src/FilterClass/QueryClass/StringFilter.php +++ b/src/FilterClass/QueryClass/StringFilter.php @@ -16,7 +16,7 @@ public function __construct($query, $filterData, $conjungtion) $this->query = $query; $this->filterData = $filterData; $this->conjungtion = $conjungtion; - $this->contains = config('dx-adapter.request.like') ?: "like"; + $this->contains = config('dx-adapter.query.contains') ?: "like"; } public static function build($query, $filterData, $conjungtion) diff --git a/tests/TestCase.php b/tests/TestCase.php index 47b77e0..6e4d101 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -44,7 +44,7 @@ protected function usesMySqlConnection(Application $app) $app->config->set('dx-adapter.request.order', 'sort'); $app->config->set('dx-adapter.request.skip', 'skip'); $app->config->set('dx-adapter.request.take', 'take'); - $app->config->set('dx-adapter.query.contains', 'LIKE'); + $app->config->set('dx-adapter.query.contains', 'like'); } protected function getPackageProviders($app) From c83245eecc8f7abbbef6108e272a73020bc7587d Mon Sep 17 00:00:00 2001 From: ghonijee Date: Sun, 7 Nov 2021 20:38:11 +0700 Subject: [PATCH 3/4] refactore Readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 8a9008e..6bae074 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Actions Status](https://github.com/ghonijee/laravel-query-adapter/actions/workflows/main.yml/badge.svg)](https://github.com/ghonijee/laravel-query-adapter/actions) ## Documenatation -Full Documentation [!Query Adapter Docs](https://query-adapter.netlify.app/docs/). This site documentation is under development. +Full Documentation [QueryAdapter Docs](https://query-adapter.netlify.app/docs/). This site documentation is under development. ## Installation From 7e457e3bb397e3c7e1933b03d7c7d268bec9b938 Mon Sep 17 00:00:00 2001 From: ghonijee Date: Sun, 7 Nov 2021 20:38:54 +0700 Subject: [PATCH 4/4] refactoring --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6bae074..cf8b99b 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![Total Downloads](https://img.shields.io/packagist/dt/ghonijee/query-adapter.svg?style=flat-square)](https://packagist.org/packages/ghonijee/query-adapter) [![Actions Status](https://github.com/ghonijee/laravel-query-adapter/actions/workflows/main.yml/badge.svg)](https://github.com/ghonijee/laravel-query-adapter/actions) -## Documenatation +## Documentation Full Documentation [QueryAdapter Docs](https://query-adapter.netlify.app/docs/). This site documentation is under development. ## Installation