diff --git a/README.md b/README.md index 09e3d81..3cc7836 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/src/Adapters/QueryBuilder.php b/src/Adapters/QueryBuilder.php index 0da4dff..0d83f35 100644 --- a/src/Adapters/QueryBuilder.php +++ b/src/Adapters/QueryBuilder.php @@ -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 '='; } @@ -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(), diff --git a/src/Field.php b/src/Field.php index b4151e0..e4ca88f 100644 --- a/src/Field.php +++ b/src/Field.php @@ -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. @@ -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));