예제 #1
0
 /**
  * @param \APY\DataGridBundle\Grid\Column\Column $column
  * @return string
  */
 protected function getFieldName($column, $withAlias = false)
 {
     $name = $column->getField();
     /* $isAssocciation = $column->getParam('isAssocciation');
        if($name=='product'){
        var_dump($isAssocciation);die();
        } */
     if (strpos($name, '.') !== false) {
         $previousParent = '';
         $elements = explode('.', $name);
         while ($element = array_shift($elements)) {
             if (count($elements) > 0) {
                 $parent = $previousParent == '' ? $this->getTableAlias() : $previousParent;
                 $previousParent .= '_' . $element;
                 $joinType = $column->getJoinType();
                 $this->joins[$previousParent] = array('field' => $parent . '.' . $element, 'type' => $joinType);
             } else {
                 $name = $previousParent . '.' . $element;
             }
         }
         $alias = str_replace('.', '::', $column->getId());
     } elseif (strpos($name, ':') !== false) {
         $previousParent = $this->getTableAlias();
         $alias = $name;
     } else {
         return $this->getTableAlias() . '.' . $name;
     }
     // Aggregate dql functions
     $matches = array();
     if ($column->hasDQLFunction($matches)) {
         if (strtolower($matches['parameters']) == 'distinct') {
             $functionWithParameters = $matches['function'] . '(DISTINCT ' . $previousParent . '.' . $matches['field'] . ')';
         } else {
             $parameters = '';
             if ($matches['parameters'] !== '') {
                 $parameters = ', ' . (is_numeric($matches['parameters']) ? $matches['parameters'] : "'" . $matches['parameters'] . "'");
             }
             $functionWithParameters = $matches['function'] . '(' . $previousParent . '.' . $matches['field'] . $parameters . ')';
         }
         if ($withAlias) {
             // Group by the primary field of the previous entity
             $this->query->addGroupBy($previousParent);
             $this->querySelectfromSource->addGroupBy($previousParent);
             return "{$functionWithParameters} as {$alias}";
         }
         return $alias;
     }
     if ($withAlias) {
         return "{$name} as {$alias}";
     }
     return $name;
 }
예제 #2
0
 /**
  * @param \APY\DataGridBundle\Grid\Column\Column $column
  * @return string
  */
 protected function getFieldName($column, $withAlias = false)
 {
     $name = $column->getField();
     if ($column instanceof DQLColumn) {
         if (!$withAlias) {
             return $name;
         }
         return $column->getDql() . ' as ' . $name;
     } else {
         if (strpos($name, '.') !== false) {
             $previousParent = '';
             $elements = explode('.', $name);
             while ($element = array_shift($elements)) {
                 if (count($elements) > 0) {
                     $parent = $previousParent == '' ? self::TABLE_ALIAS : $previousParent;
                     $previousParent .= '_' . $element;
                     $this->joins[$previousParent] = array('field' => $parent . '.' . $element, 'type' => $column->getJoinType());
                 } else {
                     $name = $previousParent . '.' . $element;
                 }
             }
             $alias = str_replace('.', '::', $column->getId());
         } elseif (strpos($name, ':') !== false) {
             $previousParent = self::TABLE_ALIAS;
             $alias = $name;
         } else {
             return self::TABLE_ALIAS . '.' . $name;
         }
     }
     // Aggregate dql functions
     $matches = array();
     if ($column->hasDQLFunction($matches)) {
         if (strtolower($matches['parameters']) == 'distinct') {
             $functionWithParameters = $matches['function'] . '(DISTINCT ' . $previousParent . '.' . $matches['field'] . ')';
         } else {
             $parameters = '';
             if ($matches['parameters'] !== '') {
                 $parameters = ', ' . (is_numeric($matches['parameters']) ? $matches['parameters'] : "'" . $matches['parameters'] . "'");
             }
             $functionWithParameters = $matches['function'] . '(' . $previousParent . '.' . $matches['field'] . $parameters . ')';
         }
         if ($withAlias) {
             // Group by the primary field of the previous entity
             $this->query->addGroupBy($previousParent);
             $this->querySelectfromSource->addGroupBy($previousParent);
             return "{$functionWithParameters} as {$alias}";
         }
         return $alias;
     }
     if ($withAlias) {
         return "{$name} as {$alias}";
     }
     return $name;
 }