<?php
class SQLGroupByHours
{
  static public function group(CDbCriteria $dbCriteria, $timeFieldName, $quantum)
  {
    $groupBy  =  "YEAR(".$timeFieldName.")";
    $groupBy .=  ",";
    $groupBy .=  "MONTH(".$timeFieldName.")";
    $groupBy .=  ",";
    $groupBy .=  "DAY(".$timeFieldName.")";
    $groupBy .=  ",";
    $groupBy .=  "(HOUR(".$timeFieldName.") DIV ".$quantum.")";

    $dbCriteria->mergeWith(array('group' => $groupBy));
    return $dbCriteria;
  }
}
