GroupBy DATE(create_date)
Wed, 08/10/2011 - 09:08
I needed QQuery with grouping by month so i made new class and paced it in QQuery.class.php
Can this be added in QCubed code and can it be improved?
Mysql
MySQL
GROUP BY MONTH(record_date)
QQ
QQ::GroupByFunction(QQN::Order()->CreateDate,'Month'), class QQGroupByFunction extends QQClause {
protected $objNode;
protected $strAttributeName;
public function __construct($objNode, $strAttributeName) {
// Check against root and table QQNodes
if ($objNode instanceof QQAssociationNode)
throw new QCallerException('Expand clause parameter cannot be the association table\'s QQNode, itself', 2);
else if (!($objNode instanceof QQNode))
throw new QCallerException('Expand clause parameter must be a QQNode object', 2);
else if (!$objNode->_ParentNode)
throw new QInvalidCastException('Unable to cast "' . $objNode->_Name . '" table to Column-based QQNode', 3);
$this->objNode = $objNode;
$this->strAttributeName = $strAttributeName;
}
public function UpdateQueryBuilder(QQueryBuilder $objBuilder) {
if($this->strAttributeName){
$objBuilder->AddGroupByItem(strtoupper($this->strAttributeName)."(".$this->objNode->GetColumnAlias($objBuilder).")");
}else{
$objBuilder->AddGroupByItem($this->objNodeArray->GetColumnAlias($objBuilder));
}
}
public function __toString() {
return 'QQGroupBy Clause';
}
}and function in QQclass
static public function GroupByFunction($objNode, $strAttributeName) {
return new QQGroupByFunction($objNode, $strAttributeName);
}