Skip to content

Commit

Permalink
Add LIKE and ILIKE approvals
Browse files Browse the repository at this point in the history
  • Loading branch information
Dick van der Heiden committed Sep 8, 2017
1 parent 76520f0 commit d92a24e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ $field = new Field($fieldKey, $fieldValue);

A field has the ability to accept, reject or see the value as part of a range with a third optional parameter. These
parameters are constants of the field `APPROVAL_ACCEPT`, `APPROVAL_REJECT`, `APPROVAL_START_OF_RANGE`,
`APPROVAL_END_OF_RANGE`, `APPROVAL_IN` and `APPROVAL_NOT_IN`.
`APPROVAL_END_OF_RANGE`, `APPROVAL_IN`, `APPROVAL_NOT_IN`, `APPROVAL_LIKE` and `APPROVAL_ILIKE` (which can only be used
if your Database supports it, like Postgres).

The field is a member of a group. The group has a conjunction, which are constants of the group called
`CONJUNCTION_AND` and `CONJUCTION_OR`.
Expand Down
13 changes: 13 additions & 0 deletions src/Adapters/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ private function getFilterFieldOperator($approval)
return '>=';
case Field::APPROVAL_END_OF_RANGE :
return '<=';
case Field::APPROVAL_LIKE :
return 'LIKE';
case Field::APPROVAL_ILIKE :
return 'ILIKE';
default :
return '=';
}
Expand Down Expand Up @@ -53,6 +57,15 @@ public function getFilterFieldQuery(Builder $query, Field $field, $method = 'and
$method
);
break;
case Field::APPROVAL_LIKE :
case Field::APPROVAL_ILIKE :
$query->where(
$field->getOption(),
$this->getFilterFieldOperator($field->getApproval()),
sprintf('%%%s%%', $field->getValue()),
$method
);
break;
default :
$query->where(
$field->getOption(),
Expand Down
4 changes: 4 additions & 0 deletions src/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ class Field implements Arrayable
const APPROVAL_END_OF_RANGE = 3;
const APPROVAL_IN = 4;
const APPROVAL_NOT_IN = 5;
const APPROVAL_LIKE = 6;
const APPROVAL_ILIKE = 7;

/**
* Holds the name of the option.
Expand Down Expand Up @@ -111,6 +113,8 @@ private function setApproval($approval)
self::APPROVAL_END_OF_RANGE,
self::APPROVAL_IN,
self::APPROVAL_NOT_IN,
self::APPROVAL_LIKE,
self::APPROVAL_ILIKE,
];
if (! in_array($approval, $availableApprovals)) {
throw new InvalidApprovalException(sprintf('Approval "%s" is not supported', $approval));
Expand Down

0 comments on commit d92a24e

Please sign in to comment.