private function renameSelectFields(SelectQuery $query, $namesMap = null, $originalSource = null) {
        if($namesMap == null) {
            $namesMap = $this->getColumnNames();
        }
        $selectFields = &$query->getSelectFields();
        //en el caso que no se indique nada en el select, pongo los del mapa
        if (empty($selectFields)) {
            foreach ($namesMap as $aliasName => $columnName) {
                if (is_numeric($aliasName)) {
                    $selectItem = $columnName;
                } else if (empty($columnName) || $aliasName === $columnName) {
                    $selectItem = $aliasName;
                } else {
                    $selectItem = [$columnName, $aliasName];
                }
                $query->select($selectItem);
            }
        } else {
            //primer for para busqueda de * o tabla.* y agregado de campos
            $newSelectFields = [];
            foreach ($selectFields as $selectField) {
                $aliasName = $selectField instanceof stdClass ? trim($selectField->expression) : trim($selectField);
                if ($aliasName == '*') {
                    foreach ($namesMap as $aliasName => $columnName) {
                        if (is_numeric($aliasName)) {
                            $newSelectFields[$columnName] = $columnName;
                        } else {
                            $newSelectFields[$aliasName] = $aliasName;
                        }
                    }
                    continue;

                } else if (!empty($originalSource) && $aliasName == "$originalSource.*") {
                    foreach ($namesMap as $aliasName => $columnName) {
                        if (is_numeric($aliasName)) {
                            $newSelectFields["$originalSource.$columnName"] = "$originalSource.$columnName";
                        } else {
                            $newSelectFields["$originalSource.$aliasName"] = "$originalSource.$aliasName";
                        }
                    }
                    continue;

                } else {
                    $newSelectFields[$aliasName] = $selectField;
                }
            }
            if (!empty($newSelectFields)) {
                $query->selectFields(array_values($newSelectFields));
            }
            //segundo for para reemplazo de nombres
            foreach ($selectFields as &$field) {
                if ($field instanceof stdClass) {
                    $aliasName = $field->alias;
                    $columnName = $this->getFieldNewName($field->expression, $namesMap, $originalSource, $query->getTable());
                } else {
                    $aliasName = $field;
                    $columnName = $this->getFieldNewName($field, $namesMap, $originalSource, $query->getTable());
                }
                if($columnName != null) {
                    if ($columnName == $aliasName) {
                        $field = $columnName;
                    } else {
                        $field = new stdClass();
                        $field->expression = $columnName;
                        $field->alias = $aliasName;
                    }
                }
            }
        }
    }
private function renameSelectFields(SelectQuery $query, $namesMap = null, $originalSource = null) {
        if($namesMap == null) {
            $namesMap = $this->getColumnNames();
        }
        $selectFields = &$query->getSelectFields();
        //en el caso que no se indique nada en el select, pongo los del mapa
        if (empty($selectFields)) {
            foreach ($namesMap as $aliasName => $columnName) {
                if (is_numeric($aliasName)) {
                    $selectItem = $columnName;
                } else if (empty($columnName) || $aliasName === $columnName) {
                    $selectItem = $aliasName;
                } else {
                    $selectItem = [$columnName, $aliasName];
                }
                $query->select($selectItem);
            }
        } else {
            //primer for para busqueda de * o tabla.* y agregado de campos
            $newSelectFields = [];
            foreach ($selectFields as $selectField) {
                $aliasName = $selectField instanceof stdClass ? trim($selectField->expression) : trim($selectField);
                if ($aliasName == '*') {
                    foreach ($namesMap as $aliasName => $columnName) {
                        if (is_numeric($aliasName)) {
                            $newSelectFields[$columnName] = $columnName;
                        } else {
                            $newSelectFields[$aliasName] = $aliasName;
                        }
                    }
                    continue;

                } else if (!empty($originalSource) && $aliasName == "$originalSource.*") {
                    foreach ($namesMap as $aliasName => $columnName) {
                        if (is_numeric($aliasName)) {
                            $newSelectFields["$originalSource.$columnName"] = "$originalSource.$columnName";
                        } else {
                            $newSelectFields["$originalSource.$aliasName"] = "$originalSource.$aliasName";
                        }
                    }
                    continue;

                } else {
                    $newSelectFields[$aliasName] = $selectField;
                }
            }
            if (!empty($newSelectFields)) {
                $query->selectFields(array_values($newSelectFields));
            }
            //segundo for para reemplazo de nombres
            foreach ($selectFields as &$field) {
                if ($field instanceof stdClass) {
                    $aliasName = $field->alias;
                    $columnName = $this->getFieldNewName($field->expression, $namesMap, $originalSource, $query->getTable());
                } else {
                    $aliasName = $field;
                    $columnName = $this->getFieldNewName($field, $namesMap, $originalSource, $query->getTable());
                }
                if($columnName != null) {
                    if ($columnName == $aliasName) {
                        $field = $columnName;
                    } else {
                        $field = new stdClass();
                        $field->expression = $columnName;
                        $field->alias = $aliasName;
                    }
                }
            }
        }
    }
