From 219bd7b2c9f781da360feb5809c30a4be0cb163f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Behram=20=C3=87ELEN?= Date: Sat, 12 Nov 2016 20:25:01 +0300 Subject: [PATCH 1/4] translation aggregation filter type support on entity source --- Grid/Source/Entity.php | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Grid/Source/Entity.php b/Grid/Source/Entity.php index 432ac908..aa13f038 100644 --- a/Grid/Source/Entity.php +++ b/Grid/Source/Entity.php @@ -367,7 +367,11 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr $isDisjunction = $column->getDataJunction() === Column::DATA_DISJUNCTION; - $hasHavingClause = $column->hasDQLFunction() || $column->getIsAggregate(); + $dqlMatches = []; + $hasHavingClause = $column->hasDQLFunction($dqlMatches) || $column->getIsAggregate(); + if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ + $hasHavingClause = false; + } $sub = $isDisjunction ? $this->query->expr()->orx() : ($hasHavingClause ? $this->query->expr()->andx() : $where); @@ -378,11 +382,15 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr $fieldName = $this->getFieldName($columnForFilter, false); $bindIndexPlaceholder = "?$bindIndex"; - if (in_array($filter->getOperator(), array(Column::OPERATOR_LIKE,Column::OPERATOR_RLIKE,Column::OPERATOR_LLIKE,Column::OPERATOR_NLIKE,))) { - $fieldName = "LOWER($fieldName)"; + if( in_array($filter->getOperator(), array(Column::OPERATOR_LIKE,Column::OPERATOR_RLIKE,Column::OPERATOR_LLIKE,Column::OPERATOR_NLIKE,))){ + if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ + $fieldName = "LOWER(_translations.".$dqlMatches['field'].")"; + }else{ + $fieldName = "LOWER($fieldName)"; + } $bindIndexPlaceholder = "LOWER($bindIndexPlaceholder)"; } - + $q = $this->query->expr()->$operator($fieldName, $bindIndexPlaceholder); if ($filter->getOperator() == Column::OPERATOR_NLIKE || $filter->getOperator() == Column::OPERATOR_NSLIKE) { From 69b8ce591c657035b158928253643d2844150ef6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Behram=20=C3=87ELEN?= Date: Sat, 12 Nov 2016 20:40:50 +0200 Subject: [PATCH 2/4] relational object translations filter support, translation_agg dql function related --- Grid/Source/Entity.php | 38 +++++++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/Grid/Source/Entity.php b/Grid/Source/Entity.php index aa13f038..b6629a48 100644 --- a/Grid/Source/Entity.php +++ b/Grid/Source/Entity.php @@ -145,6 +145,41 @@ public function initialise($container) $this->groupBy = $this->metadata->getGroupBy(); } + /** + * @param \APY\DataGridBundle\Grid\Column\Column $column + * @return string + */ + protected function getTranslationFieldNameWithParents($column) + { + $name = $column->getField(); + + if ($column->getIsManualField()) { + return $column->getField(); + } + + if (strpos($name, '.') !== false) { + $previousParent = ''; + + $elements = explode('.', $name); + while ($element = array_shift($elements)) { + if (count($elements) > 0) { + $previousParent .= '_' . $element; + } + } + } elseif (strpos($name, ':') !== false) { + $previousParent = $this->getTableAlias(); + } else { + return $this->getTableAlias().'.'.$name; + } + + $matches = array(); + if ($column->hasDQLFunction($matches)) { + return $previousParent.'.'.$matches['field']; + } + + return $column->getField(); + } + /** * @param \APY\DataGridBundle\Grid\Column\Column $column * @return string @@ -384,7 +419,8 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr $bindIndexPlaceholder = "?$bindIndex"; if( in_array($filter->getOperator(), array(Column::OPERATOR_LIKE,Column::OPERATOR_RLIKE,Column::OPERATOR_LLIKE,Column::OPERATOR_NLIKE,))){ if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ - $fieldName = "LOWER(_translations.".$dqlMatches['field'].")"; + $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); + $fieldName = "LOWER(".$translationFieldName.")"; }else{ $fieldName = "LOWER($fieldName)"; } From 64f8505786ba0fd3e1582214f47b79319c6dc432 Mon Sep 17 00:00:00 2001 From: Ahmet Yazbahar Date: Thu, 15 Dec 2016 20:55:39 +0300 Subject: [PATCH 3/4] relational object filter, journal_role_agg dql function related --- Grid/Source/Entity.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Grid/Source/Entity.php b/Grid/Source/Entity.php index b6629a48..f6cf1f57 100644 --- a/Grid/Source/Entity.php +++ b/Grid/Source/Entity.php @@ -421,6 +421,9 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); $fieldName = "LOWER(".$translationFieldName.")"; + }elseif(isset($dqlMatches['function']) && $dqlMatches['function'] == 'journal_role_agg'){ + $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); + $fieldName = "LOWER(".$translationFieldName.")"; }else{ $fieldName = "LOWER($fieldName)"; } From aa13a6a468cbe4db14df3941920877d0cad48e21 Mon Sep 17 00:00:00 2001 From: Ahmet Yazbahar Date: Thu, 15 Dec 2016 21:35:16 +0300 Subject: [PATCH 4/4] journal_role_agg term to role_agg --- Grid/Source/Entity.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Grid/Source/Entity.php b/Grid/Source/Entity.php index f6cf1f57..d4fbedc0 100644 --- a/Grid/Source/Entity.php +++ b/Grid/Source/Entity.php @@ -421,7 +421,7 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr if(isset($dqlMatches['function']) && $dqlMatches['function'] == 'translation_agg'){ $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); $fieldName = "LOWER(".$translationFieldName.")"; - }elseif(isset($dqlMatches['function']) && $dqlMatches['function'] == 'journal_role_agg'){ + }elseif(isset($dqlMatches['function']) && $dqlMatches['function'] == 'role_agg'){ $translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter); $fieldName = "LOWER(".$translationFieldName.")"; }else{