/** * 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; }
/** * A private method to retrieve the campaign delivery performance statistics for report's * date range, as well as for "yesterday" and "today", and to return the combined data. * * @access private * @return array */ function _getDeliveryPerformanceData() { // Get the report period raw performance data, using UTC time $oSpan = new OA_Admin_DaySpan(); $oSpan->setSpanDays($this->_oDaySpan->oStartDate, $this->_oDaySpan->oEndDate); $oSpan->toUTC(); $aReportData = $this->_getDeliveryPerformanceDataRange($this->_oScope, $oSpan, true); // Get the raw performance data for "yesterday", using UTC time $oSpanYesterday = new OA_Admin_DaySpan('yesterday'); $oSpanYesterday->toUTC(); $aYesterdayData = $this->_getDeliveryPerformanceDataRange($this->_oScope, $oSpanYesterday); // Get the raw performance data for "today", using UTC time $oSpanToday = new OA_Admin_DaySpan('today'); $oSpanToday->toUTC(); $aTodayData = $this->_getDeliveryPerformanceDataRange($this->_oScope, $oSpanToday); // Merge the above data, injecting today's delivery at the same time, // using normal time, as the merge process will convert to UTC time $oSpanYesterday = new OA_Admin_DaySpan('yesterday'); $oSpanToday = new OA_Admin_DaySpan('today'); $aData = $this->_mergeDeliveryPerformanceData($aReportData, $aYesterdayData, $oSpanYesterday, $aTodayData, $oSpanToday); return $aData; }