. */ /** * GroupByClause = "GROUP" "BY" GroupByItem {"," GroupByItem} * * @package Doctrine * @subpackage Query * @author Guilherme Blanco * @author Janne Vanhala * @license http://www.opensource.org/licenses/lgpl-license.php LGPL * @link http://www.phpdoctrine.org * @since 2.0 * @version $Revision$ */ class Doctrine_Query_Production_GroupByClause extends Doctrine_Query_Production { protected $_groupByItems = array(); public function syntax($paramHolder) { $this->_parser->match(Doctrine_Query_Token::T_GROUP); $this->_parser->match(Doctrine_Query_Token::T_BY); $this->_groupByItems[] = $this->AST('GroupByItem', $paramHolder); while ($this->_isNextToken(',')) { $this->_parser->match(','); $this->_groupByItems[] = $this->AST('GroupByItem', $paramHolder); } } public function buildSql() { return 'GROUP BY ' . implode(', ', $this->_mapGroupByItems()); } protected function _mapGroupByItems() { return array_map(array(&$this, '_mapGroupByItem'), $this->_groupByItems); } protected function _mapGroupByItem($value) { return $value->buildSql(); } /** * Visitor support * * @param object $visitor */ public function accept($visitor) { foreach ($this->_groupByItems as $item) { $item->accept($visitor); } $visitor->visitGroupByClause($this); } /* Getters */ public function getGroupByItems() { return $this->_groupByItems; } }