Index: trunk/extensions/ContributionReporting/DailyTotal_body.php |
— | — | @@ -22,17 +22,83 @@ |
23 | 23 | |
24 | 24 | $js = $wgRequest->getBool( 'js', false ); |
25 | 25 | |
26 | | - $timezone = $wgRequest->getVal( 'timezone', '0' ); |
27 | | - // Make sure it's a number and reasonable |
28 | | - if ( is_nan( $timezone ) || abs( $timezone ) > 100 ) { |
29 | | - $timezone = 0; |
30 | | - } |
| 26 | + $timezone = $wgRequest->getText( 'timezone', '0:00' ); |
31 | 27 | |
32 | 28 | /* Setup */ |
33 | 29 | $wgOut->disable(); |
34 | 30 | $this->sendHeaders(); |
35 | 31 | |
36 | | - $start = date( 'Y-m-d' ); // Get the current date |
| 32 | + $zoneList = array ( |
| 33 | + '-12:00' => 'Kwajalein', |
| 34 | + '-11:00' => 'Pacific/Midway', |
| 35 | + '-10:00' => 'Pacific/Honolulu', |
| 36 | + '-9:00' => 'America/Anchorage', |
| 37 | + '-09:00' => 'America/Anchorage', |
| 38 | + '-8:00' => 'America/Los_Angeles', |
| 39 | + '-08:00' => 'America/Los_Angeles', |
| 40 | + '-7:00' => 'America/Denver', |
| 41 | + '-07:00' => 'America/Denver', |
| 42 | + '-6:00' => 'America/Tegucigalpa', |
| 43 | + '-06:00' => 'America/Tegucigalpa', |
| 44 | + '-5:00' => 'America/New_York', |
| 45 | + '-05:00' => 'America/New_York', |
| 46 | + '-4:30' => 'America/Caracas', |
| 47 | + '-04:30' => 'America/Caracas', |
| 48 | + '-4:00' => 'America/Halifax', |
| 49 | + '-04:00' => 'America/Halifax', |
| 50 | + '-3:30' => 'America/St_Johns', |
| 51 | + '-03:30' => 'America/St_Johns', |
| 52 | + '-3:00' => 'America/Sao_Paulo', |
| 53 | + '-03:00' => 'America/Sao_Paulo', |
| 54 | + '-2:00' => 'Atlantic/South_Georgia', |
| 55 | + '-02:00' => 'Atlantic/South_Georgia', |
| 56 | + '-1:00' => 'Atlantic/Azores', |
| 57 | + '-01:00' => 'Atlantic/Azores', |
| 58 | + '0:00' => 'UTC', |
| 59 | + '00:00' => 'UTC', |
| 60 | + '1:00' => 'Europe/Belgrade', |
| 61 | + '01:00' => 'Europe/Belgrade', |
| 62 | + '2:00' => 'Europe/Minsk', |
| 63 | + '02:00' => 'Europe/Minsk', |
| 64 | + '3:00' => 'Asia/Kuwait', |
| 65 | + '03:00' => 'Asia/Kuwait', |
| 66 | + '3:30' => 'Asia/Tehran', |
| 67 | + '03:30' => 'Asia/Tehran', |
| 68 | + '4:00' => 'Asia/Muscat', |
| 69 | + '04:00' => 'Asia/Muscat', |
| 70 | + '5:00' => 'Asia/Yekaterinburg', |
| 71 | + '05:00' => 'Asia/Yekaterinburg', |
| 72 | + '5:30' => 'Asia/Kolkata', |
| 73 | + '05:30' => 'Asia/Kolkata', |
| 74 | + '5:45' => 'Asia/Katmandu', |
| 75 | + '05:45' => 'Asia/Katmandu', |
| 76 | + '6:00' => 'Asia/Dhaka', |
| 77 | + '06:00' => 'Asia/Dhaka', |
| 78 | + '6:30' => 'Asia/Rangoon', |
| 79 | + '06:30' => 'Asia/Rangoon', |
| 80 | + '7:00' => 'Asia/Krasnoyarsk', |
| 81 | + '07:00' => 'Asia/Krasnoyarsk', |
| 82 | + '8:00' => 'Asia/Brunei', |
| 83 | + '08:00' => 'Asia/Brunei', |
| 84 | + '9:00' => 'Asia/Seoul', |
| 85 | + '09:00' => 'Asia/Seoul', |
| 86 | + '9:30' => 'Australia/Darwin', |
| 87 | + '09:30' => 'Australia/Darwin', |
| 88 | + '10:00' => 'Australia/Canberra', |
| 89 | + '11:00' => 'Asia/Magadan', |
| 90 | + '12:00' => 'Pacific/Fiji', |
| 91 | + '13:00' => 'Pacific/Tongatapu', |
| 92 | + ); |
| 93 | + |
| 94 | + // Translate offset to timezone name for PHP |
| 95 | + if ( array_key_exists( $timezone, $zoneList ) ) { |
| 96 | + $timeZoneName = $zoneList[$timezone]; |
| 97 | + } else { |
| 98 | + $timeZoneName = 'UTC'; |
| 99 | + } |
| 100 | + |
| 101 | + $setTimeZone = date_default_timezone_set( $timeZoneName ); |
| 102 | + $start = date( 'Y-m-d' ); // Get the current date in the requested timezone |
37 | 103 | $total = $this->query( $timezone, $start ); |
38 | 104 | |
39 | 105 | $content = "wgFundraisingDailyTotal = $total;"; |
— | — | @@ -54,19 +120,18 @@ |
55 | 121 | if ( $cache != false && $cache != -1 ) { |
56 | 122 | return $cache; |
57 | 123 | } |
58 | | - $timeShift = $timezone * 60 * 60; |
| 124 | + |
59 | 125 | // Use database |
60 | 126 | $dbr = efContributionReportingConnection(); |
61 | 127 | #$dbr = wfGetDB( DB_MASTER ); |
62 | 128 | $conditions = array( |
63 | | - 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) + $timeShift ) ), |
64 | | - 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) + 24 * 60 * 60 + $timeShift ) ), |
65 | 129 | 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
66 | | - 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
| 130 | + 'converted_amount <= ' . $egFundraiserStatisticsMaximum, |
| 131 | + "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$timezone'),'%Y-%m-%d') = '$start'" |
67 | 132 | ); |
| 133 | + |
68 | 134 | $select = $dbr->select( 'public_reporting', |
69 | 135 | array( |
70 | | - "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')", |
71 | 136 | 'sum(converted_amount)' |
72 | 137 | ), |
73 | 138 | $conditions, |