Skip to content

Commit f990c88

Browse files
committed
Changed to grouping
Changed the method from `whereGroup` to `grouping` and moved the flatten function to be a private method in the `ezQuery` file as per @techno-express recommendations.
1 parent 1637812 commit f990c88

File tree

7 files changed

+28
-28
lines changed

7 files changed

+28
-28
lines changed

lib/ezFunctions.php

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -349,11 +349,11 @@ function where(...$args)
349349
: false;
350350
}
351351

352-
function whereGroup(...$args)
352+
function grouping(...$args)
353353
{
354354
$ezQuery = \getInstance();
355355
return ($ezQuery instanceof DatabaseInterface)
356-
? $ezQuery->whereGroup(...$args)
356+
? $ezQuery->grouping(...$args)
357357
: false;
358358
}
359359

@@ -493,19 +493,6 @@ function replace($table = '', $keyValue)
493493
: false;
494494
}
495495

496-
function flattenWhereConditions($whereConditions)
497-
{
498-
$whereConditionsReturn = [];
499-
foreach ($whereConditions as $whereCondition) {
500-
if (!empty($whereCondition[0]) && is_array($whereCondition[0])) {
501-
$whereConditionsReturn = array_merge($whereConditionsReturn, flattenWhereConditions($whereCondition));
502-
} else {
503-
$whereConditionsReturn[] = $whereCondition;
504-
}
505-
}
506-
return $whereConditionsReturn;
507-
}
508-
509496
function ezFunctions()
510497
{
511498
return true;

lib/ezQuery.php

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,22 @@ private function conditionIs($key, $condition, $combine)
391391
$this->whereSQL .= "$key $isCondition NULL $combine ";
392392
}
393393

394+
private function flattenWhereConditions($whereConditions)
395+
{
396+
$whereConditionsReturn = [];
397+
foreach ($whereConditions as $whereCondition) {
398+
if (!empty($whereCondition[0]) && is_array($whereCondition[0])) {
399+
$whereConditionsReturn = array_merge($whereConditionsReturn, $this->flattenWhereConditions($whereCondition));
400+
} else {
401+
$whereConditionsReturn[] = $whereCondition;
402+
}
403+
}
404+
return $whereConditionsReturn;
405+
}
406+
394407
private function retrieveConditions($whereConditions)
395408
{
396-
$whereConditions = flattenWhereConditions($whereConditions);
409+
$whereConditions = $this->flattenWhereConditions($whereConditions);
397410
$whereKey = [];
398411
$whereValue = [];
399412
$operator = [];
@@ -442,7 +455,7 @@ private function processConditions($column, $condition, $value, $valueOrCombine,
442455
}
443456
}
444457

445-
public function whereGroup(...$whereConditions)
458+
public function grouping(...$whereConditions)
446459
{
447460
if (empty($whereConditions))
448461
return false;

lib/ezQueryInterface.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,10 @@ public function limit($numberOf, $offset = null);
298298
* Helper adds WHERE grouping to the conditions
299299
*
300300
* format:
301-
* `whereGroup( comparison(x, y, and) )`
301+
* `grouping( comparison(x, y, and) )`
302302
*
303303
* example:
304-
* `whereGroup( eq(key, value, combiner ), eq(key, value, combiner ) );`
304+
* `grouping( eq(key, value, combiner ), eq(key, value, combiner ) );`
305305
*
306306
* @param array $whereConditions - In the following format:
307307
*
@@ -319,7 +319,7 @@ public function limit($numberOf, $offset = null);
319319
*
320320
* @return array modified conditions
321321
*/
322-
public function whereGroup(...$whereConditions);
322+
public function grouping(...$whereConditions);
323323

324324
/**
325325
* Helper returns an WHERE sql clause string.

tests/pdo/pdo_mysqlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ public function testSelecting()
265265
$this->assertEquals(0, $this->object->query('DROP TABLE unit_test'));
266266
}
267267

268-
public function testWhereGroup()
268+
public function testWhereGrouping()
269269
{
270270
$this->assertTrue($this->object->connect('mysql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
271271
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))');
@@ -274,7 +274,7 @@ public function testWhereGroup()
274274
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1));
275275
$this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1));
276276

277-
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), whereGroup(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
277+
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
278278
$i = 1;
279279
foreach ($result as $row) {
280280
$this->assertEquals($i, $row->id);

tests/pdo/pdo_pgsqlTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public function testSelecting()
189189
}
190190
}
191191

192-
public function testWhereGroup()
192+
public function testWhereGrouping()
193193
{
194194
$this->assertTrue($this->object->connect('pgsql:host=' . self::TEST_DB_HOST . ';dbname=' . self::TEST_DB_NAME . ';port=' . self::TEST_DB_PORT, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
195195
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))');
@@ -198,7 +198,7 @@ public function testWhereGroup()
198198
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1));
199199
$this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1));
200200

201-
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), whereGroup(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
201+
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
202202
$i = 1;
203203
foreach ($result as $row) {
204204
$this->assertEquals($i, $row->id);

tests/pdo/pdo_sqliteTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ public function testSelecting()
216216
$this->assertEquals(1, $this->object->query('DROP TABLE unit_test'));
217217
}
218218

219-
public function testWhereGroup()
219+
public function testWhereGrouping()
220220
{
221221
$this->assertTrue($this->object->connect('sqlite:' . self::TEST_SQLITE_DB, '', '', array(), true));
222222
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))');
@@ -225,7 +225,7 @@ public function testWhereGroup()
225225
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1));
226226
$this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1));
227227

228-
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), whereGroup(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
228+
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
229229
$i = 1;
230230
foreach ($result as $row) {
231231
$this->assertEquals($i, $row->id);

tests/pdo/pdo_sqlsrvTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ public function testSelecting()
193193
}
194194
}
195195

196-
public function testWhereGroup()
196+
public function testWhereGrouping()
197197
{
198198
$this->assertTrue($this->object->connect('sqlsrv:Server=' . self::TEST_DB_HOST . ';Database=' . self::TEST_DB_NAME, self::TEST_DB_USER, self::TEST_DB_PASSWORD));
199199
$this->object->query('CREATE TABLE unit_test(id integer, test_key varchar(50), active tinyint(1), PRIMARY KEY (ID))');
@@ -202,7 +202,7 @@ public function testWhereGroup()
202202
$this->object->insert('unit_test', array('id' => '3', 'test_key' => 'testing 3', 'active' => 1));
203203
$this->object->insert('unit_test', array('id' => '4', 'test_key' => 'testing 4', 'active' => 1));
204204

205-
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), whereGroup(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
205+
$result = $this->object->selecting('unit_test', '*', where(eq('active', '1'), grouping(like('test_key', '%1%', _OR), like('test_key', '%3%'))));
206206
$i = 1;
207207
foreach ($result as $row) {
208208
$this->assertEquals($i, $row->id);

0 commit comments

Comments
 (0)