Skip to content

Commit

Permalink
Merge pull request #892 from bulutyazilim/master
Browse files Browse the repository at this point in the history
translation aggregation filter type support on entity source
  • Loading branch information
Hüseyin Mert authored Dec 16, 2016
2 parents 4605318 + 55abba4 commit 5a37f78
Showing 1 changed file with 51 additions and 3 deletions.
54 changes: 51 additions & 3 deletions Grid/Source/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,41 @@ public function initialise($container)
*
* @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
*/
protected function getFieldName($column, $withAlias = false)
{
$name = $column->getField();
Expand Down Expand Up @@ -373,7 +408,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);

Expand All @@ -384,8 +423,17 @@ public function execute($columns, $page = 0, $limit = 0, $maxResults = null, $gr

$fieldName = $this->getFieldName($columnForFilter, false);
$bindIndexPlaceholder = "?$bindIndex";
if (in_array($filter->getOperator(), [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'){
$translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter);
$fieldName = "LOWER(".$translationFieldName.")";
}elseif(isset($dqlMatches['function']) && $dqlMatches['function'] == 'role_agg'){
$translationFieldName = $this->getTranslationFieldNameWithParents($columnForFilter);
$fieldName = "LOWER(".$translationFieldName.")";
}else{
$fieldName = "LOWER($fieldName)";
}
$bindIndexPlaceholder = "LOWER($bindIndexPlaceholder)";
}

Expand Down

0 comments on commit 5a37f78

Please sign in to comment.