Пример #1
0
 /**
  * build the query for the avg caclculation
  * @param model $listModel
  * @param string $label the label to apply to each avg
  * @return string sql statement
  */
 protected function getAvgQuery(&$tableModel, $label = "'calc'")
 {
     $fields = $tableModel->getDBFields($this->getTableName(), 'Field');
     if ($fields[$this->getElement()->name]->Type == 'time') {
         $name = $this->getFullName(false, false, false);
         $table =& $tableModel->getTable();
         $joinSQL = $tableModel->_buildQueryJoin();
         $whereSQL = $tableModel->_buildQueryWhere();
         return "SELECT SEC_TO_TIME(AVG(TIME_TO_SEC({$name}))) AS value, {$label} AS label FROM `{$table->db_table_name}` {$joinSQL} {$whereSQL}";
     } else {
         return parent::getAvgQuery($tableModel, $label);
     }
 }