@@ -500,38 +500,68 @@ private function setJoins(QueryBuilder $qb)
500
500
*/
501
501
private function setWhere (QueryBuilder $ qb )
502
502
{
503
+ // Retrieving parameter counter
504
+ $ parameterCounter = self ::INIT_PARAMETER_COUNTER ;
505
+
503
506
// global filtering
504
507
if (isset ($ this ->requestParams ['search ' ]) && '' !== $ this ->requestParams ['search ' ]['value ' ]) {
505
- $ orExpr = $ qb ->expr ()->orX ();
506
508
507
509
$ globalSearch = $ this ->requestParams ['search ' ]['value ' ];
508
510
$ globalSearchType = $ this ->options ->getGlobalSearchType ();
509
511
510
- foreach ($ this ->columns as $ key => $ column ) {
511
- if (true === $ this ->isSearchableColumn ($ column )) {
512
- /** @var AbstractFilter $filter */
513
- $ filter = $ this ->accessor ->getValue ($ column , 'filter ' );
514
- $ searchType = $ globalSearchType ;
515
- $ searchFields = (array ) $ this ->searchColumns [$ key ];
516
- $ searchValue = $ globalSearch ;
517
- $ searchTypeOfField = $ column ->getTypeOfField ();
518
- foreach ($ searchFields as $ searchField ) {
519
- $ orExpr = $ filter ->addOrExpression ($ orExpr , $ qb , $ searchType , $ searchField , $ searchValue , $ searchTypeOfField , $ key );
512
+ // If global search type is a list of key words
513
+ if ($ globalSearchType == 'keywords_string ' ) {
514
+
515
+ // Removing unnecessary spaces at the beginning and at the end
516
+ $ globalSearch = trim ($ globalSearch );
517
+
518
+ // Removing multiples spaces
519
+ $ globalSearch = preg_replace ('!\s+! ' , ' ' , $ globalSearch );
520
+
521
+ // Parsing search value to array of keywords
522
+ $ keywords = explode (' ' , $ globalSearch );
523
+
524
+ // Setting type of search type to 'like'
525
+ $ globalSearchType = 'like ' ;
526
+
527
+ // Else considering only one searchstring
528
+ } else {
529
+ $ keywords = [$ globalSearch ];
530
+ }
531
+
532
+ // Iterating through each keyword
533
+ foreach ($ keywords as $ k => $ word ) {
534
+
535
+ // Initialising 'OR' expression
536
+ $ orExpr = $ qb ->expr ()->orX ();
537
+
538
+ // Iterating through columns
539
+ foreach ($ this ->columns as $ key => $ column ) {
540
+
541
+ if (true === $ this ->isSearchableColumn ($ column )) {
542
+ /** @var AbstractFilter $filter */
543
+ $ filter = $ this ->accessor ->getValue ($ column , 'filter ' );
544
+ $ searchType = $ globalSearchType ;
545
+ $ searchFields = (array ) $ this ->searchColumns [$ key ];
546
+ $ searchValue = $ keywords [$ k ];
547
+ $ searchTypeOfField = $ column ->getTypeOfField ();
548
+ foreach ($ searchFields as $ searchField ) {
549
+ $ orExpr = $ filter ->addOrExpression ($ orExpr , $ qb , $ searchType , $ searchField , $ searchValue , $ searchTypeOfField , $ parameterCounter );
550
+ }
520
551
}
521
552
}
522
- }
523
-
524
- if ($ orExpr ->count () > 0 ) {
525
- $ qb ->andWhere ($ orExpr );
553
+
554
+ // Adding 'OR' expression to global 'WHERE'
555
+ if ($ orExpr ->count () > 0 ) {
556
+ $ qb ->andWhere ($ orExpr );
557
+ }
526
558
}
527
559
}
528
560
529
561
// individual filtering
530
562
if (true === $ this ->accessor ->getValue ($ this ->options , 'individualFiltering ' )) {
531
563
$ andExpr = $ qb ->expr ()->andX ();
532
564
533
- $ parameterCounter = self ::INIT_PARAMETER_COUNTER ;
534
-
535
565
foreach ($ this ->columns as $ key => $ column ) {
536
566
if (true === $ this ->isSearchableColumn ($ column )) {
537
567
if (false === \array_key_exists ($ key , $ this ->requestParams ['columns ' ])) {
0 commit comments