r105051 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r105050‎ | r105051 | r105052 >
Date:03:43, 3 December 2011
Author:kaldari
Status:ok
Tags:
Comment:
removing timezone code, renaming some poorly named variables, adding comments
Modified paths:
  • /trunk/extensions/ContributionReporting/ContributionReporting.php (modified) (history)
  • /trunk/extensions/ContributionReporting/FundraiserStatistics_body.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/ContributionReporting.php
@@ -45,7 +45,6 @@
4646 $wgAutoloadClasses['SpecialYearlyTotal'] = $dir . 'YearlyTotal_body.php';
4747 $wgAutoloadClasses['DisabledNotice'] = $dir . 'DisabledNotice_body.php';
4848
49 -/*
5049 $wgSpecialPages['ContributionHistory'] = 'ContributionHistory';
5150 $wgSpecialPages['ContributionTotal'] = 'ContributionTotal';
5251 $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics';
@@ -53,8 +52,8 @@
5453 $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics';
5554 $wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal';
5655 $wgSpecialPages['YearlyTotal'] = 'SpecialYearlyTotal';
57 -*/
5856
 57+/*
5958 // Temporarily redirect all pages to DisabledNotice
6059 $wgSpecialPages['DisabledNotice'] = 'DisabledNotice';
6160 $wgSpecialPages['ContributionHistory'] = 'DisabledNotice';
@@ -64,6 +63,7 @@
6564 $wgSpecialPages['ContributionTrackingStatistics'] = 'DisabledNotice';
6665 $wgSpecialPages['DailyTotal'] = 'DisabledNotice';
6766 $wgSpecialPages['YearlyTotal'] = 'DisabledNotice';
 67+*/
