/** * Get stats by entity. * * @param string $entity * @param array $aParams * @param boolean $allFields * @param string $key The primary key field name * @return array An array of entity records */ function _getEntitiesStats($entity, $aParams, $allFields = false, $key = null) { if (empty($key)) { $key = "{$entity}_id"; } $aColumns = SqlBuilder::_getStatsColumns($entity); $aTables = SqlBuilder::_getTables($entity, $aParams, true); $aLimitations = array_merge(SqlBuilder::_getStatsLimitations($entity, $aParams), SqlBuilder::_getTableLimitations($aTables, $aParams)); // An ugly hack to get the alias used for the entity table so // the query works with Postgres. end($aColumns); $groupByColumn = key($aColumns); reset($aColumns); $aGroups = array($groupByColumn); return SqlBuilder::_select($aColumns, $aTables, $aLimitations, $aGroups, $key); }
/** * Get stats by entity. * * @param string $entity * @param array $aParams * @param boolean $allFields * @param string $key The primary key field name * @return array An array of entity records */ function _getEntitiesStats($entity, $aParams, $allFields = false, $key = null) { if (empty($key)) { $key = "{$entity}_id"; } $aColumns = SqlBuilder::_getStatsColumns($entity); $aTables = SqlBuilder::_getTables($entity, $aParams, true); $aLimitations = array_merge(SqlBuilder::_getStatsLimitations($entity, $aParams), SqlBuilder::_getTableLimitations($aTables, $aParams)); $aGroupBy = array($key); return SqlBuilder::_select($aColumns, $aTables, $aLimitations, $aGroupBy, $key); }