Exemplo n.º 1
0
 /**
  * Test campaign zone statistics.
  *
  */
 function testGetCampaignZoneStatistics()
 {
     $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);
     $doAgency = OA_Dal::factoryDO('agency');
     $doPublisher = OA_Dal::factoryDO('affiliates');
     $doZone1 = OA_Dal::factoryDO('zones');
     $doZone1->zonename = 'Test zone name 1';
     $doPublisher->name = "Test publisher name";
     $this->generateZoneWithParents($doAgency, $doPublisher, $doZone1);
     $doZone2 = OA_Dal::factoryDO('zones');
     $this->generateZoneForPublisher($doPublisher, $doZone2);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 11;
     $doDataSummaryAdHourly->requests = 22;
     $doDataSummaryAdHourly->total_revenue = 33;
     $doDataSummaryAdHourly->clicks = 44;
     $doDataSummaryAdHourly->conversions = 55;
     $doDataSummaryAdHourly->date_time = '1986-04-08';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner, $doZone1);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 10;
     $doDataSummaryAdHourly->requests = 20;
     $doDataSummaryAdHourly->total_revenue = 30;
     $doDataSummaryAdHourly->clicks = 40;
     $doDataSummaryAdHourly->conversions = 50;
     $doDataSummaryAdHourly->date_time = '2007-09-13';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner, $doZone1);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 10;
     $doDataSummaryAdHourly->requests = 20;
     $doDataSummaryAdHourly->total_revenue = 30;
     $doDataSummaryAdHourly->clicks = 40;
     $doDataSummaryAdHourly->conversions = 50;
     $doDataSummaryAdHourly->date_time = '2007-09-13';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner, $doZone2);
     // 1. Get data existing range
     $rsCampaignStatistics = $this->_dalCampaignStatistics->getCampaignZoneStatistics($doCampaign->campaignid, new Date('1984-01-01'), new Date('2007-09-18'));
     $rsCampaignStatistics->find();
     $this->assertTrue($rsCampaignStatistics->getRowCount() == 2, '2 records should be returned');
     $rsCampaignStatistics->fetch();
     $aRow1 = $rsCampaignStatistics->toArray();
     $rsCampaignStatistics->fetch();
     $aRow2 = $rsCampaignStatistics->toArray();
     $this->ensureRowSequence($aRow1, $aRow2, 'zoneid', $doZone1->zoneid);
     // 2. Check return fields names
     $this->assertFieldExists($aRow1, 'publisherid');
     $this->assertFieldExists($aRow1, 'publishername');
     $this->assertFieldExists($aRow1, 'zoneid');
     $this->assertFieldExists($aRow1, 'zonename');
     $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', 21);
     $this->assertFieldEqual($aRow1, 'requests', 42);
     $this->assertFieldEqual($aRow1, 'revenue', 63);
     $this->assertFieldEqual($aRow1, 'clicks', 84);
     $this->assertFieldEqual($aRow1, 'conversions', 105);
     $this->assertFieldEqual($aRow1, 'publishername', $doPublisher->name);
     $this->assertFieldEqual($aRow1, 'zonename', $doZone1->zonename);
     $this->assertFieldEqual($aRow2, 'impressions', 10);
     $this->assertFieldEqual($aRow2, 'requests', 20);
     $this->assertFieldEqual($aRow2, 'revenue', 30);
     $this->assertFieldEqual($aRow2, 'clicks', 40);
     $this->assertFieldEqual($aRow2, 'conversions', 50);
     // 4. Get data in not existing range
     $rsCampaignStatistics = $this->_dalCampaignStatistics->getCampaignZoneStatistics($doCampaign->campaignid, new Date('2007-09-21'), new Date('2007-09-21'));
     $rsCampaignStatistics->find();
     $this->assertTrue($rsCampaignStatistics->getRowCount() == 0, 'Recordset should be empty');
     // 5. Get 1 row
     $rsCampaignStatistics = $this->_dalCampaignStatistics->getCampaignZoneStatistics($doCampaign->campaignid, new Date('1986-01-01'), new Date('1986-04-09'));
     $rsCampaignStatistics->find();
     $this->assertTrue($rsCampaignStatistics->getRowCount() == 1, '1 records should be returned');
 }
Exemplo n.º 2
0
 /**
  * This method returns zone 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>publisherID integer</b> The ID of the publisher
  *   <li><b>publisherName string (255)</b> The name of the publisher
  *   <li><b>zoneID integer</b> The ID of the zone
  *   <li><b>zoneName string (255)</b> The name of the zone
  *   <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 getCampaignZoneStatistics($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->getCampaignZoneStatistics($campaignId, $oStartDate, $oEndDate, $localTZ);
         return true;
     } else {
         return false;
     }
 }