@@ -411,36 +411,66 @@ private function setJoins(QueryBuilder $qb)
411
411
*/
412
412
private function setWhere (QueryBuilder $ qb )
413
413
{
414
+ // Retrieving parameter counter
415
+ $ parameterCounter = DatatableQueryBuilder::INIT_PARAMETER_COUNTER ;
416
+
414
417
// global filtering
415
418
if (isset ($ this ->requestParams ['search ' ]) && '' != $ this ->requestParams ['search ' ]['value ' ]) {
416
- $ orExpr = $ qb ->expr ()->orX ();
417
419
418
420
$ globalSearch = $ this ->requestParams ['search ' ]['value ' ];
419
421
$ globalSearchType = $ this ->options ->getGlobalSearchType ();
420
422
421
- foreach ($ this ->columns as $ key => $ column ) {
422
- if (true === $ this ->isSearchableColumn ($ column )) {
423
- /** @var AbstractFilter $filter */
424
- $ filter = $ this ->accessor ->getValue ($ column , 'filter ' );
425
- $ searchType = $ globalSearchType ;
426
- $ searchField = $ this ->searchColumns [$ key ];
427
- $ searchValue = $ globalSearch ;
428
- $ searchTypeOfField = $ column ->getTypeOfField ();
429
- $ orExpr = $ filter ->addOrExpression ($ orExpr , $ qb , $ searchType , $ searchField , $ searchValue , $ searchTypeOfField , $ key );
430
- }
423
+ // If global search type is a list of key words
424
+ if ($ globalSearchType == 'keywords_string ' ) {
425
+
426
+ // Removing unnecessary spaces at the beginning and at the end
427
+ $ globalSearch = trim ($ globalSearch );
428
+
429
+ // Removing multiples spaces
430
+ $ globalSearch = preg_replace ('!\s+! ' , ' ' , $ globalSearch );
431
+
432
+ // Parsing search value to array of keywords
433
+ $ keywords = explode (' ' , $ globalSearch );
434
+
435
+ // Setting type of search type to 'like'
436
+ $ globalSearchType = 'like ' ;
437
+
438
+ // Else considering only one searchstring
439
+ } else {
440
+ $ keywords = [$ globalSearch ];
431
441
}
432
-
433
- if ($ orExpr ->count () > 0 ) {
434
- $ qb ->andWhere ($ orExpr );
442
+
443
+ // Iterating through each keyword
444
+ foreach ($ keywords as $ k => $ word ) {
445
+
446
+ // Initialising 'OR' expression
447
+ $ orExpr = $ qb ->expr ()->orX ();
448
+
449
+ // Iterating through columns
450
+ foreach ($ this ->columns as $ key => $ column ) {
451
+
452
+ if (true === $ this ->isSearchableColumn ($ column )) {
453
+ /** @var AbstractFilter $filter */
454
+ $ filter = $ this ->accessor ->getValue ($ column , 'filter ' );
455
+ $ searchType = $ globalSearchType ;
456
+ $ searchField = $ this ->searchColumns [$ key ];
457
+ $ searchValue = $ keywords [$ k ];
458
+ $ searchTypeOfField = $ column ->getTypeOfField ();
459
+ $ orExpr = $ filter ->addOrExpression ($ orExpr , $ qb , $ searchType , $ searchField , $ searchValue , $ searchTypeOfField , $ parameterCounter );
460
+ }
461
+ }
462
+
463
+ // Adding 'OR' expression to global 'WHERE'
464
+ if ($ orExpr ->count () > 0 ) {
465
+ $ qb ->andWhere ($ orExpr );
466
+ }
435
467
}
436
468
}
437
469
438
470
// individual filtering
439
471
if (true === $ this ->accessor ->getValue ($ this ->options , 'individualFiltering ' )) {
440
472
$ andExpr = $ qb ->expr ()->andX ();
441
473
442
- $ parameterCounter = DatatableQueryBuilder::INIT_PARAMETER_COUNTER ;
443
-
444
474
foreach ($ this ->columns as $ key => $ column ) {
445
475
if (true === $ this ->isSearchableColumn ($ column )) {
446
476
if (false === array_key_exists ($ key , $ this ->requestParams ['columns ' ])) {
0 commit comments