/**
  * Returns an array of constraints given an entity with params.
  *
  * @param string $entity
  * @param array $aParams
  * @return array
  */
 function _getStatsLimitations($entity, $aParams)
 {
     $aLimitations = array();
     if (!empty($aParams['agency_id'])) {
         switch ($entity) {
             case 'advertiser':
             case 'placement':
             case 'ad':
                 $aLimitations[] = "a.agencyid={$aParams['agency_id']}";
                 break;
             case 'publisher':
             case 'zone':
                 $aLimitations[] = "p.agencyid={$aParams['agency_id']}";
                 break;
             default:
                 $aLimitations[] = "p.agencyid={$aParams['agency_id']}";
                 $aLimitations[] = "a.agencyid={$aParams['agency_id']}";
         }
     }
     if (!empty($aParams['publisher_id'])) {
         SqlBuilder::_addLimitation($aLimitations, 'publisher_id', 'z.affiliateid', $aParams['publisher_id']);
     }
     if (!empty($aParams['advertiser_id'])) {
         SqlBuilder::_addLimitation($aLimitations, 'advertiser_id', 'm.clientid', $aParams['advertiser_id']);
     }
     if (!empty($aParams['zone_id'])) {
         SqlBuilder::_addLimitation($aLimitations, 'zone_id', 's.zone_id', $aParams['zone_id']);
     }
     if (!empty($aParams['placement_id'])) {
         SqlBuilder::_addLimitation($aLimitations, 'placement_id', 'd.campaignid', $aParams['placement_id']);
     }
     if (!empty($aParams['ad_id'])) {
         SqlBuilder::_addLimitation($aLimitations, 'ad_id', 's.ad_id', $aParams['ad_id']);
     }
     if (!empty($aParams['day_begin'])) {
         $aLimitations[] = "s.date_time>='{$aParams['day_begin']}'";
     }
     if (!empty($aParams['day_end'])) {
         $aLimitations[] = "s.date_time<='{$aParams['day_end']}'";
     }
     return $aLimitations;
 }