/** * 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'); }
/** * 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; } }