Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -41,30 +41,22 @@ |
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 | +/* |
45 | 46 | $wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php'; |
46 | 47 | $wgAutoloadClasses['SpecialYearlyTotal'] = $dir . 'YearlyTotal_body.php'; |
47 | 48 | $wgAutoloadClasses['DisabledNotice'] = $dir . 'DisabledNotice_body.php'; |
| 49 | +*/ |
48 | 50 | |
49 | | -/* |
50 | 51 | $wgSpecialPages['ContributionHistory'] = 'ContributionHistory'; |
51 | 52 | $wgSpecialPages['ContributionTotal'] = 'ContributionTotal'; |
52 | 53 | $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics'; |
53 | 54 | $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics'; |
54 | 55 | $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics'; |
| 56 | +/* |
55 | 57 | $wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal'; |
56 | 58 | $wgSpecialPages['YearlyTotal'] = 'SpecialYearlyTotal'; |
57 | 59 | */ |
58 | 60 | |
59 | | -// Temporarily redirect all pages to DisabledNotice |
60 | | -$wgSpecialPages['DisabledNotice'] = 'DisabledNotice'; |
61 | | -$wgSpecialPages['ContributionHistory'] = 'DisabledNotice'; |
62 | | -$wgSpecialPages['ContributionTotal'] = 'DisabledNotice'; |
63 | | -$wgSpecialPages['ContributionStatistics'] = 'DisabledNotice'; |
64 | | -$wgSpecialPages['FundraiserStatistics'] = 'DisabledNotice'; |
65 | | -$wgSpecialPages['ContributionTrackingStatistics'] = 'DisabledNotice'; |
66 | | -$wgSpecialPages['DailyTotal'] = 'DisabledNotice'; |
67 | | -$wgSpecialPages['YearlyTotal'] = 'DisabledNotice'; |
68 | | - |
69 | 61 | $wgSpecialPageGroups['ContributionHistory'] = 'contribution'; |
70 | 62 | $wgSpecialPageGroups['ContributionTotal'] = 'contribution'; |
71 | 63 | $wgSpecialPageGroups['ContributionStatistics'] = 'contribution'; |
— | — | @@ -115,6 +107,10 @@ |
116 | 108 | ), |
117 | 109 | ); |
118 | 110 | |
| 111 | +// The first year of statistics to make visible by default. |
| 112 | +// We normally don't show all of them by default, since it makes the chart extremely wide. |
| 113 | +$egFundraiserStatisticsFirstYearDefault = 2009; |
| 114 | + |
119 | 115 | // Thesholds for fundraiser statistics |
120 | 116 | $egFundraiserStatisticsMinimum = 1; |
121 | 117 | $egFundraiserStatisticsMaximum = 10000; |
— | — | @@ -229,6 +225,11 @@ |
230 | 226 | |
231 | 227 | # Output |
232 | 228 | $output = $row['ttl'] ? $row['ttl'] : '0'; |
| 229 | + |
| 230 | + // Make sure fudge factor is a number |
| 231 | + if ( is_nan( $fudgeFactor ) ) { |
| 232 | + $fudgeFactor = 0; |
| 233 | + } |
233 | 234 | |
234 | 235 | $output += $fudgeFactor; |
235 | 236 | |
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/ContributionReporting.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
236 | 237 | Merged /trunk/extensions/ContributionReporting/ContributionReporting.php:r105051,105064,105145,105214,105353,105454 |
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/FundraiserStatistics_body.php |
— | — | @@ -1,6 +1,7 @@ |
2 | 2 | <?php |
3 | 3 | /** |
4 | 4 | * Special Page for Contribution statistics extension |
| 5 | + * This page displays charts and tables related to donation statistics. |
5 | 6 | * |
6 | 7 | * @file |
7 | 8 | * @ingroup Extensions |
— | — | @@ -15,15 +16,22 @@ |
16 | 17 | } |
17 | 18 | |
18 | 19 | public function execute( $sub ) { |
19 | | - global $wgRequest, $wgOut, $wgLang, $wgScriptPath, $egFundraiserStatisticsFundraisers; |
| 20 | + global $wgRequest, $wgOut, $wgLang, $wgScriptPath, $egFundraiserStatisticsFundraisers, |
| 21 | + $egFundraiserStatisticsFirstYearDefault; |
20 | 22 | |
| 23 | + // Figure out what years to display initially |
21 | 24 | $showYear = array(); |
22 | 25 | foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) { |
23 | | - if ( $wgRequest->wasPosted() ) { |
24 | | - $showYear[$fundraiser['id']] = $wgRequest->getCheck( 'toogle'.$fundraiser['id'] ); |
| 26 | + // You can override the years to display by default via the query string. |
| 27 | + // For example, Special:FundraiserStatistics?2007=show&2010=hide |
| 28 | + $yearOverride = $wgRequest->getVal( $fundraiser['id'] ); |
| 29 | + if ( $yearOverride === "hide" ) { |
| 30 | + $showYear[$fundraiser['id']] = false; |
| 31 | + } else if ( $yearOverride === "show" ) { |
| 32 | + $showYear[$fundraiser['id']] = true; |
25 | 33 | } else { |
26 | | - // By default, show only the fundraising years after 2008 |
27 | | - if ( intval( $fundraiser['id'] ) > 2008 ) { |
| 34 | + // By default, show only the recent fundraising years |
| 35 | + if ( intval( $fundraiser['id'] ) >= $egFundraiserStatisticsFirstYearDefault ) { |
28 | 36 | $showYear[$fundraiser['id']] = true; |
29 | 37 | } else { |
30 | 38 | $showYear[$fundraiser['id']] = false; |
— | — | @@ -31,15 +39,12 @@ |
32 | 40 | } |
33 | 41 | } |
34 | 42 | |
35 | | - $this->timezone = $wgRequest->getText( 'timezone', '+0:00' ); |
36 | | - |
37 | 43 | /* Configuration (this isn't totally static data, some of it gets built on the fly) */ |
38 | 44 | |
39 | 45 | $charts = array( |
40 | 46 | 'totals' => array( |
41 | 47 | 'data' => array(), |
42 | 48 | 'index' => 1, |
43 | | - 'query' => 'dailyTotalMax', |
44 | 49 | 'precision' => 2, |
45 | 50 | 'label' => 'fundraiserstats-total', |
46 | 51 | 'max' => 1, |
— | — | @@ -47,7 +52,6 @@ |
48 | 53 | 'contributions' => array( |
49 | 54 | 'data' => array(), |
50 | 55 | 'index' => 2, |
51 | | - 'query' => 'contributionsMax', |
52 | 56 | 'precision' => 0, |
53 | 57 | 'label' => 'fundraiserstats-contributions', |
54 | 58 | 'max' => 1, |
— | — | @@ -55,7 +59,6 @@ |
56 | 60 | 'averages' => array( |
57 | 61 | 'data' => array(), |
58 | 62 | 'index' => 3, |
59 | | - 'query' => 'averagesMax', |
60 | 63 | 'precision' => 2, |
61 | 64 | 'label' => 'fundraiserstats-avg', |
62 | 65 | 'max' => 1, |
— | — | @@ -63,7 +66,6 @@ |
64 | 67 | 'maximums' => array( |
65 | 68 | 'data' => array(), |
66 | 69 | 'index' => 4, |
67 | | - 'query' => 'maximumsMax', |
68 | 70 | 'precision' => 2, |
69 | 71 | 'label' => 'fundraiserstats-max', |
70 | 72 | 'max' => 1, |
— | — | @@ -71,7 +73,6 @@ |
72 | 74 | 'ytd' => array( |
73 | 75 | 'data' => array(), |
74 | 76 | 'index' => 5, |
75 | | - 'query' => 'yearlyTotalMax', |
76 | 77 | 'precision' => 2, |
77 | 78 | 'label' => 'fundraiserstats-ytd', |
78 | 79 | 'max' => 1, |
— | — | @@ -85,11 +86,30 @@ |
86 | 87 | |
87 | 88 | /* Display */ |
88 | 89 | |
89 | | - $wgOut->addWikiMsg('contribstats-header'); |
| 90 | + $wgOut->addWikiMsg( 'contribstats-header' ); // Header (typically empty) |
| 91 | + |
| 92 | + // The $fundraisingData array contains all of the fundraising data in the following scheme: |
| 93 | + // $fundraisingData[<fundraiserId>][<dayIndex>][<dataTypeIndex>] |
| 94 | + $fundraisingData = array(); |
| 95 | + |
| 96 | + foreach ( $egFundraiserStatisticsFundraisers as $fundraiserIndex => $fundraiser ) { |
| 97 | + |
| 98 | + // See if this is the most recent fundraiser or not |
| 99 | + if ( $fundraiserIndex == count( $egFundraiserStatisticsFundraisers ) - 1 ) { |
| 100 | + $mostRecent = true; |
| 101 | + } else { |
| 102 | + $mostRecent = false; |
| 103 | + } |
| 104 | + |
| 105 | + // Collect all the data |
| 106 | + $fundraisingData[$fundraiser['id']] = $this->query( $mostRecent, $fundraiser['start'], $fundraiser['end'] ); |
| 107 | + } |
| 108 | + |
90 | 109 | // Chart maximums |
91 | | - foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) { |
| 110 | + // We cycle through all the fundraisers with all the different chart types and collect the maximums. |
| 111 | + foreach ( $fundraisingData as $fundraiser ) { |
92 | 112 | foreach ( $charts as $name => $chart ) { |
93 | | - $chartMax = $this->query( $charts[$name]['query'], $fundraiser['start'], $fundraiser['end'] ); |
| 113 | + $chartMax = $this->getMaximum( $fundraiser, $chart['index'] ); |
94 | 114 | if ( $chartMax > $charts[$name]['max'] ) { |
95 | 115 | $charts[$name]['max'] = $chartMax; |
96 | 116 | } |
— | — | @@ -99,12 +119,25 @@ |
100 | 120 | foreach ( $charts as $name => $chart ) { |
101 | 121 | $charts[$name]['factor'] = 300 / $chart['max']; |
102 | 122 | } |
| 123 | + |
103 | 124 | // HTML-time! |
104 | | - $view = 0; |
105 | | - $htmlViews = ''; |
| 125 | + |
| 126 | + // Each bar on the graph is associated with an individual data table. The ID linking the |
| 127 | + // bar and the table is stored in $dataTableId. |
| 128 | + $dataTableId = 0; |
| 129 | + $dataTablesHtml = ''; // This will contain the HTML for all the data tables |
106 | 130 | foreach ( $egFundraiserStatisticsFundraisers as $fundraiserIndex => $fundraiser ) { |
107 | | - $days = $this->query( 'dailyTotals', $fundraiser['start'], $fundraiser['end'] ); |
108 | | - $mostRecentFundraiser = $fundraiserIndex == count( $egFundraiserStatisticsFundraisers ) - 1; |
| 131 | + |
| 132 | + // Get all the daily data for a particular fundraiser |
| 133 | + $days = $fundraisingData[$fundraiser['id']]; |
| 134 | + |
| 135 | + // See if this is the most recent fundraiser or not |
| 136 | + if ( $fundraiserIndex == count( $egFundraiserStatisticsFundraisers ) - 1 ) { |
| 137 | + $mostRecentFundraiser = true; |
| 138 | + } else { |
| 139 | + $mostRecentFundraiser = false; |
| 140 | + } |
| 141 | + |
109 | 142 | foreach ( $charts as $name => $chart ) { |
110 | 143 | $column = 0; |
111 | 144 | foreach( $days as $i => $day ) { |
— | — | @@ -125,13 +158,13 @@ |
126 | 159 | |
127 | 160 | $height = $chart['factor'] * $day[$chart['index']]; |
128 | 161 | $style = "height:{$height}px;"; |
129 | | - if ( $showYear[$fundraiser['id']] !== true ) { |
| 162 | + if ( !$showYear[$fundraiser['id']] ) { |
130 | 163 | $style .= "display:none;"; |
131 | 164 | } |
132 | 165 | $attributes = array( |
133 | 166 | 'style' => $style, |
134 | 167 | 'class' => "fundraiserstats-bar fundraiserstats-bar-{$fundraiser['id']}", |
135 | | - 'rel' => "fundraiserstats-view-box-{$view}", |
| 168 | + 'rel' => "fundraiserstats-view-box-{$dataTableId}", |
136 | 169 | ); |
137 | 170 | if ( $mostRecentFundraiser && $i == count( $days ) -1 ) { |
138 | 171 | $attributes['class'] .= ' fundraiserstats-current'; |
— | — | @@ -139,28 +172,31 @@ |
140 | 173 | $charts[$name]['data'][$column] .= Xml::tags( |
141 | 174 | 'td', array( 'valign' => 'bottom' ), Xml::element( 'div', $attributes, '', false ) |
142 | 175 | ); |
143 | | - $htmlView = Xml::openElement( 'tr' ); |
| 176 | + |
| 177 | + // Construct the data table for this day |
| 178 | + $dataTable = Xml::openElement( 'tr' ); |
144 | 179 | $count = 0; |
145 | 180 | foreach ( $charts as $subchart ) { |
146 | | - $htmlView .= Xml::element( |
| 181 | + $dataTable .= Xml::element( |
147 | 182 | 'td', array( 'width' => '16%', 'nowrap' => 'nowrap' ), wfMsg( $subchart['label'] ) |
148 | 183 | ); |
149 | | - $htmlView .= Xml::element( |
| 184 | + $dataTable .= Xml::element( |
150 | 185 | 'td', |
151 | 186 | array( 'width' => '16%', 'nowrap' => 'nowrap', 'align' => 'right' ), |
152 | 187 | $wgLang->formatNum( number_format( $day[$subchart['index']], $subchart['precision'] ) ) |
153 | 188 | ); |
154 | 189 | if ( ++$count % 3 == 0 ) { |
155 | | - $htmlView .= Xml::closeElement( 'tr' ) . Xml::openElement( 'tr' ); |
| 190 | + $dataTable .= Xml::closeElement( 'tr' ) . Xml::openElement( 'tr' ); |
156 | 191 | } |
157 | 192 | } |
158 | | - $htmlView .= Xml::closeElement( 'tr' ); |
159 | | - $htmlViews .= Xml::tags( |
| 193 | + $dataTable .= Xml::closeElement( 'tr' ); |
| 194 | + |
| 195 | + $dataTablesHtml .= Xml::tags( |
160 | 196 | 'div', |
161 | 197 | array( |
162 | | - 'id' => 'fundraiserstats-view-box-' . $view, |
| 198 | + 'id' => 'fundraiserstats-view-box-' . $dataTableId, |
163 | 199 | 'class' => 'fundraiserstats-view-box', |
164 | | - 'style' => 'display: ' . ( $view == 0 ? 'block' : 'none' ) |
| 200 | + 'style' => 'display: ' . ( $dataTableId == 0 ? 'block' : 'none' ) |
165 | 201 | ), |
166 | 202 | Xml::tags( |
167 | 203 | 'table', |
— | — | @@ -171,7 +207,7 @@ |
172 | 208 | Xml::tags( |
173 | 209 | 'td', |
174 | 210 | array( 'colspan' => 6 ), |
175 | | - Xml::element( 'h3', array( 'style' => 'float:right;color:gray;' ), $day[0] ) . |
| 211 | + Xml::element( 'h3', array( 'style' => 'float:right;color:gray;' ), $day[0] ) . // The date |
176 | 212 | Xml::tags( |
177 | 213 | 'h3', |
178 | 214 | array( 'style' => 'float:left;color:black;' ), |
— | — | @@ -180,11 +216,11 @@ |
181 | 217 | Xml::element( 'div', array( 'style' => 'clear:both;' ), '', false ) |
182 | 218 | ) |
183 | 219 | ) . |
184 | | - $htmlView |
| 220 | + $dataTable |
185 | 221 | ) |
186 | 222 | ); |
187 | 223 | $column++; |
188 | | - $view++; |
| 224 | + $dataTableId++; |
189 | 225 | } |
190 | 226 | } |
191 | 227 | } |
— | — | @@ -197,15 +233,12 @@ |
198 | 234 | |
199 | 235 | $years = wfMsg( 'fundraiserstats-show-years' ).'<br/>'; |
200 | 236 | foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) { |
201 | | - $years .= Xml::check( 'toogle'.$fundraiser['id'], $showYear[$fundraiser['id']], array( 'id' => 'bar-'.$fundraiser['id'], 'class' => 'yeartoggle' ) ); |
202 | | - $years .= Xml::label( $fundraiser['id'], 'toogle'.$fundraiser['id'] ); |
| 237 | + $years .= Xml::check( 'toggle'.$fundraiser['id'], $showYear[$fundraiser['id']], array( 'id' => 'bar-'.$fundraiser['id'], 'class' => 'yeartoggle' ) ); |
| 238 | + $years .= Xml::label( $fundraiser['id'], 'toggle'.$fundraiser['id'] ); |
203 | 239 | $years .= "<br/>"; |
204 | 240 | } |
205 | 241 | $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'configholder' ) ) ); |
206 | 242 | $wgOut->addHTML( $years ); |
207 | | - // TODO: Fix timezone feature to work with caching correctly. |
208 | | - // $wgOut->addHTML( wfMsg( 'fundraiserstats-time-zone' ).'<br/>' ); |
209 | | - // $wgOut->addHTML( ' '.Xml::listDropDown( 'timezone', $this->dropDownList( range ( -12, 14, 1 ) ), '', $this->timezone, '', 1 ).' '.wfMsg( 'fundraiserstats-utc' ) ); |
210 | 243 | $wgOut->addHTML( Xml::closeElement( 'div' ) ); |
211 | 244 | |
212 | 245 | $wgOut->addHTML( Xml::closeElement( 'form' ) ); |
— | — | @@ -213,11 +246,13 @@ |
214 | 247 | // Instructions |
215 | 248 | $wgOut->addWikiMsg( 'fundraiserstats-instructions' ); |
216 | 249 | |
| 250 | + $chartsHtml = ''; // This will contain the HTML for all of the bar charts and tabs |
| 251 | + |
217 | 252 | // Tabs |
| 253 | + $chartsHtml .= Xml::openElement( 'div', array( 'class' => 'fundraiserstats-chart-tabs' ) ); |
218 | 254 | $first = true; |
219 | | - $htmlCharts = Xml::openElement( 'div', array( 'class' => 'fundraiserstats-chart-tabs' ) ); |
220 | 255 | foreach ( $charts as $chart => $columns ) { |
221 | | - $htmlCharts .= Xml::tags( |
| 256 | + $chartsHtml .= Xml::tags( |
222 | 257 | 'div', |
223 | 258 | array( |
224 | 259 | 'id' => "fundraiserstats-chart-{$chart}-tab", |
— | — | @@ -228,11 +263,12 @@ |
229 | 264 | ); |
230 | 265 | $first = false; |
231 | 266 | } |
232 | | - $htmlCharts .= Xml::closeElement( 'div' ); |
| 267 | + $chartsHtml .= Xml::closeElement( 'div' ); |
| 268 | + |
233 | 269 | // Charts |
234 | 270 | $first = true; |
235 | 271 | foreach ( $charts as $name => $chart ) { |
236 | | - $htmlCharts .= Xml::tags( |
| 272 | + $chartsHtml .= Xml::tags( |
237 | 273 | 'div', |
238 | 274 | array( |
239 | 275 | 'id' => "fundraiserstats-chart-{$name}", |
— | — | @@ -247,7 +283,8 @@ |
248 | 284 | ); |
249 | 285 | $first = false; |
250 | 286 | } |
251 | | - // Output |
| 287 | + |
| 288 | + // Output everything |
252 | 289 | $wgOut->addHTML( |
253 | 290 | Xml::tags( |
254 | 291 | 'table', |
— | — | @@ -256,23 +293,36 @@ |
257 | 294 | 'cellspacing' => 0, |
258 | 295 | 'border' => 0 |
259 | 296 | ), |
260 | | - Xml::tags( 'tr', null, Xml::tags( 'td', null, $htmlCharts ) ) . |
261 | | - Xml::tags( 'tr', null, Xml::tags( 'td', null, $htmlViews ) ) |
| 297 | + Xml::tags( 'tr', null, Xml::tags( 'td', null, $chartsHtml ) ) . |
| 298 | + Xml::tags( 'tr', null, Xml::tags( 'td', null, $dataTablesHtml ) ) |
262 | 299 | ) |
263 | 300 | ); |
264 | | - $wgOut->addWikiMsg('contribstats-footer'); |
| 301 | + |
| 302 | + $wgOut->addWikiMsg( 'contribstats-footer' ); // Footer (typically empty) |
265 | 303 | } |
266 | 304 | |
267 | 305 | /* Private Functions */ |
268 | 306 | |
269 | | - private function query( $type, $start, $end ) { |
| 307 | + /** |
| 308 | + * Retrieve the donation data from the database |
| 309 | + * |
| 310 | + * @param boolean $mostRecent Is this query for the most recent fundraiser? |
| 311 | + * @param string $start The start date for a fundraiser |
| 312 | + * @param string $end The end date for a fundraiser |
| 313 | + * @return an array of results or null |
| 314 | + */ |
| 315 | + private function query( $mostRecent, $start, $end ) { |
270 | 316 | global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout; |
271 | 317 | |
272 | | - $key = wfMemcKey( 'fundraiserstatistics', $type, $start, $end ); |
| 318 | + // Conctruct the key for memcached |
| 319 | + $key = wfMemcKey( 'fundraiserstatistics', $start, $end ); |
| 320 | + |
| 321 | + // If result exists in memcached, use that |
273 | 322 | $cache = $wgMemc->get( $key ); |
274 | 323 | if ( $cache != false && $cache != -1 ) { |
275 | 324 | return $cache; |
276 | 325 | } |
| 326 | + |
277 | 327 | // Use database |
278 | 328 | $dbr = efContributionReportingConnection(); |
279 | 329 | $conditions = array( |
— | — | @@ -281,99 +331,60 @@ |
282 | 332 | 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
283 | 333 | 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
284 | 334 | ); |
285 | | - switch ( $type ) { |
286 | | - case 'dailyTotals': |
287 | | - $select = $dbr->select( 'public_reporting', |
288 | | - array( |
289 | | - "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')", |
290 | | - 'sum(converted_amount)', |
291 | | - 'count(*)', |
292 | | - 'avg(converted_amount)', |
293 | | - 'max(converted_amount)', |
294 | | - ), |
295 | | - $conditions, |
296 | | - __METHOD__ . '-dailyTotals', |
297 | | - array( |
298 | | - 'ORDER BY' => 'received', |
299 | | - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')" |
300 | | - ) |
301 | | - ); |
302 | | - $result = array(); |
303 | | - $ytd = 0; |
304 | | - while ( $row = $dbr->fetchRow( $select ) ) { |
305 | | - $row[] = $ytd += $row[1]; // YTD |
306 | | - $result[] = $row; |
307 | | - } |
308 | | - break; |
309 | | - case 'dailyTotalMax': |
310 | | - $result = $dbr->selectField( 'public_reporting', |
311 | | - array( 'sum(converted_amount) as sum' ), |
312 | | - $conditions, |
313 | | - __METHOD__ . '-dailyTotalMax', |
314 | | - array( |
315 | | - 'ORDER BY' => 'sum DESC', |
316 | | - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')" |
317 | | - ) |
318 | | - ); |
319 | | - break; |
320 | | - case 'yearlyTotalMax': |
321 | | - $result = $dbr->selectField( 'public_reporting', |
322 | | - array( 'sum(converted_amount) as sum' ), |
323 | | - $conditions, |
324 | | - __METHOD__ . '-yearlyTotalMax' |
325 | | - ); |
326 | | - break; |
327 | | - case 'contributionsMax': |
328 | | - $result = $dbr->selectField( 'public_reporting', |
329 | | - array( 'count(converted_amount) as sum' ), |
330 | | - $conditions, |
331 | | - __METHOD__ . '-contributionsMax', |
332 | | - array( |
333 | | - 'ORDER BY' => 'sum DESC', |
334 | | - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')" |
335 | | - ) |
336 | | - ); |
337 | | - break; |
338 | | - case 'averagesMax': |
339 | | - $result = $dbr->selectField( 'public_reporting', |
340 | | - array( 'avg(converted_amount) as sum' ), |
341 | | - $conditions, |
342 | | - __METHOD__ . '-averagesMax', |
343 | | - array( |
344 | | - 'ORDER BY' => 'sum DESC', |
345 | | - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')" |
346 | | - ) |
347 | | - ); |
348 | | - break; |
349 | | - case 'maximumsMax': |
350 | | - $result = $dbr->selectField( 'public_reporting', |
351 | | - array( 'max(converted_amount) as sum' ), |
352 | | - $conditions, |
353 | | - __METHOD__ . '-maximumsMax', |
354 | | - array( |
355 | | - 'ORDER BY' => 'sum DESC', |
356 | | - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')" |
357 | | - ) |
358 | | - ); |
359 | | - break; |
| 335 | + |
| 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 | + ); |
| 352 | + $result = array(); |
| 353 | + $ytd = 0; |
| 354 | + while ( $row = $dbr->fetchRow( $select ) ) { |
| 355 | + // Insert the year-to-date amount as a record in the row (existing $ytd + sum) |
| 356 | + $row[5] = $ytd += $row[1]; |
| 357 | + $result[] = $row; |
360 | 358 | } |
| 359 | + |
361 | 360 | if ( isset( $result ) ) { |
362 | | - $wgMemc->set( $key, $result, $egFundraiserStatisticsCacheTimeout ); |
| 361 | + // Store the result in memcached. |
| 362 | + // If it's the most recent fundraiser, cache for a short period of time, otherwise |
| 363 | + // cache for 24 hours (since the query is expensive). |
| 364 | + if ( $mostRecent ) { |
| 365 | + $wgMemc->set( $key, $result, $egFundraiserStatisticsCacheTimeout ); |
| 366 | + } else { |
| 367 | + $wgMemc->set( $key, $result, 86400 ); |
| 368 | + } |
363 | 369 | return $result; |
364 | 370 | } |
365 | 371 | return null; |
366 | 372 | } |
367 | | - |
| 373 | + |
368 | 374 | /** |
369 | | - * @param $values |
370 | | - * @return string |
| 375 | + * Given a particular index, find the maximum for all values in a 2D array with that particular |
| 376 | + * index as the 2nd key. |
| 377 | + * |
| 378 | + * @param array $fundraiserDays A 2D array of daily data for a particular fundraiser |
| 379 | + * @param integer $comparisonIndex The index to find the maximum for |
| 380 | + * @return an integer |
371 | 381 | */ |
372 | | - private function dropDownList ( $values ) { |
373 | | - $dropDown = ''; |
374 | | - foreach ( $values as $value ) { |
375 | | - if ( $value >= 0 ) $dropDown .= '+'; |
376 | | - $dropDown .= "$value:00\n"; |
| 382 | + private function getMaximum( $fundraiserDays, $comparisonIndex ) { |
| 383 | + $max = 0; |
| 384 | + foreach( $fundraiserDays as $day ) { |
| 385 | + if ( $day[$comparisonIndex] > $max ) { |
| 386 | + $max = $day[$comparisonIndex]; |
| 387 | + } |
377 | 388 | } |
378 | | - return $dropDown; |
| 389 | + return $max; |
379 | 390 | } |
380 | 391 | } |
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting/FundraiserStatistics_body.php |
___________________________________________________________________ |
Modified: svn:mergeinfo |
381 | 392 | Merged /trunk/extensions/ContributionReporting/FundraiserStatistics_body.php:r105051,105064,105145,105214,105353,105454 |
Index: branches/wmf/1.18wmf1/extensions/ContributionReporting/modules/ext.fundraiserstatistics.js |
— | — | @@ -33,9 +33,11 @@ |
34 | 34 | $j( '.fundraiserstats-current' ).each( function() { |
35 | 35 | replaceView( $j(this).attr( 'rel' ) ) |
36 | 36 | } ); |
| 37 | + // When someone clicks on a year, hide or show that year in the chart |
37 | 38 | $j( '#configholder .yeartoggle' ).click( function() { |
38 | 39 | $j('.fundraiserstats-'+$j(this).attr( 'id' )).toggle(); |
39 | 40 | } ); |
| 41 | + // When someone clicks on Customize, display pop-up menu and change arrow icon. |
40 | 42 | $j( '#configtoggle' ).click( function() { |
41 | 43 | $j('#configholder').toggle(); |
42 | 44 | if ($j( '#configtoggle a' ).css( 'background-position' ) == '0px -18px') { |
— | — | @@ -44,8 +46,5 @@ |
45 | 47 | $j( '#configtoggle a' ).css( 'background-position','0px -18px' ); |
46 | 48 | } |
47 | 49 | } ); |
48 | | - $j( '#timezone' ).change( function() { |
49 | | - $j('#configform').submit(); |
50 | | - } ); |
51 | 50 | |
52 | 51 | } ); |
Property changes on: branches/wmf/1.18wmf1/extensions/ContributionReporting |
___________________________________________________________________ |
Modified: svn:mergeinfo |
53 | 52 | Merged /trunk/extensions/ContributionReporting:r105051,105064,105145,105214,105353,105454 |