Skip to content

Commit

Permalink
relational object translations filter support, translation_agg dql fu…
Browse files Browse the repository at this point in the history
…nction related
  • Loading branch information
behram authored Nov 12, 2016
1 parent 219bd7b commit 69b8ce5
Showing 1 changed file with 37 additions and 1 deletion.
38 changes: 37 additions & 1 deletion Grid/Source/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)";
}
Expand Down

0 comments on commit 69b8ce5

Please sign in to comment.