1
0
mirror of synced 2024-12-15 15:46:02 +03:00
doctrine2/Doctrine/Query/Orderby.php

42 lines
1.2 KiB
PHP
Raw Normal View History

2006-06-30 03:04:39 +04:00
<?php
require_once("Part.php");
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
*/
final 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 = $tname.".".$field;
if(isset($e[1]))
$r .= " ".$e[1];
}
$ret[] = $r;
}
return implode(", ", $ret);
}
public function __toString() {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}
?>