@@ -153,6 +153,41 @@ public function initialise($container)
153153 *
154154 * @return string
155155 */
156+ protected function getTranslationFieldNameWithParents ($ column )
157+ {
158+ $ name = $ column ->getField ();
159+
160+ if ($ column ->getIsManualField ()) {
161+ return $ column ->getField ();
162+ }
163+
164+ if (strpos ($ name , '. ' ) !== false ) {
165+ $ previousParent = '' ;
166+
167+ $ elements = explode ('. ' , $ name );
168+ while ($ element = array_shift ($ elements )) {
169+ if (count ($ elements ) > 0 ) {
170+ $ previousParent .= '_ ' . $ element ;
171+ }
172+ }
173+ } elseif (strpos ($ name , ': ' ) !== false ) {
174+ $ previousParent = $ this ->getTableAlias ();
175+ } else {
176+ return $ this ->getTableAlias ().'. ' .$ name ;
177+ }
178+
179+ $ matches = array ();
180+ if ($ column ->hasDQLFunction ($ matches )) {
181+ return $ previousParent .'. ' .$ matches ['field ' ];
182+ }
183+
184+ return $ column ->getField ();
185+ }
186+
187+ /**
188+ * @param \APY\DataGridBundle\Grid\Column\Column $column
189+ * @return string
190+ */
156191 protected function getFieldName ($ column , $ withAlias = false )
157192 {
158193 $ name = $ column ->getField ();
@@ -373,7 +408,11 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr
373408
374409 $ isDisjunction = $ column ->getDataJunction () === Column::DATA_DISJUNCTION ;
375410
376- $ hasHavingClause = $ column ->hasDQLFunction () || $ column ->getIsAggregate ();
411+ $ dqlMatches = [];
412+ $ hasHavingClause = $ column ->hasDQLFunction ($ dqlMatches ) || $ column ->getIsAggregate ();
413+ if (isset ($ dqlMatches ['function ' ]) && $ dqlMatches ['function ' ] == 'translation_agg ' ){
414+ $ hasHavingClause = false ;
415+ }
377416
378417 $ sub = $ isDisjunction ? $ this ->query ->expr ()->orx () : ($ hasHavingClause ? $ this ->query ->expr ()->andx () : $ where );
379418
@@ -384,8 +423,17 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr
384423
385424 $ fieldName = $ this ->getFieldName ($ columnForFilter , false );
386425 $ bindIndexPlaceholder = "? $ bindIndex " ;
387- if (in_array ($ filter ->getOperator (), [Column::OPERATOR_LIKE , Column::OPERATOR_RLIKE , Column::OPERATOR_LLIKE , Column::OPERATOR_NLIKE ])) {
388- $ fieldName = "LOWER( $ fieldName) " ;
426+
427+ if ( in_array ($ filter ->getOperator (), array (Column::OPERATOR_LIKE ,Column::OPERATOR_RLIKE ,Column::OPERATOR_LLIKE ,Column::OPERATOR_NLIKE ,))){
428+ if (isset ($ dqlMatches ['function ' ]) && $ dqlMatches ['function ' ] == 'translation_agg ' ){
429+ $ translationFieldName = $ this ->getTranslationFieldNameWithParents ($ columnForFilter );
430+ $ fieldName = "LOWER( " .$ translationFieldName .") " ;
431+ }elseif (isset ($ dqlMatches ['function ' ]) && $ dqlMatches ['function ' ] == 'role_agg ' ){
432+ $ translationFieldName = $ this ->getTranslationFieldNameWithParents ($ columnForFilter );
433+ $ fieldName = "LOWER( " .$ translationFieldName .") " ;
434+ }else {
435+ $ fieldName = "LOWER( $ fieldName) " ;
436+ }
389437 $ bindIndexPlaceholder = "LOWER( $ bindIndexPlaceholder) " ;
390438 }
391439
0 commit comments