Index: trunk/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -42,6 +42,7 @@ |
43 | 43 | $wgAutoloadClasses['SpecialFundraiserStatistics'] = $dir . 'FundraiserStatistics_body.php'; |
44 | 44 | $wgAutoloadClasses['SpecialContributionTrackingStatistics'] = $dir . 'ContributionTrackingStatistics_body.php'; |
45 | 45 | $wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php'; |
| 46 | +$wgAutoloadClasses['SpecialYearlyTotal'] = $dir . 'YearlyTotal_body.php'; |
46 | 47 | |
47 | 48 | $wgSpecialPages['ContributionHistory'] = 'ContributionHistory'; |
48 | 49 | $wgSpecialPages['ContributionTotal'] = 'ContributionTotal'; |
— | — | @@ -49,6 +50,7 @@ |
50 | 51 | $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics'; |
51 | 52 | $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics'; |
52 | 53 | $wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal'; |
| 54 | +$wgSpecialPages['YearlyTotal'] = 'SpecialYearlyTotal'; |
53 | 55 | $wgSpecialPageGroups['ContributionHistory'] = 'contribution'; |
54 | 56 | $wgSpecialPageGroups['ContributionTotal'] = 'contribution'; |
55 | 57 | $wgSpecialPageGroups['ContributionStatistics'] = 'contribution'; |
— | — | @@ -67,6 +69,7 @@ |
68 | 70 | $egContributionStatisticsViewDays = 7; |
69 | 71 | |
70 | 72 | // Fundraiser dates |
| 73 | +// Please list these in chronological order |
71 | 74 | $egFundraiserStatisticsFundraisers = array( |
72 | 75 | array( |
73 | 76 | 'id' => '2007', |
— | — | @@ -162,6 +165,7 @@ |
163 | 166 | |
164 | 167 | function efContributionReportingTotal( $start, $fudgeFactor ) { |
165 | 168 | $db = efContributionReportingConnection(); |
| 169 | + #$db = wfGetDB( DB_MASTER ); |
166 | 170 | |
167 | 171 | $sql = 'SELECT ROUND( SUM(converted_amount) ) AS ttl FROM public_reporting'; |
168 | 172 | |
Index: trunk/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -10,7 +10,6 @@ |
11 | 11 | |
12 | 12 | protected $sharedMaxAge = 300; // Cache for 5 minutes on the server side |
13 | 13 | protected $maxAge = 300; // Cache for 5 minutes on the client side |
14 | | - public $timezone; |
15 | 14 | |
16 | 15 | /* Functions */ |
17 | 16 | |
— | — | @@ -21,18 +20,18 @@ |
22 | 21 | public function execute( $sub ) { |
23 | 22 | global $wgRequest, $wgOut; |
24 | 23 | |
25 | | - $this->timezone = $wgRequest->getVal( 'timezone', '0' ); |
| 24 | + $timezone = $wgRequest->getVal( 'timezone', '0' ); |
26 | 25 | // Make sure it's a number and reasonable |
27 | | - if ( is_nan( $this->timezone ) || abs( $this->timezone ) > 100 ) { |
28 | | - $this->timezone = 0; |
| 26 | + if ( is_nan( $timezone ) || abs( $timezone ) > 100 ) { |
| 27 | + $timezone = 0; |
29 | 28 | } |
30 | 29 | |
31 | 30 | /* Setup */ |
32 | 31 | $wgOut->disable(); |
33 | 32 | $this->sendHeaders(); |
34 | 33 | |
35 | | - $start = date( 'Y-m-d' ); // Get the current date |
36 | | - $total = $this->query( $start ); |
| 34 | + $start = time(); // Get the current unix timestamp |
| 35 | + $total = $this->query( $timezone, $start ); |
37 | 36 | |
38 | 37 | $content = "wgFundraisingDailyTotal = $total;"; |
39 | 38 | echo $content; |
— | — | @@ -40,21 +39,21 @@ |
41 | 40 | |
42 | 41 | /* Private Functions */ |
43 | 42 | |
44 | | - private function query( $start ) { |
| 43 | + private function query( $timezone, $start ) { |
45 | 44 | global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout; |
46 | 45 | |
47 | | - $key = wfMemcKey( 'fundraiserstatistics', $this->timezone, $start ); |
| 46 | + $key = wfMemcKey( 'fundraiserstatistics', $timezone, $start ); |
48 | 47 | $cache = $wgMemc->get( $key ); |
49 | 48 | if ( $cache != false && $cache != -1 ) { |
50 | 49 | return $cache; |
51 | 50 | } |
52 | | - $timeShift = $this->timezone * 60 * 60; |
| 51 | + $timeShift = $timezone * 60 * 60; |
53 | 52 | // Use database |
54 | | - //$dbr = efContributionReportingConnection(); |
55 | | - $dbr = wfGetDB( DB_MASTER ); |
| 53 | + $dbr = efContributionReportingConnection(); |
| 54 | + #$dbr = wfGetDB( DB_MASTER ); |
56 | 55 | $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 ) ), |
| 56 | + 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, $start + $timeShift ) ), |
| 57 | + 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, $start + 24 * 60 * 60 + $timeShift ) ), |
59 | 58 | 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
60 | 59 | 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
61 | 60 | ); |
— | — | @@ -71,12 +70,10 @@ |
72 | 71 | ); |
73 | 72 | $row = $dbr->fetchRow( $select ); |
74 | 73 | $total = $row['sum(converted_amount)']; |
| 74 | + if ( !$total ) $total = 0; |
75 | 75 | |
76 | | - if ( $total ) { |
77 | | - $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
78 | | - return $total; |
79 | | - } |
80 | | - return null; |
| 76 | + $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
| 77 | + return $total; |
81 | 78 | } |
82 | 79 | |
83 | 80 | private function sendHeaders() { |
Index: trunk/extensions/ContributionReporting/YearlyTotal_body.php |
— | — | @@ -0,0 +1,70 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special Page for Contribution statistics extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +class SpecialYearlyTotal extends IncludableSpecialPage { |
| 11 | + |
| 12 | + protected $sharedMaxAge = 600; // Cache for 10 minutes on the server side |
| 13 | + protected $maxAge = 600; // Cache for 10 minutes on the client side |
| 14 | + |
| 15 | + /* Functions */ |
| 16 | + |
| 17 | + public function __construct() { |
| 18 | + parent::__construct( 'YearlyTotal' ); |
| 19 | + } |
| 20 | + |
| 21 | + public function execute( $sub ) { |
| 22 | + global $wgRequest, $wgOut, $egFundraiserStatisticsFundraisers; |
| 23 | + |
| 24 | + $adjustment = $wgRequest->getVal( 'adjustment' ); |
| 25 | + // Make sure it's a number |
| 26 | + if ( is_nan( $adjustment ) ) { |
| 27 | + $adjustment = 0; |
| 28 | + } |
| 29 | + |
| 30 | + /* Setup */ |
| 31 | + $wgOut->disable(); |
| 32 | + $this->sendHeaders(); |
| 33 | + |
| 34 | + $total = $this->query( $adjustment ); |
| 35 | + |
| 36 | + $content = "wgFundraisingYearlyTotal = $total;"; |
| 37 | + echo $content; |
| 38 | + } |
| 39 | + |
| 40 | + /* Private Functions */ |
| 41 | + |
| 42 | + private function query( $adjustment ) { |
| 43 | + global $wgMemc, $egFundraiserStatisticsCacheTimeout, $egFundraiserStatisticsFundraisers; |
| 44 | + |
| 45 | + $currenctFundraiserIndex = count( $egFundraiserStatisticsFundraisers ) - 1; |
| 46 | + $year = $egFundraiserStatisticsFundraisers[$currenctFundraiserIndex]['id']; |
| 47 | + |
| 48 | + $key = wfMemcKey( 'fundraiserstatistics', $year, $adjustment ); |
| 49 | + $cache = $wgMemc->get( $key ); |
| 50 | + if ( $cache != false && $cache != -1 ) { |
| 51 | + return $cache; |
| 52 | + } |
| 53 | + |
| 54 | + // Get the timestamp for the start of the current fundraiser |
| 55 | + // Note: This depends on the fundraisers being listed in chronological order |
| 56 | + $start = strtotime( $egFundraiserStatisticsFundraisers[$currenctFundraiserIndex]['start'] ); |
| 57 | + $start = intval( wfTimestampOrNull( TS_UNIX, $start ) ); |
| 58 | + |
| 59 | + $total = efContributionReportingTotal( $start, $adjustment ); |
| 60 | + if ( !$total ) $total = 0; |
| 61 | + |
| 62 | + $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout ); |
| 63 | + return $total; |
| 64 | + } |
| 65 | + |
| 66 | + private function sendHeaders() { |
| 67 | + global $wgJsMimeType; |
| 68 | + header( "Content-type: $wgJsMimeType; charset=utf-8" ); |
| 69 | + header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" ); |
| 70 | + } |
| 71 | +} |