. */ Doctrine::autoload('Doctrine_Query_Part'); /** * Doctrine_Query_Orderby * * @package Doctrine * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @category Object Relational Mapping * @link www.phpdoctrine.com * @since 1.0 * @version $Revision$ * @author Konsta Vesterinen */ class Doctrine_Query_Orderby extends Doctrine_Query_Part { /** * DQL ORDER BY PARSER * parses the order by part of the query string * * @param string $str * @return void */ public function parse($str) { $ret = array(); foreach (explode(',', trim($str)) as $r) { $r = trim($r); $e = explode(' ', $r); $a = explode('.', $e[0]); if (count($a) > 1) { $field = array_pop($a); $reference = implode('.', $a); $name = end($a); $this->query->load($reference, false); $alias = $this->query->getTableAlias($reference); $tname = $this->query->getTable($alias)->getTableName(); $r = $alias . '.' . $field; } else { $field = $this->query->getAggregateAlias($e[0]); $r = $field; } if (isset($e[1])) { $r .= ' '.$e[1]; } $ret[] = $r; } return implode(', ', $ret); } public function __toString() { return ( ! empty($this->parts))?implode(', ', $this->parts):''; } }