private function renameSelectFields ( SelectQuery $ query , $ namesMap = null , $ originalSource = null ) { if ( $ namesMap == null ) { $ namesMap = $ this -> getColumnNames ( ) ; } $ selectFields = & $ query -> getSelectFields ( ) ; //en el caso que no se indique nada en el select, pongo los del mapa if ( empty ( $ selectFields ) ) { foreach ( $ namesMap as $ aliasName => $ columnName ) { if ( is_numeric ( $ aliasName ) ) { $ selectItem = $ columnName ; } else if ( empty ( $ columnName ) || $ aliasName === $ columnName ) { $ selectItem = $ aliasName ; } else { $ selectItem = [ $ columnName , $ aliasName ] ; } $ query -> select ( $ selectItem ) ; } } else { //primer for para busqueda de * o tabla.* y agregado de campos $ newSelectFields = [ ] ; foreach ( $ selectFields as $ selectField ) { $ aliasName = $ selectField instanceof stdClass ? trim ( $ selectField -> expression ) : trim ( $ selectField ) ; if ( $ aliasName == '*' ) { foreach ( $ namesMap as $ aliasName => $ columnName ) { if ( is_numeric ( $ aliasName ) ) { $ newSelectFields [ $ columnName ] = $ columnName ; } else { $ newSelectFields [ $ aliasName ] = $ aliasName ; } } continue ; } else if ( ! empty ( $ originalSource ) && $ aliasName == "$originalSource.*" ) { foreach ( $ namesMap as $ aliasName => $ columnName ) { if ( is_numeric ( $ aliasName ) ) { $ newSelectFields [ "$originalSource.$columnName" ] = "$originalSource.$columnName" ; } else { $ newSelectFields [ "$originalSource.$aliasName" ] = "$originalSource.$aliasName" ; } } continue ; } else { $ newSelectFields [ $ aliasName ] = $ selectField ; } } if ( ! empty ( $ newSelectFields ) ) { $ query -> selectFields ( array_values ( $ newSelectFields ) ) ; } //segundo for para reemplazo de nombres foreach ( $ selectFields as & $ field ) { if ( $ field instanceof stdClass ) { $ aliasName = $ field -> alias ; $ columnName = $ this -> getFieldNewName ( $ field -> expression , $ namesMap , $ originalSource , $ query -> getTable ( ) ) ; } else { $ aliasName = $ field ; $ columnName = $ this -> getFieldNewName ( $ field , $ namesMap , $ originalSource , $ query -> getTable ( ) ) ; } if ( $ columnName != null ) { if ( $ columnName == $ aliasName ) { $ field = $ columnName ; } else { $ field = new stdClass ( ) ; $ field -> expression = $ columnName ; $ field -> alias = $ aliasName ; } } } } }
Modifica el select con los alias correspondientes

Nota: si la tabla tiene algunos campos a cambiar y otros no, en el mapa debemos poner todos para el caso de select *.
Es por ello que sumo una validacion para que en el caso que el mapa contenga una entrada donde clave y valor
son iguales no ponga el alias, o bien que tenga solo valor, en ese caso la clave es un autonumerico y por eso
pregunto por is_numeric
@param SelectQuery $query
@param $namesMap
@param mixed $originalSource
Modifica el select con los alias correspondientes