Skip to content

Commit 886dc05

Browse files
committed
Merge remote-tracking branch 'origin/master'
2 parents bb11e0e + 3d0ed8e commit 886dc05

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The main motive for this library is an environment where a lot of things are aut
1414
Here a few things to keep in mind:
1515

1616
* The charset is up to you. No special binding to UTF8, although UTF8 is the default.
17+
* You're allowed to nest most queries to build big and powerful queries.
1718
* The order of method-calls of each statement-builder is irrelevant. The resulting query will always render the right order.
1819
* No animals were harmed due to the production of this library.
1920
* The order of method-calls doesn't matter.

doc/optional-conditions.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Optional conditions
22

3+
Sometimes you want to set conditions based on dynamic data. One example would be a grid-list with dynamic filters for certain columns. Following the example below, you can predefine _optional conditions_ which will execute when the corresponding data in the `$filter`-Array is present.
4+
35
```PHP
46
$filter = [
57
'name' => 'Peter',
@@ -9,15 +11,19 @@ $filter = [
911
],
1012
];
1113

12-
$req = new RequiredFilterMap($filter);
13-
$opt = new OptionalFilterMap($filter);
14+
$orderBy = [
15+
['date', 'DESC'], // Define the Sort-Order as a Multi-Value-Field
16+
['name' => 'ASC'], // ... or define the Sort-Order as a Key-Value-Field
17+
];
1418

1519
$query = $db
1620
->from('t', 'test')
17-
->where($req('t.name=?', $filter, 'name'))
18-
->where($opt('t.date >= ?', $filter, 'date.start')) // Key in dot-notation
19-
->where($opt('t.date <= ?', $filter, ['date', 'end'])) // Array-Key
21+
->where(new DBExprFilter('t.name = ?', $filter, 'name'))
22+
->where(new DBExprFilter('t.date >= ?', $filter, 'date.start')) // Key in dot-notation
23+
->where(new DBExprFilter('t.date <= ?', $filter, ['date', 'end'])) // Key in array-notation
24+
->orderBy(new DBExprOrderBySpec(['name', 'date' => 'DATE(t.date)'], $orderBy))
2025
```
2126

27+
You can also define validation rules to only match certain data in `$filter`.
2228

2329
[Back](../README.md)

0 commit comments

Comments
 (0)