/** * @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; }
/** * @param string $section * @param \APY\DataGridBundle\Grid\Grid $grid * @param \APY\DataGridBundle\Grid\Column\Column $param * @return string */ public function getGridUrl($section, $grid, $param = null) { $separator = strpos($grid->getRouteUrl(), '?') ? '&' : '?'; switch ($section) { case 'order': if ($param->isSorted()) { return $grid->getRouteUrl() . $separator . $grid->getHash() . '[' . Grid::REQUEST_QUERY_ORDER . ']=' . $param->getId() . '|' . ($param->getOrder() == 'asc' ? 'desc' : 'asc'); } else { return $grid->getRouteUrl() . $separator . $grid->getHash() . '[' . Grid::REQUEST_QUERY_ORDER . ']=' . $param->getId() . '|asc'; } case 'page': return $grid->getRouteUrl() . $separator . $grid->getHash() . '[' . Grid::REQUEST_QUERY_PAGE . ']=' . $param; case 'limit': return $grid->getRouteUrl() . $separator . $grid->getHash() . '[' . Grid::REQUEST_QUERY_LIMIT . ']='; case 'reset': return $grid->getRouteUrl() . $separator . $grid->getHash() . '[' . Grid::REQUEST_QUERY_RESET . ']='; } }
/** * @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; }