Skip to content

Commit

Permalink
Merge pull request #10 from ghonijee/development
Browse files Browse the repository at this point in the history
Update Config & Sort Query Builder
  • Loading branch information
ghonijee authored Nov 7, 2021
2 parents c95d0c9 + 7e457e3 commit 2cbdb2b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

## Documentation
Full Documentation [QueryAdapter Docs](https://query-adapter.netlify.app/docs/). This site documentation is under development.

## Installation

You can install the package via composer:
Expand Down
2 changes: 1 addition & 1 deletion config/dx-adapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@
'take' => 'take',
],
'query' => [
'contains' => 'LIKE'
'contains' => 'like'
]
];
26 changes: 14 additions & 12 deletions src/FilterClass/QueryClass/StringFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.query.contains') ?: "like";
}

public static function build($query, $filterData, $conjungtion)
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2cbdb2b

Please sign in to comment.