6868
6969 $wgSpecialPageGroups['ContributionHistory'] = 'contribution';
7070 $wgSpecialPageGroups['ContributionTotal'] = 'contribution';
Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php
@@ -31,8 +31,6 @@
3232 }
3333 }
3434
35 - $this->timezone = $wgRequest->getText( 'timezone', '+0:00' );
36 -
3735 /* Configuration (this isn't totally static data, some of it gets built on the fly) */
3836
3937 $charts = array(
@@ -85,7 +83,8 @@
8684
8785 /* Display */
8886
89 - $wgOut->addWikiMsg('contribstats-header');
 87+ $wgOut->addWikiMsg( 'contribstats-header' ); // Header (typically empty)
 88+
9089 // Chart maximums
9190 foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) {
9291 foreach ( $charts as $name => $chart ) {
@@ -99,12 +98,25 @@
10099 foreach ( $charts as $name => $chart ) {
101100 $charts[$name]['factor'] = 300 / $chart['max'];
102101 }
 102+
103103 // HTML-time!
104 - $view = 0;
105 - $htmlViews = '';
 104+
 105+ // Each bar on the graph is associated with an individual data table. The ID linking the
 106+ // bar and the table is stored in $dataTableId.
 107+ $dataTableId = 0;
 108+ $dataTablesHtml = ''; // This will contain the HTML for all the data tables
106109 foreach ( $egFundraiserStatisticsFundraisers as $fundraiserIndex => $fundraiser ) {
 110+
 111+ // Get all the daily data for a particular fundraiser
107112 $days = $this->query( 'dailyTotals', $fundraiser['start'], $fundraiser['end'] );
108 - $mostRecentFundraiser = $fundraiserIndex == count( $egFundraiserStatisticsFundraisers ) - 1;
 113+
 114+ // See if this is the most recent fundraiser or not
 115+ if ( $fundraiserIndex == count( $egFundraiserStatisticsFundraisers ) - 1 ) {
 116+ $mostRecentFundraiser = true;
 117+ } else {
 118+ $mostRecentFundraiser = false;
 119+ }
 120+
109121 foreach ( $charts as $name => $chart ) {
110122 $column = 0;
111123 foreach( $days as $i => $day ) {
@@ -131,7 +143,7 @@
132144 $attributes = array(
133145 'style' => $style,
134146 'class' => "fundraiserstats-bar fundraiserstats-bar-{$fundraiser['id']}",
135 - 'rel' => "fundraiserstats-view-box-{$view}",
 147+ 'rel' => "fundraiserstats-view-box-{$dataTableId}",
136148 );
137149 if ( $mostRecentFundraiser && $i == count( $days ) -1 ) {
138150 $attributes['class'] .= ' fundraiserstats-current';
@@ -139,28 +151,31 @@
140152 $charts[$name]['data'][$column] .= Xml::tags(
141153 'td', array( 'valign' => 'bottom' ), Xml::element( 'div', $attributes, '', false )
142154 );
143 - $htmlView = Xml::openElement( 'tr' );
 155+
 156+ // Construct the data table for this day
 157+ $dataTable = Xml::openElement( 'tr' );
144158 $count = 0;
145159 foreach ( $charts as $subchart ) {
146 - $htmlView .= Xml::element(
 160+ $dataTable .= Xml::element(
147161 'td', array( 'width' => '16%', 'nowrap' => 'nowrap' ), wfMsg( $subchart['label'] )
148162 );
149 - $htmlView .= Xml::element(
 163+ $dataTable .= Xml::element(
150164 'td',
151165 array( 'width' => '16%', 'nowrap' => 'nowrap', 'align' => 'right' ),
152166 $wgLang->formatNum( number_format( $day[$subchart['index']], $subchart['precision'] ) )
153167 );
154168 if ( ++$count % 3 == 0 ) {
155 - $htmlView .= Xml::closeElement( 'tr' ) . Xml::openElement( 'tr' );
 169+ $dataTable .= Xml::closeElement( 'tr' ) . Xml::openElement( 'tr' );
156170 }
157171 }
158 - $htmlView .= Xml::closeElement( 'tr' );
159 - $htmlViews .= Xml::tags(
 172+ $dataTable .= Xml::closeElement( 'tr' );
 173+
 174+ $dataTablesHtml .= Xml::tags(
160175 'div',
161176 array(
162 - 'id' => 'fundraiserstats-view-box-' . $view,
 177+ 'id' => 'fundraiserstats-view-box-' . $dataTableId,
163178 'class' => 'fundraiserstats-view-box',
164 - 'style' => 'display: ' . ( $view == 0 ? 'block' : 'none' )
 179+ 'style' => 'display: ' . ( $dataTableId == 0 ? 'block' : 'none' )
165180 ),
166181 Xml::tags(
167182 'table',
@@ -171,7 +186,7 @@
172187 Xml::tags(
173188 'td',
174189 array( 'colspan' => 6 ),
175 - Xml::element( 'h3', array( 'style' => 'float:right;color:gray;' ), $day[0] ) .
 190+ Xml::element( 'h3', array( 'style' => 'float:right;color:gray;' ), $day[0] ) . // The date
176191 Xml::tags(
177192 'h3',
178193 array( 'style' => 'float:left;color:black;' ),
@@ -180,11 +195,11 @@
181196 Xml::element( 'div', array( 'style' => 'clear:both;' ), '', false )
182197 )
183198 ) .
184 - $htmlView
 199+ $dataTable
185200 )
186201 );
187202 $column++;
188 - $view++;
 203+ $dataTableId++;
189204 }
190205 }
191206 }
@@ -203,9 +218,6 @@
204219 }
205220 $wgOut->addHTML( Xml::openElement( 'div', array( 'id' => 'configholder' ) ) );
206221 $wgOut->addHTML( $years );
207 - // TODO: Fix timezone feature to work with caching correctly.
208 - // $wgOut->addHTML( wfMsg( 'fundraiserstats-time-zone' ).'<br/>' );
209 - // $wgOut->addHTML( '&#160;'.Xml::listDropDown( 'timezone', $this->dropDownList( range ( -12, 14, 1 ) ), '', $this->timezone, '', 1 ).' '.wfMsg( 'fundraiserstats-utc' ) );
210222 $wgOut->addHTML( Xml::closeElement( 'div' ) );
211223
212224 $wgOut->addHTML( Xml::closeElement( 'form' ) );
@@ -213,11 +225,13 @@
214226 // Instructions
215227 $wgOut->addWikiMsg( 'fundraiserstats-instructions' );
216228
 229+ $chartsHtml = ''; // This will contain the HTML for all of the bar charts and tabs
 230+
217231 // Tabs
 232+ $chartsHtml .= Xml::openElement( 'div', array( 'class' => 'fundraiserstats-chart-tabs' ) );
218233 $first = true;
219 - $htmlCharts = Xml::openElement( 'div', array( 'class' => 'fundraiserstats-chart-tabs' ) );
220234 foreach ( $charts as $chart => $columns ) {
221 - $htmlCharts .= Xml::tags(
 235+ $chartsHtml .= Xml::tags(
222236 'div',
223237 array(
224238 'id' => "fundraiserstats-chart-{$chart}-tab",
@@ -228,11 +242,12 @@
229243 );
230244 $first = false;
231245 }
232 - $htmlCharts .= Xml::closeElement( 'div' );
 246+ $chartsHtml .= Xml::closeElement( 'div' );
 247+
233248 // Charts
234249 $first = true;
235250 foreach ( $charts as $name => $chart ) {
236 - $htmlCharts .= Xml::tags(
 251+ $chartsHtml .= Xml::tags(
237252 'div',
238253 array(
239254 'id' => "fundraiserstats-chart-{$name}",
@@ -256,23 +271,35 @@
257272 'cellspacing' => 0,
258273 'border' => 0
259274 ),
260 - Xml::tags( 'tr', null, Xml::tags( 'td', null, $htmlCharts ) ) .
261 - Xml::tags( 'tr', null, Xml::tags( 'td', null, $htmlViews ) )
 275+ Xml::tags( 'tr', null, Xml::tags( 'td', null, $chartsHtml ) ) .
 276+ Xml::tags( 'tr', null, Xml::tags( 'td', null, $dataTablesHtml ) )
262277 )
263278 );
264 - $wgOut->addWikiMsg('contribstats-footer');
 279+ $wgOut->addWikiMsg( 'contribstats-footer' ); // Footer (typically empty)
265280 }
266281
267282 /* Private Functions */
268283
 284+ /**
 285+ * Retrieve the donation data from the database
 286+ *
 287+ * @param string $type Which type of query to do
 288+ * @param string $start The start date for a fundraiser
 289+ * @param string $end The end date for a fundraiser
 290+ * @return an array of results or null
 291+ */
269292 private function query( $type, $start, $end ) {
270293 global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout;
271294
 295+ // Conctruct the key for memcached
272296 $key = wfMemcKey( 'fundraiserstatistics', $type, $start, $end );
 297+
 298+ // If result exists in memcached, use that
273299 $cache = $wgMemc->get( $key );
274300 if ( $cache != false && $cache != -1 ) {
275301 return $cache;
276302 }
 303+
277304 // Use database
278305 $dbr = efContributionReportingConnection();
279306 $conditions = array(
@@ -285,7 +312,7 @@
286313 case 'dailyTotals':
287314 $select = $dbr->select( 'public_reporting',
288315 array(
289 - "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')",
 316+ "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')",
290317 'sum(converted_amount)',
291318 'count(*)',
292319 'avg(converted_amount)',
@@ -295,13 +322,14 @@
296323 __METHOD__ . '-dailyTotals',
297324 array(
298325 'ORDER BY' => 'received',
299 - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')"
 326+ 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')"
300327 )
301328 );
302329 $result = array();
303330 $ytd = 0;
304331 while ( $row = $dbr->fetchRow( $select ) ) {
305 - $row[] = $ytd += $row[1]; // YTD
 332+ // Insert the year-to-date amount as a record in the row (existing $ytd + sum)
 333+ $row[5] = $ytd += $row[1];
306334 $result[] = $row;
307335 }
308336 break;
@@ -312,7 +340,7 @@
313341 __METHOD__ . '-dailyTotalMax',
314342 array(
315343 'ORDER BY' => 'sum DESC',
316 - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')"
 344+ 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')"
317345 )
318346 );
319347 break;
@@ -330,7 +358,7 @@
331359 __METHOD__ . '-contributionsMax',
332360 array(
333361 'ORDER BY' => 'sum DESC',
334 - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')"
 362+ 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')"
335363 )
336364 );
337365 break;
@@ -341,7 +369,7 @@
342370 __METHOD__ . '-averagesMax',
343371 array(
344372 'ORDER BY' => 'sum DESC',
345 - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')"
 373+ 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')"
346374 )
347375 );
348376 break;
@@ -352,28 +380,16 @@
353381 __METHOD__ . '-maximumsMax',
354382 array(
355383 'ORDER BY' => 'sum DESC',
356 - 'GROUP BY' => "DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(received),'+00:00','$this->timezone'),'%Y-%m-%d')"
 384+ 'GROUP BY' => "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')"
357385 )
358386 );
359387 break;
360388 }
361389 if ( isset( $result ) ) {
 390+ // Store the result in memcached
362391 $wgMemc->set( $key, $result, $egFundraiserStatisticsCacheTimeout );
363392 return $result;
364393 }
365394 return null;
366395 }
367 -
368 - /**
369 - * @param $values
370 - * @return string
371 - */
372 - private function dropDownList ( $values ) {
373 - $dropDown = '';
374 - foreach ( $values as $value ) {
375 - if ( $value >= 0 ) $dropDown .= '+';
376 - $dropDown .= "$value:00\n";
377 - }
378 - return $dropDown;
379 - }
380396 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r105485MFT r105051, r105064, r105145, r105214, r105353, r105454awjrichards23:27, 7 December 2011

Status & tagging log