/** * Test agency advertiser statistics. * */ function testGetAgencyAdvertiserStatistics() { $doAgency = OA_Dal::factoryDO('agency'); $doAdvertiser = OA_Dal::factoryDO('clients'); $doCampaign = OA_Dal::factoryDO('campaigns'); $doBanner1 = OA_Dal::factoryDO('banners'); $this->generateBannerWithParents($doAgency, $doAdvertiser, $doCampaign, $doBanner1); $doBanner2 = OA_Dal::factoryDO('banners'); $this->generateBannerForCampaign($doCampaign, $doBanner2); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->requests = 20; $doDataSummaryAdHourly->total_revenue = 4; $doDataSummaryAdHourly->date_time = '2007-08-20'; $this->generateDataSummaryAdHourlyForBanner($doDataSummaryAdHourly, $doBanner1); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->requests = 1; $doDataSummaryAdHourly->total_revenue = 6; $doDataSummaryAdHourly->date_time = '2007-08-08'; $this->generateDataSummaryAdHourlyForBanner($doDataSummaryAdHourly, $doBanner2); // 1. Get data existing range $rsAgencyStatistics = $this->_dalAgencyStatistics->getAgencyAdvertiserStatistics($doAgency->agencyid, new Date('2001-12-01'), new Date('2007-09-19')); $rsAgencyStatistics->find(); $this->assertTrue($rsAgencyStatistics->getRowCount() == 1, 'Some records should be returned'); $rsAgencyStatistics->fetch(); $aRow = $rsAgencyStatistics->toArray(); // 2. Check return fields names $this->assertFieldExists($aRow, 'advertiserid'); $this->assertFieldExists($aRow, 'advertisername'); $this->assertFieldExists($aRow, 'requests'); $this->assertFieldExists($aRow, 'impressions'); $this->assertFieldExists($aRow, 'clicks'); $this->assertFieldExists($aRow, 'revenue'); // 3. Check return fields value $this->assertFieldEqual($aRow, 'requests', 21); $this->assertFieldEqual($aRow, 'revenue', 10); // 4. Get data in not existing range $rsAgencyStatistics = $this->_dalAgencyStatistics->getAgencyAdvertiserStatistics($doAgency->agencyid, new Date('2001-12-01'), new Date('2006-09-19')); $rsAgencyStatistics->find(); $this->assertTrue($rsAgencyStatistics->getRowCount() == 0, 'Recordset should be empty'); }
/** * This method returns advertiser statistics for an agency for a specified period. * * @access public * * @param integer $agencyId The ID of the agency to view statistics for * @param date $oStartDate The date from which to get statistics (inclusive) * @param date $oEndDate The date to which to get statistics (inclusive) * @param array &$rsStatisticsData The data returned by the function * <ul> * <li><b>advertiserID integer</b> The ID of the advertiser * <li><b>advertiserName string (255)</b> The name of the advertiser * <li><b>requests integer</b> The number of requests for the day * <li><b>impressions integer</b> The number of impressions for the day * <li><b>clicks integer</b> The number of clicks for the day * <li><b>revenue decimal</b> The revenue earned for the day * </ul> * * @return boolean True if the operation was successful and false if not. * */ function getAgencyAdvertiserStatistics($agencyId, $oStartDate, $oEndDate, $localTZ, &$rsStatisticsData) { if (!$this->checkPermissions(array(OA_ACCOUNT_ADMIN, OA_ACCOUNT_MANAGER), 'agency', $agencyId)) { return false; } if ($this->_validateForStatistics($agencyId, $oStartDate, $oEndDate)) { $dalAgency = new OA_Dal_Statistics_Agency(); $rsStatisticsData = $dalAgency->getAgencyAdvertiserStatistics($agencyId, $oStartDate, $oEndDate, $localTZ); return true; } else { return false; } }