/** * A method to update the summary table from the intermediate tables. * * @param PEAR::Date $oStartDate The start date/time to update from. * @param PEAR::Date $oEndDate The end date/time to update to. * @param array $aActions An array of data types to summarise. Contains * two array, the first containing the data types, * and the second containing the connection type * values associated with those data types, if * appropriate. For example: * array( * 'types' => array( * 0 => 'request', * 1 => 'impression', * 2 => 'click' * ), * 'connections' => array( * 1 => MAX_CONNECTION_AD_IMPRESSION, * 2 => MAX_CONNECTION_AD_CLICK * ) * ) * Note that the order of the items must match * the order of the items in the database tables * (e.g. in data_intermediate_ad and * data_summary_ad_hourly for the above example). * @param string $fromTable The name of the intermediate table to summarise * from (e.g. 'data_intermediate_ad'). * @param string $toTable The name of the summary table to summarise to * (e.g. 'data_summary_ad_hourly'). */ function saveSummary($oStartDate, $oEndDate, $aActions, $fromTable, $toTable) { $aConf = $GLOBALS['_MAX']['CONF']; // Check that there are types to summarise if (empty($aActions['types']) || empty($aActions['connections'])) { return; } // How many days does the start/end period span? $days = Date_Calc::dateDiff($oStartDate->getDay(), $oStartDate->getMonth(), $oStartDate->getYear(), $oEndDate->getDay(), $oEndDate->getMonth(), $oEndDate->getYear()); if ($days == 0) { // Save the data $this->_saveSummary($oStartDate, $oEndDate, $aActions, $fromTable, $toTable); } else { // Save each day's data separately for ($counter = 0; $counter <= $days; $counter++) { if ($counter == 0) { // This is the first day $oInternalStartDate = new Date(); $oInternalStartDate->copy($oStartDate); $oInternalEndDate = new Date($oStartDate->format('%Y-%m-%d') . ' 23:59:59'); } elseif ($counter == $days) { // This is the last day $oInternalStartDate = new Date($oEndDate->format('%Y-%m-%d') . ' 00:00:00'); $oInternalEndDate = new Date(); $oInternalEndDate->copy($oEndDate); } else { // This is a day in the middle $oDayDate = new Date(); $oDayDate->copy($oStartDate); $oDayDate->addSeconds(SECONDS_PER_DAY * $counter); $oInternalStartDate = new Date($oDayDate->format('%Y-%m-%d') . ' 00:00:00'); $oInternalEndDate = new Date($oDayDate->format('%Y-%m-%d') . ' 23:59:59'); } $this->_saveSummary($oInternalStartDate, $oInternalEndDate, $aActions, $fromTable, $toTable); } } }