Esempio n. 1
0
 /**
  * This method returns campaign statistics for a publisher for a specified period.
  *
  * @access public
  *
  * @param integer $publisherId The ID of the publisher 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>campaignID integer</b> The ID of the campaign
  *   <li><b>campaignName string (255)</b> The name of the campaign
  *   <li><b>advertiserID integer</b> The ID of the advertiser
  *   <li><b>advertiserName string</b> The name of the advertiser
  *   <li><b>requests integer</b> The number of requests for the campaign
  *   <li><b>impressions integer</b> The number of impressions for the campaign
  *   <li><b>clicks integer</b> The number of clicks for the campaign
  *   <li><b>revenue decimal</b> The revenue earned for the campaign
  *   </ul>
  *
  * @return boolean True if the operation was successful and false if not.
  *
  */
 function getPublisherCampaignStatistics($publisherId, $oStartDate, $oEndDate, $localTZ, &$rsStatisticsData)
 {
     if (!$this->checkPermissions($this->aAllowTraffickerAndAbovePerm, 'affiliates', $publisherId)) {
         return false;
     }
     if ($this->_validateForStatistics($publisherId, $oStartDate, $oEndDate)) {
         $publisherDal = new OA_Dal_Statistics_Publisher();
         $rsStatisticsData = $publisherDal->getPublisherCampaignStatistics($publisherId, $oStartDate, $oEndDate, $localTZ);
         return true;
     } else {
         return false;
     }
 }
 /**
  * Test publisher campaign statistics.
  *
  */
 function testGetPublisherCampaignStatistics()
 {
     $doAgency = OA_Dal::factoryDO('agency');
     $doAdvertiser = OA_Dal::factoryDO('clients');
     $doCampaign1 = OA_Dal::factoryDO('campaigns');
     $doBanner1 = OA_Dal::factoryDO('banners');
     $this->generateBannerWithParents($doAgency, $doAdvertiser, $doCampaign1, $doBanner1);
     $doBanner2 = OA_Dal::factoryDO('banners');
     $this->generateBannerForCampaign($doCampaign1, $doBanner2);
     $doCampaign2 = OA_Dal::factoryDO('campaigns');
     $doBanner3 = OA_Dal::factoryDO('banners');
     $this->generateBannerAndCampaignForAdvertiser($doAdvertiser, $doCampaign2, $doBanner3);
     $doAgency = OA_Dal::factoryDO('agency');
     $doPublisher = OA_Dal::factoryDO('affiliates');
     $doZone = OA_Dal::factoryDO('zones');
     $this->generateZoneWithParents($doAgency, $doPublisher, $doZone);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 1;
     $doDataSummaryAdHourly->requests = 2;
     $doDataSummaryAdHourly->total_revenue = 3;
     $doDataSummaryAdHourly->clicks = 4;
     $doDataSummaryAdHourly->conversions = 5;
     $doDataSummaryAdHourly->date_time = '2007-08-08';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner1, $doZone);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 0;
     $doDataSummaryAdHourly->requests = 1;
     $doDataSummaryAdHourly->total_revenue = 2;
     $doDataSummaryAdHourly->clicks = 3;
     $doDataSummaryAdHourly->conversions = 4;
     $doDataSummaryAdHourly->date_time = '2007-09-08';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner2, $doZone);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 10;
     $doDataSummaryAdHourly->requests = 10;
     $doDataSummaryAdHourly->total_revenue = 10;
     $doDataSummaryAdHourly->clicks = 10;
     $doDataSummaryAdHourly->conversions = 10;
     $doDataSummaryAdHourly->date_time = '2007-09-09';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner3, $doZone);
     // 1. Get data existing range
     $rsPublisherStatistics = $this->_dalPublisherStatistics->getPublisherCampaignStatistics($doPublisher->affiliateid, new Date('2007-06-06'), new Date('2007-09-18'));
     $rsPublisherStatistics->find();
     $this->assertTrue($rsPublisherStatistics->getRowCount() == 2, '2 records should be returned');
     $rsPublisherStatistics->fetch();
     $aRow1 = $rsPublisherStatistics->toArray();
     $rsPublisherStatistics->fetch();
     $aRow2 = $rsPublisherStatistics->toArray();
     $this->ensureRowSequence($aRow1, $aRow2, 'campaignid', $doCampaign1->campaignid);
     // 2. Check return fields names
     $this->assertFieldExists($aRow1, 'advertiserid');
     $this->assertFieldExists($aRow1, 'advertisername');
     $this->assertFieldExists($aRow1, 'campaignid');
     $this->assertFieldExists($aRow1, 'campaignname');
     $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', 1);
     $this->assertFieldEqual($aRow1, 'requests', 3);
     $this->assertFieldEqual($aRow2, 'revenue', 10);
     $this->assertFieldEqual($aRow2, 'clicks', 10);
     $this->assertFieldEqual($aRow2, 'conversions', 10);
     // 4. Get data in not existing range
     $rsPublisherStatistics = $this->_dalPublisherStatistics->getPublisherCampaignStatistics($doPublisher->affiliateid, new Date('2007-09-21'), new Date('2007-09-21'));
     $rsPublisherStatistics->find();
     $this->assertTrue($rsPublisherStatistics->getRowCount() == 0, 'Recordset should be empty');
     // 5. Get data from only 1 row
     $rsPublisherStatistics = $this->_dalPublisherStatistics->getPublisherCampaignStatistics($doPublisher->affiliateid, new Date('2007-06-06'), new Date('2007-09-08'));
     $rsPublisherStatistics->find();
     $this->assertTrue($rsPublisherStatistics->getRowCount() == 1, 'Some records should be returned');
 }