1
0
mirror of synced 2024-12-14 07:06:04 +03:00
doctrine2/Doctrine/Query/Orderby.php

47 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);
2006-09-18 21:32:12 +04:00
2006-06-30 03:04:39 +04:00
$this->query->load($reference, false);
$alias = $this->query->getTableAlias($reference);
2006-09-18 21:32:12 +04:00
2006-06-30 03:04:39 +04:00
$tname = $this->query->getTable($alias)->getTableName();
2006-09-18 21:32:12 +04:00
$r = $alias.".".$field;
if(isset($e[1]))
2006-06-30 03:04:39 +04:00
$r .= " ".$e[1];
}
$ret[] = $r;
}
2006-09-18 21:32:12 +04:00
2006-06-30 03:04:39 +04:00
return implode(", ", $ret);
}
public function __toString() {
return ( ! empty($this->parts))?implode(", ", $this->parts):'';
}
}