/** * This method returns zone 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>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 zone * <li><b>impressions integer</b> The number of impressions for the zone * <li><b>clicks integer</b> The number of clicks for the zone * <li><b>revenue decimal</b> The revenue earned for the zone * </ul> * * @return boolean True if the operation was successful and false if not. * */ function getPublisherZoneStatistics($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->getPublisherZoneStatistics($publisherId, $oStartDate, $oEndDate, $localTZ); return true; } else { return false; } }
/** * Test publisher zone statistics. * */ function testGetPublisheryZoneStatistics() { $doAgency = OA_Dal::factoryDO('agency'); $doPublisher = OA_Dal::factoryDO('affiliates'); $doPublisher->name = 'test publisher'; $doZone1 = OA_Dal::factoryDO('zones'); $doZone1->zonename = 'test zone'; $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 = 3; $doDataSummaryAdHourly->total_revenue = 5; $doDataSummaryAdHourly->clicks = 6; $doDataSummaryAdHourly->date_time = '2007-03-01'; $this->generateDataSummaryAdHourlyForZone($doDataSummaryAdHourly, $doZone1); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->impressions = 1; $doDataSummaryAdHourly->requests = 3; $doDataSummaryAdHourly->total_revenue = 5; $doDataSummaryAdHourly->clicks = 6; $doDataSummaryAdHourly->date_time = '2007-03-02'; $this->generateDataSummaryAdHourlyForZone($doDataSummaryAdHourly, $doZone1); $doDataSummaryAdHourly = OA_Dal::factoryDO('data_summary_ad_hourly'); $doDataSummaryAdHourly->impressions = 0; $doDataSummaryAdHourly->requests = 0; $doDataSummaryAdHourly->total_revenue = 0; $doDataSummaryAdHourly->clicks = 1; $doDataSummaryAdHourly->date_time = '2007-02-02'; $this->generateDataSummaryAdHourlyForZone($doDataSummaryAdHourly, $doZone2); // 1. Get data existing range $rsPublisherStatistics = $this->_dalPublisherStatistics->getPublisherZoneStatistics($doPublisher->affiliateid, new Date('2007-01-01'), new Date('2007-03-02')); $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, 'zoneid', $doZone1->zoneid); // 2. Check return fields names $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, 'zoneid', $doZone1->zoneid); $this->assertFieldEqual($aRow1, 'zonename', $doZone1->zonename); $this->assertFieldEqual($aRow1, 'impressions', 2); $this->assertFieldEqual($aRow1, 'requests', 6); $this->assertFieldEqual($aRow1, 'revenue', 10); $this->assertFieldEqual($aRow1, 'clicks', 12); $this->assertFieldEqual($aRow2, 'impressions', 0); $this->assertFieldEqual($aRow2, 'requests', 0); $this->assertFieldEqual($aRow2, 'revenue', 0); $this->assertFieldEqual($aRow2, 'clicks', 1); // 4. Get data in not existing range $rsPublisherStatistics = $this->_dalPublisherStatistics->getPublisherZoneStatistics($doPublisher->affiliateid, new Date('2007-05-01'), new Date('2007-05-02')); $rsPublisherStatistics->find(); $this->assertTrue($rsPublisherStatistics->getRowCount() == 0, 'Recordset should be empty'); }