Groupby.php 884 Bytes
Newer Older
lsmith's avatar
lsmith committed
1
<?php
doctrine's avatar
doctrine committed
2 3
require_once("Part.php");

lsmith's avatar
lsmith committed
4 5
class Doctrine_Query_Groupby extends Doctrine_Query_Part
{
doctrine's avatar
doctrine committed
6 7 8 9 10 11 12
    /**
     * DQL GROUP BY PARSER
     * parses the group by part of the query string

     * @param string $str
     * @return void
     */
lsmith's avatar
lsmith committed
13 14
    final public function parse($str)
    {
doctrine's avatar
doctrine committed
15
        $r = array();
lsmith's avatar
lsmith committed
16
        foreach (explode(",", $str) as $reference) {
doctrine's avatar
doctrine committed
17 18 19 20 21 22 23 24 25 26 27
            $reference = trim($reference);
            $e     = explode(".",$reference);
            $field = array_pop($e);
            $ref   = implode(".", $e);
            $table = $this->query->load($ref);
            $component = $table->getComponentName();
            $r[] = $this->query->getTableAlias($ref).".".$field;
        }
        return implode(", ", $r);
    }

lsmith's avatar
lsmith committed
28 29
    public function __toString()
    {
doctrine's avatar
doctrine committed
30 31 32
        return ( ! empty($this->parts))?implode(", ", $this->parts):'';
    }
}