Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php |
— | — | @@ -307,7 +307,7 @@ |
308 | 308 | * Retrieve the donation data from the database |
309 | 309 | * |
310 | 310 | * @param boolean $mostRecent Is this query for the most recent fundraiser? |
311 | | - * @param string $start The start date for a fundraiser |
| 311 | + * @param string $start The start date for a fundraiser, e.g. 'Oct 22 2007' |
312 | 312 | * @param string $end The end date for a fundraiser |
313 | 313 | * @return an array of results or null |
314 | 314 | */ |
— | — | @@ -325,29 +325,61 @@ |
326 | 326 | |
327 | 327 | // Use database |
328 | 328 | $dbr = efContributionReportingConnection(); |
329 | | - $conditions = array( |
330 | | - 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) ) ), |
331 | | - 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ), |
332 | | - 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
333 | | - 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
334 | | - ); |
| 329 | + // Set timezone to UTC just in case |
| 330 | + date_default_timezone_set( 'UTC' ); |
335 | 331 | |
336 | | - // Get the data for a fundraiser |
337 | | - $select = $dbr->select( 'public_reporting', |
338 | | - array( |
339 | | - "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')", |
340 | | - 'sum(converted_amount)', |
341 | | - 'count(*)', |
342 | | - 'avg(converted_amount)', |
343 | | - 'max(converted_amount)', |
344 | | - ), |
345 | | - $conditions, |
346 | | - __METHOD__, |
347 | | - array( |
348 | | - 'ORDER BY' => 'received', |
349 | | - 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')" |
350 | | - ) |
351 | | - ); |
| 332 | + // If the summary table exists, use that, otherwise compute from scratch |
| 333 | + if ( mysql_num_rows( mysql_query( "SHOW TABLES LIKE 'public_reporting_days'" ) ) ) { |
| 334 | + |
| 335 | + $conditions = array( |
| 336 | + 'prd_date >= ' . $dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $start ) ) ), |
| 337 | + 'prd_date <= ' . $dbr->addQuotes( wfTimestamp( TS_DB, strtotime( $end ) ) ), |
| 338 | + ); |
| 339 | + |
| 340 | + // Get the data for a fundraiser |
| 341 | + $select = $dbr->select( 'public_reporting_days', |
| 342 | + array( |
| 343 | + 'prd_date', |
| 344 | + 'prd_total', |
| 345 | + 'prd_number', |
| 346 | + 'prd_average', |
| 347 | + 'prd_maximum', |
| 348 | + ), |
| 349 | + $conditions, |
| 350 | + __METHOD__, |
| 351 | + array( |
| 352 | + 'ORDER BY' => 'prd_date', |
| 353 | + ) |
| 354 | + ); |
| 355 | + |
| 356 | + } else { |
| 357 | + |
| 358 | + $conditions = array( |
| 359 | + 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) ) ), |
| 360 | + 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ), |
| 361 | + 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
| 362 | + 'converted_amount <= ' . $egFundraiserStatisticsMaximum, |
| 363 | + ); |
| 364 | + |
| 365 | + // Get the data for a fundraiser |
| 366 | + $select = $dbr->select( 'public_reporting', |
| 367 | + array( |
| 368 | + "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')", |
| 369 | + 'sum(converted_amount)', |
| 370 | + 'count(*)', |
| 371 | + 'avg(converted_amount)', |
| 372 | + 'max(converted_amount)', |
| 373 | + ), |
| 374 | + $conditions, |
| 375 | + __METHOD__, |
| 376 | + array( |
| 377 | + 'ORDER BY' => 'received', |
| 378 | + 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')" |
| 379 | + ) |
| 380 | + ); |
| 381 | + |
| 382 | + } |
| 383 | + |
352 | 384 | $result = array(); |
353 | 385 | $ytd = 0; |
354 | 386 | while ( $row = $dbr->fetchRow( $select ) ) { |