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

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