Ejemplo n.º 1
0
 /**
  * Test agency zone statistics.
  *
  */
 function testGetAgencyZoneStatistics()
 {
     $doAgency = OA_Dal::factoryDO('agency');
     $doPublisher = OA_Dal::factoryDO('affiliates');
     $doZone1 = OA_Dal::factoryDO('zones');
     $doPublisher->name = 'test publisher name';
     $doZone1->zonename = 'test zone 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 = 0;
     $doDataSummaryAdHourly->requests = 0;
     $doDataSummaryAdHourly->total_revenue = 0;
     $doDataSummaryAdHourly->clicks = 2;
     $doDataSummaryAdHourly->date_time = '2007-01-01';
     $this->generateDataSummaryAdHourlyForZone($doDataSummaryAdHourly, $doZone1);
     $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-02-01';
     $this->generateDataSummaryAdHourlyForZone($doDataSummaryAdHourly, $doZone2);
     $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-03-01';
     $this->generateDataSummaryAdHourlyForZone($doDataSummaryAdHourly, $doZone2);
     // 1. Get data existing range
     $rsAgencyStatistics = $this->_dalAgencyStatistics->getAgencyZoneStatistics($doAgency->agencyid, new Date('2007-01-01'), new Date('2007-03-01'));
     $rsAgencyStatistics->find();
     $this->assertTrue($rsAgencyStatistics->getRowCount() == 2, '2 records should be returned');
     $rsAgencyStatistics->fetch();
     $aRow1 = $rsAgencyStatistics->toArray();
     $rsAgencyStatistics->fetch();
     $aRow2 = $rsAgencyStatistics->toArray();
     $this->ensureRowSequence($aRow1, $aRow2, 'zoneid', $doZone1->zoneid);
     // 2. Check return fields names
     $this->assertFieldExists($aRow2, 'publisherid');
     $this->assertFieldExists($aRow2, 'publishername');
     $this->assertFieldExists($aRow2, 'zoneid');
     $this->assertFieldExists($aRow2, 'zonename');
     $this->assertFieldExists($aRow2, 'requests');
     $this->assertFieldExists($aRow2, 'impressions');
     $this->assertFieldExists($aRow2, 'clicks');
     $this->assertFieldExists($aRow2, 'revenue');
     // 3. Check return fields value
     $this->assertFieldEqual($aRow1, 'publisherid', $doPublisher->affiliateid);
     $this->assertFieldEqual($aRow1, 'publishername', $doPublisher->name);
     $this->assertFieldEqual($aRow1, 'zoneid', $doZone1->zoneid);
     $this->assertFieldEqual($aRow1, 'zonename', $doZone1->zonename);
     $this->assertFieldEqual($aRow1, 'impressions', 0);
     $this->assertFieldEqual($aRow1, 'requests', 0);
     $this->assertFieldEqual($aRow1, 'revenue', 0);
     $this->assertFieldEqual($aRow1, 'clicks', 2);
     $this->assertFieldEqual($aRow2, 'impressions', 2);
     $this->assertFieldEqual($aRow2, 'requests', 4);
     $this->assertFieldEqual($aRow2, 'revenue', 6);
     $this->assertFieldEqual($aRow2, 'clicks', 8);
     // 4. Get data in not existing range
     $rsAgencyStatistics = $this->_dalAgencyStatistics->getAgencyZoneStatistics($doAgency->agencyid, new Date('2007-05-01'), new Date('2007-05-02'));
     $rsAgencyStatistics->find();
     $this->assertTrue($rsAgencyStatistics->getRowCount() == 0, 'Recordset should be empty');
     // 5. Get 1 rows
     $rsAgencyStatistics = $this->_dalAgencyStatistics->getAgencyZoneStatistics($doAgency->agencyid, new Date('2007-01-02'), new Date('2007-03-01'));
     $rsAgencyStatistics->find();
     $this->assertTrue($rsAgencyStatistics->getRowCount() == 1, '1 records should be returned');
 }
Ejemplo n.º 2
0
 /**
  * Test banner zone statistics.
  *
  */
 function testGetBannerZoneStatistics()
 {
     $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');
     $doPublisher->name = 'test publisher name';
     $doZone1 = OA_Dal::factoryDO('zones');
     $doZone1->zonename = 'test zone 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 = 1;
     $doDataSummaryAdHourly->requests = 2;
     $doDataSummaryAdHourly->total_revenue = 3;
     $doDataSummaryAdHourly->clicks = 4;
     $doDataSummaryAdHourly->conversions = 5;
     $doDataSummaryAdHourly->date_time = '1984-03-08';
     $this->generateDataSummaryAdHourlyForBannerAndZone($doDataSummaryAdHourly, $doBanner, $doZone1);
     $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly');
     $doDataSummaryAdHourly->impressions = 11;
     $doDataSummaryAdHourly->requests = 12;
     $doDataSummaryAdHourly->total_revenue = 13;
     $doDataSummaryAdHourly->clicks = 14;
     $doDataSummaryAdHourly->conversions = 15;
     $doDataSummaryAdHourly->date_time = '1984-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, $doZone2);
     // 1. Get data existing range
     $rsBannerStatistics = $this->_dalBannerStatistics->getBannerZoneStatistics($doBanner->bannerid, new Date('1984-01-01'), new Date('2007-09-13'));
     $rsBannerStatistics->find();
     $this->assertTrue($rsBannerStatistics->getRowCount() == 2, '2 records should be returned');
     $rsBannerStatistics->fetch();
     $aRow1 = $rsBannerStatistics->toArray();
     $rsBannerStatistics->fetch();
     $aRow2 = $rsBannerStatistics->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');
     $this->assertFieldExists($aRow1, 'conversions');
     // 3. Check return fields value
     $this->assertFieldEqual($aRow1, 'publishername', $doPublisher->name);
     $this->assertFieldEqual($aRow1, 'zonename', $doZone1->zonename);
     $this->assertFieldEqual($aRow1, 'impressions', 12);
     $this->assertFieldEqual($aRow1, 'requests', 14);
     $this->assertFieldEqual($aRow1, 'revenue', 16);
     $this->assertFieldEqual($aRow1, 'clicks', 18);
     $this->assertFieldEqual($aRow1, 'conversions', 20);
     $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
     $rsBannerStatistics = $this->_dalBannerStatistics->getBannerZoneStatistics($doBanner->bannerid, new Date('2007-09-21'), new Date('2007-09-21'));
     $rsBannerStatistics->find();
     $this->assertTrue($rsBannerStatistics->getRowCount() == 0, 'Recordset should be empty');
     // 5. Get 1 row
     $rsBannerStatistics = $this->_dalBannerStatistics->getBannerZoneStatistics($doBanner->bannerid, new Date('1984-01-01'), new Date('1984-03-09'));
     $rsBannerStatistics->find();
     $this->assertTrue($rsBannerStatistics->getRowCount() == 1, 'Some records should be returned');
 }
Ejemplo n.º 3
0
 /**
  * This method returns zone 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>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 getAgencyZoneStatistics($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->getAgencyZoneStatistics($agencyId, $oStartDate, $oEndDate, $localTZ);
         return true;
     } else {
         return false;
     }
 }