/** * A private method to return an array containing the start and end dates * of a report in a format that is suitable for display in a worksheet's * sub-heading. * * @access private * @return array An array containing the Start Date and End Date, if required. */ function _getDisplayableParametersFromDaySpan() { $aParams = array(); if (!is_null($this->_oDaySpan)) { global $date_format; $aParams[MAX_Plugin_Translation::translate('Start Date', $this->module, $this->package)] = $this->_oDaySpan->getStartDateString($date_format); $aParams[MAX_Plugin_Translation::translate('End Date', $this->module, $this->package)] = $this->_oDaySpan->getEndDateString($date_format); } return $aParams; }
/** * A method to test the setSpanPresetValue() method. */ function testSetSpanPresetValue() { $oDaySpan = new OA_Admin_DaySpan(); $oDaySpan->oNowDate = new Date('2007-05-09'); $oDaySpan->setSpanPresetValue('today'); $this->assertEqual($oDaySpan->getStartDateString(), '2007-05-09'); $this->assertEqual($oDaySpan->getEndDateString(), '2007-05-09'); $oDaySpan->oNowDate = new Date('2007-05-10'); $oDaySpan->setSpanPresetValue('today'); $this->assertEqual($oDaySpan->getStartDateString(), '2007-05-10'); $this->assertEqual($oDaySpan->getEndDateString(), '2007-05-10'); }
/** * A private method to prepare an array of connections and variable values for the * report. * * @access private * @return array An array with the following format: * array( * $trackerId => array( * 'connections' => array( * $connectionId => array( * 'data_intermediate_ad_connection_id' => Integer: The conversion ID * 'tracker_date_time' => Timestamp: The date/time of the conversion * 'tracker_day' => String: The day of the conversion in YYYY-MM-DD format * 'connection_date_time' => Timestamp: The date/time of the ad impression/click * 'connection_status' => Integer: The status of the connection * 'connection_channel' => Integer: The channel ID of the ad impression/click * 'connection_action' => Integer: If it was an ad impression or click * 'connection_ip_address' => String: The IP address of the ad impression/click * 'connection_country' => String: The country of the ad impression/click * 'connection_domain' => String: The domain of the ad impression/click * 'connection_language' => String: The language of the ad impression/click * 'connection_os' => String: The operating system of the ad impression/click * 'connection_browser' => String: The browser of the ad impression/click * 'connection_comments' => String: Any comments associated with the connection * 'advertiser_id' => Integer: The advertiser ID of the ad impression/click * 'advertiser_name' => String: The name of the advertiser of the ad impression/click * 'placement_id' => Integer: The placement ID of the ad impression/click * 'placement_name' => String: The name of the placement of the ad impression/click * 'ad_id' => Integer: The ad ID of the ad impression/click * 'ad_name' => String: The name of the ad of the ad impression/click * 'ad_alt' => String: The alt. name of the ad of the ad impression/click * 'publisher_id' => Integer: The publisher ID of the ad impression/click * 'publisher_name' => String: The name of the publisher of the ad impression/click * 'zone_id' => Integer: The zone ID of the ad impression/click * 'zone_name' => String: The name of the zone of the ad impression/click * 'tracker_id' => Integer: The tracker ID for the conversion * 'variables' => array( * $trackerVariableId => array( * tracker_variable_id => Integer: The tracker variable ID * tracker_variable_value => Mixed: The tracker variable value for the conversion * ) * ) * ) * ) * ) * ) */ function _prepareConnections() { $aConnections = array(); $aConf = $GLOBALS['_MAX']['CONF']; // Prepare the start and end dates for the conversion range $oDaySpan = new OA_Admin_DaySpan(); $oDaySpan->setSpanDays($this->_oDaySpan->oStartDate, $this->_oDaySpan->oEndDate); $oDaySpan->toUTC(); $startDateString = $oDaySpan->getStartDateString('%Y-%m-%d %H:%M:%S'); $endDateString = $oDaySpan->getEndDateString('%Y-%m-%d %H:%M:%S'); // Prepare the agency/advertiser/publisher limitations $agencyId = $this->_oScope->getAgencyId(); $advertiserId = $this->_oScope->getAdvertiserId(); $publisherId = $this->_oScope->getPublisherId(); // Prepare the query to select the required conversions and variable values $query = "\n SELECT\n diac.data_intermediate_ad_connection_id AS data_intermediate_ad_connection_id,\n diac.tracker_date_time AS tracker_date_time,\n diac.tracker_id AS tracker_id,\n diac.connection_date_time AS connection_date_time,\n diac.connection_status AS connection_status,\n diac.connection_channel AS connection_channel,\n diac.connection_action AS connection_action,\n diac.tracker_ip_address AS connection_ip_address,\n diac.tracker_country AS connection_country,\n diac.tracker_domain AS connection_domain,\n diac.tracker_language AS connection_language,\n diac.tracker_os AS connection_os,\n diac.tracker_browser AS connection_browser,\n diac.comments AS connection_comments,\n z.zoneid AS zone_id,\n z.zonename AS zone_name,\n p.affiliateid AS publisher_id,\n p.name AS publisher_name,\n a.clientid AS advertiser_id,\n a.clientname AS advertiser_name,\n c.campaignid AS placement_id,\n c.campaignname AS campaign_name,\n b.bannerid AS ad_id,\n b.description AS ad_name,\n b.alt AS ad_alt,\n diavv.tracker_variable_id AS tracker_variable_id,\n diavv.value AS tracker_variable_value\n FROM\n {$aConf['table']['prefix']}{$aConf['table']['data_intermediate_ad_connection']} AS diac\n JOIN\n {$aConf['table']['prefix']}{$aConf['table']['banners']} AS b\n ON\n (\n diac.ad_id = b.bannerid\n )\n JOIN\n {$aConf['table']['prefix']}{$aConf['table']['campaigns']} AS c\n ON\n (\n b.campaignid = c.campaignid\n )\n JOIN\n {$aConf['table']['prefix']}{$aConf['table']['clients']} AS a\n ON\n (\n c.clientid = a.clientid\n )\n LEFT JOIN\n {$aConf['table']['prefix']}{$aConf['table']['zones']} AS z\n ON\n (\n diac.zone_id = z.zoneid\n )\n LEFT JOIN\n {$aConf['table']['prefix']}{$aConf['table']['affiliates']} AS p\n ON\n (\n z.affiliateid = p.affiliateid\n )\n LEFT JOIN\n {$aConf['table']['prefix']}{$aConf['table']['data_intermediate_ad_variable_value']} AS diavv\n ON\n (\n diac.data_intermediate_ad_connection_id = diavv.data_intermediate_ad_connection_id\n )\n WHERE\n diac.tracker_date_time >= " . DBC::makeLiteral($startDateString, 'string') . "\n AND\n diac.tracker_date_time <= " . DBC::makeLiteral($endDateString, 'string') . "\n AND\n diac.inside_window = 1"; if ($agencyId) { $query .= "\n AND\n a.agencyid = " . DBC::makeLiteral($agencyId, 'integer'); } if ($advertiserId) { $query .= "\n AND\n a.clientid = " . DBC::makeLiteral($advertiserId, 'integer'); } if ($publisherId) { $query .= "\n AND\n z.affiliateid = " . DBC::makeLiteral($publisherId, 'integer'); } $query .= "\n ORDER BY\n tracker_id,\n data_intermediate_ad_connection_id"; // Select the conversions in the report $rsConversions = DBC::NewRecordSet($query); $rsConversions->find(); while ($rsConversions->fetch()) { $aConversion = $rsConversions->toArray(); $trackerId = $aConversion['tracker_id']; $connectionId = $aConversion['data_intermediate_ad_connection_id']; // Does this tracker/connection pair exist in the result array already? // It might, due to multiple attached variable values... if (!isset($aConnections[$trackerId]['connections'][$connectionId])) { // It's not set, store the connection details $oTrackerDate = new Date($aConversion['tracker_date_time']); $oTrackerDate->setTZbyID('UTC'); $oTrackerDate->convertTZ($this->_oDaySpan->oStartDate->tz); $oConnectionDate = new Date($aConversion['connection_date_time']); $oConnectionDate->setTZbyID('UTC'); $oConnectionDate->convertTZ($this->_oDaySpan->oStartDate->tz); $aConnections[$trackerId]['connections'][$connectionId] = array('data_intermediate_ad_connection_id' => $connectionId, 'tracker_date_time' => $oTrackerDate->format('%Y-%m-%d %H:%M:%S'), 'tracker_day' => $oTrackerDate->format('%Y-%m-%d'), 'connection_date_time' => $oConnectionDate->format('%Y-%m-%d %H:%M:%S'), 'connection_status' => $aConversion['connection_status'], 'connection_channel' => $aConversion['connection_channel'], 'connection_action' => $aConversion['connection_action'], 'connection_ip_address' => $aConversion['connection_ip_address'], 'connection_country' => $aConversion['connection_country'], 'connection_domain' => $aConversion['connection_domain'], 'connection_language' => $aConversion['connection_language'], 'connection_os' => $aConversion['connection_os'], 'connection_browser' => $aConversion['connection_browser'], 'connection_comments' => $aConversion['connection_comments'], 'advertiser_id' => $aConversion['advertiser_id'], 'advertiser_name' => $aConversion['advertiser_name'], 'placement_id' => $aConversion['placement_id'], 'placement_name' => $aConversion['placement_name'], 'ad_id' => $aConversion['ad_id'], 'ad_name' => $aConversion['ad_name'], 'ad_alt' => $aConversion['ad_alt'], 'publisher_id' => $aConversion['publisher_id'], 'publisher_name' => $aConversion['publisher_name'], 'zone_id' => $aConversion['zone_id'], 'zone_name' => $aConversion['zone_name'], 'tracker_id' => $aConversion['tracker_id']); } // Store the variable value associated with this connection, if one exists $trackerVariableId = $aConversion['tracker_variable_id']; if (!empty($trackerVariableId)) { $aConnections[$trackerId]['connections'][$connectionId]['variables'][$trackerVariableId] = array('tracker_variable_id' => $trackerVariableId, 'tracker_variable_value' => $aConversion['tracker_variable_value']); } } // Return the connections return $aConnections; }
/** * Take impressions from today's/yesterday's statistics and use them to augment the overall statistics. * * This step is only necessary because the underlying query builder is incapable of * joining a table to itself, which would be necessary to gather today's impressions * at the same time as those for the whole period. * * @access private * @param array $aReportData The result of * {@link Plugins_Reports_Standard_LiveCampaignDeliveryReport::_getDeliveryPerformanceDataRange()} * for the report period. * @param array $aYesterdayData The result of * {@link Plugins_Reports_Standard_LiveCampaignDeliveryReport::_getDeliveryPerformanceDataRange()} * for "yesterday". * @param OA_Admin_DaySpan $oSpanYesterday The OA_Admin_DaySpan object for "yesterday". * @param array $aTodayData The result of * {@link Plugins_Reports_Standard_LiveCampaignDeliveryReport::_getDeliveryPerformanceDataRange()} * for "today". * @param OA_Admin_DaySpan $oSpanToday The OA_Admin_DaySpan object for "today". * @return array An array of campaign information as per the $aReportData array, but also * including 'yesterdays_impressions' and 'todays_impressions', as well as * an hourly breakdown of "yesterday's" and "today's" impressions in hourly * format in 'yesterdays_impressions_by_hour' and 'todays_impressions_by_hour'. */ function _mergeDeliveryPerformanceData($aReportData, $aYesterdayData, $oSpanYesterday, $aTodayData, $oSpanToday) { $aData = array(); foreach ($aReportData as $aCampaignData) { $campaignId = $aCampaignData['campaign_id']; // Add yesterday's impressions to the campaign report period data $aCampaignDataYesterday = $this->_findMatchingCampaignData($campaignId, $aYesterdayData); $yesterdaysImpressions = $aCampaignDataYesterday['campaign_impressions']; $aCampaignData['yesterdays_impressions'] = $yesterdaysImpressions; // Get and add yesterday's impressions by hour $yesterdayDateString = $oSpanYesterday->getStartDateString(); $aYesterdaysImpressionsByHour = Admin_DA::getHourHistory(array('placement_id' => $campaignId, 'day_begin' => $yesterdayDateString, 'day_end' => $yesterdayDateString)); $aCampaignData['yesterdays_impressions_by_hour'] = $aYesterdaysImpressionsByHour; // Add today's impressions to the campaign report period data $aCampaignDataToday = $this->_findMatchingCampaignData($campaignId, $aTodayData); $todaysImpressions = $aCampaignDataToday['campaign_impressions']; $aCampaignData['todays_impressions'] = $todaysImpressions; // Get and add today's impressions by hour $todayDateString = $oSpanToday->getStartDateString(); $aTodaysImpressionsByHour = Admin_DA::getHourHistory(array('placement_id' => $campaignId, 'day_begin' => $todayDateString, 'day_end' => $todayDateString)); $aCampaignData['todays_impressions_by_hour'] = $aTodaysImpressionsByHour; // Add the newly merged data for this campaign to the return array $aData[] = $aCampaignData; } return $aData; }