/** * Test campaign daily statistics. * */ function testGetCampaignDailyStatistics() { $doAgency = OA_Dal::factoryDO('agency'); $doAdvertiser = OA_Dal::factoryDO('clients'); $doCampaign = OA_Dal::factoryDO('campaigns'); $doBanner = OA_Dal::factoryDO('banners'); $this->generateBannerWithParents($doAgency, $doAdvertiser, $doCampaign, $doBanner); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->impressions = 1; $doDataSummaryAdHourly->requests = 2; $doDataSummaryAdHourly->total_revenue = 3; $doDataSummaryAdHourly->clicks = 4; $doDataSummaryAdHourly->date_time = '2007-08-08'; $this->generateDataSummaryAdHourlyForBanner($doDataSummaryAdHourly, $doBanner); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->impressions = 11; $doDataSummaryAdHourly->requests = 12; $doDataSummaryAdHourly->total_revenue = 13; $doDataSummaryAdHourly->clicks = 14; $doDataSummaryAdHourly->date_time = '2007-08-08'; $this->generateDataSummaryAdHourlyForBanner($doDataSummaryAdHourly, $doBanner); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->impressions = 1; $doDataSummaryAdHourly->requests = 0; $doDataSummaryAdHourly->total_revenue = 0; $doDataSummaryAdHourly->clicks = 0; $doDataSummaryAdHourly->date_time = '2007-08-12'; $dayForRecord2 = $doDataSummaryAdHourly->date_time; $this->generateDataSummaryAdHourlyForBanner($doDataSummaryAdHourly, $doBanner); // 1. Get data existing range $aData = $this->_dalCampaignStatistics->getCampaignDailyStatistics($doCampaign->campaignid, new Date('2007-08-01'), new Date('2007-08-20')); $this->assertEqual(count($aData), 2, '2 records should be returned'); $aRow1 = current($aData); $aRow2 = next($aData); $this->ensureRowSequence($aRow2, $aRow1, 'day', $dayForRecord2); // 2. Check return fields names $this->assertFieldExists($aRow1, 'day'); $this->assertFieldExists($aRow1, 'requests'); $this->assertFieldExists($aRow1, 'impressions'); $this->assertFieldExists($aRow1, 'clicks'); $this->assertFieldExists($aRow1, 'revenue'); // 3. Check return fields value $this->assertFieldEqual($aRow1, 'impressions', 12); $this->assertFieldEqual($aRow1, 'requests', 14); $this->assertFieldEqual($aRow1, 'revenue', 16); $this->assertFieldEqual($aRow1, 'clicks', 18); $this->assertFieldEqual($aRow2, 'requests', 0); $this->assertFieldEqual($aRow2, 'day', $dayForRecord2); // 4. Get data in not existing range $aData = $this->_dalCampaignStatistics->getCampaignDailyStatistics($doCampaign->campaignid, new Date('2007-01-01'), new Date('2007-01-20')); $this->assertEqual(count($aData), 0, 'Recordset should be empty'); }
/** * This method returns daily statistics for a campaign for a specified period. * * @access public * * @param integer $campaignId The ID of the campaign 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 bool $localTZ Should stats be using the manager TZ or UTC? * @param array &$rsStatisticsData The data returned by the function * <ul> * <li><b>day date</b> The day * <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 getCampaignDailyStatistics($campaignId, $oStartDate, $oEndDate, $localTZ, &$rsStatisticsData) { if (!$this->checkStatisticsPermissions($campaignId)) { return false; } if ($this->_validateForStatistics($campaignId, $oStartDate, $oEndDate)) { $dalCampaign = new OA_Dal_Statistics_Campaign(); $rsStatisticsData = $dalCampaign->getCampaignDailyStatistics($campaignId, $oStartDate, $oEndDate, $localTZ); return true; } else { return false; } }