function test_getStatsColumns()
 {
     $entities = array('ad', 'advertiser', 'agency', 'placement', 'publisher', 'zone');
     foreach ($entities as $entity) {
         $ret = SqlBuilder::_getStatsColumns($entity);
         $this->assertTrue(is_array($ret));
         $this->assertEqual(count($ret), 5);
         //  each hash should have 5 elements
         $lastElement = array_pop($ret);
         //   last element should be the entity_id
         $this->assertEqual($entity . '_id', $lastElement);
     }
 }
Пример #2
0
 /**
  * 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);
 }
Пример #3
0
 /**
  * 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);
 }