/**
  * Returns an array of entity arrays, where the keys are the entity IDs.
  *
  * @param string  $entity The name of the entities to get (e.g. "agency").
  * @param array   $aParams Map column => value.
  * @param boolean $allFields Return *all* fields the entity has, or just the default fields?
  * @param string  $key The primary key field name.
  * @return array  An array of entity records.
  */
 function _getEntities($entity, $aParams, $allFields = false, $key = null)
 {
     if (empty($key)) {
         $key = "{$entity}_id";
     }
     $aColumns = SqlBuilder::_getColumns($entity, $aParams, $allFields);
     $aTables = SqlBuilder::_getTables($entity, $aParams);
     $aLimitations = array_merge(SqlBuilder::_getLimitations($entity, $aParams), SqlBuilder::_getTableLimitations($aTables, $aParams));
     $aGroupColumns = SqlBuilder::_getGroupColumns($entity, $aParams);
     $aLeftJoinedTables = SqlBuilder::_getLeftJoinedTables($entity, $aParams);
     return SqlBuilder::_select($aColumns, $aTables, $aLimitations, $aGroupColumns, $key, $aLeftJoinedTables);
 }