dudapiotr / ZfTable

*Not supported*ZfTable 3.1. Awesome ZF2 table / grid (and much much more) generator with huge possibilities of decorating and conditioning. Integrated with DataTables, Doctrine 2, Bootstrap 2.0 and 3.0.
http://dudapiotrek.laohost.net/
MIT License
75 stars 59 forks source link

tableAlias . included even for composed columns #78

Open cbichis opened 9 years ago

cbichis commented 9 years ago

Hi,

The table alias "." is included into order even if the field is a composed one.

sample:

For CONCAT(u.lastName, ' ', u.firstName) staff_name

Order looks like this:

ORDER BY .staff_name

So i created fix for ZfTable\Source\DoctrineQueryBuilder:

    protected function order()
    {
        $column = $this->getParamAdapter()->getColumn();
        $order = $this->getParamAdapter()->getOrder();

        if (!$column) {
            return;
        }

        $header = $this->getTable()->getHeader($column);
        $tableAlias = ($header) ? $header->getTableAlias() : 'q';

        if (false === strpos($tableAlias, '.')) {
            if(empty($tableAlias)){
                $tableAlias = $column;
            } else {
                $tableAlias = $tableAlias.'.'.$column;
            }
        }

        $this->query->orderBy($tableAlias, $order);
    }
stijnhau commented 8 years ago

Can you fork and create a PR so it's eadier to review the changes?

cbichis commented 8 years ago

See now.

Can you fork and create a PR so it's eadier to review the changes?

— Reply to this email directly or view it on GitHub https://github.com/dudapiotr/ZfTable/issues/78#issuecomment-158667629.

Cristian Bichis IMAGIS Strada Faiantei nr 13 550098 Sibiu, Romania Phone: 004.0727.757533 Email: office@imagis.ro Web: www.imagis.ro