Index: trunk/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -41,12 +41,14 @@ |
42 | 42 | $wgAutoloadClasses['SpecialContributionStatistics'] = $dir . 'ContributionStatistics_body.php'; |
43 | 43 | $wgAutoloadClasses['SpecialFundraiserStatistics'] = $dir . 'FundraiserStatistics_body.php'; |
44 | 44 | $wgAutoloadClasses['SpecialContributionTrackingStatistics'] = $dir . 'ContributionTrackingStatistics_body.php'; |
| 45 | +$wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php'; |
45 | 46 | |
46 | 47 | $wgSpecialPages['ContributionHistory'] = 'ContributionHistory'; |
47 | 48 | $wgSpecialPages['ContributionTotal'] = 'ContributionTotal'; |
48 | 49 | $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics'; |
49 | 50 | $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics'; |
50 | 51 | $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics'; |
| 52 | +$wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal'; |
51 | 53 | $wgSpecialPageGroups['ContributionHistory'] = 'contribution'; |
52 | 54 | $wgSpecialPageGroups['ContributionTotal'] = 'contribution'; |
53 | 55 | $wgSpecialPageGroups['ContributionStatistics'] = 'contribution'; |
Index: trunk/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -0,0 +1,87 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special Page for Contribution statistics extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class SpecialDailyTotal extends IncludableSpecialPage { |
| 11 | + |
| 12 | + protected $sharedMaxAge = 300; // Cache for 5 minutes on the server side |
| 13 | + protected $maxAge = 300; // Cache for 5 minutes on the client side |
| 14 | + public $timezone; |
| 15 | + |
| 16 | + /* Functions */ |
| 17 | + |
| 18 | + public function __construct() { |
| 19 | + parent::__construct( 'DailyTotal' ); |
| 20 | + } |
| 21 | + |
| 22 | + public function execute( $sub ) { |
| 23 | + global $wgRequest, $wgOut; |
| 24 | + |
| 25 | + $this->timezone = $wgRequest->getVal( 'timezone', '0' ); |
| 26 | + // Make sure it's a number and reasonable |
| 27 | + if ( is_nan( $this->timezone ) || abs( $this->timezone ) > 100 ) { |
| 28 | + $this->timezone = 0; |
| 29 | + } |
| 30 | + |
| 31 | + /* Setup */ |
| 32 | + $wgOut->disable(); |
| 33 | + $this->sendHeaders(); |
| 34 | + |
| 35 | + $start = date( 'Y-m-d' ); // Get the current date |
| 36 | + $total = $this->query( $start ); |
| 37 | + |
| 38 | + $content = "wgFundraisingDailyTotal = $total;"; |
| 39 | + echo $content; |
| 40 | + } |
| 41 | + |
| 42 | + /* Private Functions */ |
| 43 | + |
| 44 | + private function query( $start ) { |
| 45 | + global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout; |
| 46 | + |
| 47 | + $key = wfMemcKey( 'fundraiserstatistics', $this->timezone, $start ); |
| 48 | + $cache = $wgMemc->get( $key ); |
| 49 | + if ( $cache != false && $cache != -1 ) { |
| 50 | + return $cache; |
| 51 | + } |
| 52 | + $timeShift = $this->timezone * 60 * 60; |
| 53 | + // Use database |
| 54 | + //$dbr = efContributionReportingConnection(); |
| 55 | + $dbr = wfGetDB( DB_MASTER ); |
| 56 | + $conditions = array( |
| 57 | + 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) + $timeShift ) ), |
| 58 | + 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) + 24 * 60 * 60 + $timeShift ) ), |
| 59 | + 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
| 60 | + 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
| 61 | + ); |
| 62 | + $select = $dbr->select( 'public_reporting', |
| 63 | + array( |
| 64 | + "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')", |
| 65 | + 'sum(converted_amount)' |
| 66 | + ), |
| 67 | + $conditions, |
| 68 | + __METHOD__, |
| 69 | + array( |
| 70 | + 'ORDER BY' => 'received' |
| 71 | + ) |
| 72 | + ); |
| 73 | + $row = $dbr->fetchRow( $select ); |
| 74 | + $total = $row['sum(converted_amount)']; |
| 75 | + |
| 76 | + if ( $total ) { |
| 77 | + $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
| 78 | + return $total; |
| 79 | + } |
| 80 | + return null; |
| 81 | + } |
| 82 | + |
| 83 | + private function sendHeaders() { |
| 84 | + global $wgJsMimeType; |
| 85 | + header( "Content-type: $wgJsMimeType; charset=utf-8" ); |
| 86 | + header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" ); |
| 87 | + } |
| 88 | +} |