Index: trunk/extensions/ContributionReporting/ContributionReporting.php |
— | — | @@ -32,10 +32,12 @@ |
33 | 33 | $wgAutoloadClasses['ContributionHistory'] = $dir . 'ContributionHistory_body.php'; |
34 | 34 | $wgAutoloadClasses['ContributionTotal'] = $dir . 'ContributionTotal_body.php'; |
35 | 35 | $wgAutoloadClasses['SpecialContributionStatistics'] = $dir . 'ContributionStatistics_body.php'; |
| 36 | +$wgAutoloadClasses['SpecialFundraiserStatistics'] = $dir . 'FundraiserStatistics_body.php'; |
36 | 37 | |
37 | 38 | $wgSpecialPages['ContributionHistory'] = 'ContributionHistory'; |
38 | 39 | $wgSpecialPages['ContributionTotal'] = 'ContributionTotal'; |
39 | 40 | $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics'; |
| 41 | +$wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics'; |
40 | 42 | |
41 | 43 | // Shortcut to this extension directory |
42 | 44 | $dir = dirname( __FILE__ ) . '/'; |
— | — | @@ -46,6 +48,26 @@ |
47 | 49 | // Days back to show |
48 | 50 | $egContributionStatisticsViewDays = 7; |
49 | 51 | |
| 52 | +// Fundraiser dates |
| 53 | +$egFundraiserStatisticsFundraisers = array( |
| 54 | + array( |
| 55 | + 'title' => '2007 Fundraiser', |
| 56 | + 'start' => 'Oct 22 2007', |
| 57 | + 'end' => 'Jan 3 2008', |
| 58 | + 'color' => '#AAAAFF' |
| 59 | + ), |
| 60 | + array( |
| 61 | + 'title' => '2008 Fundraiser', |
| 62 | + 'start' => 'Nov 4 2008', |
| 63 | + 'end' => 'Jan 9 2009', |
| 64 | + 'color' => '#AAFFAA' |
| 65 | + ) |
| 66 | +); |
| 67 | + |
| 68 | +// Thesholds for fundraiser statistics |
| 69 | +$egFundraiserStatisticsMinimum = 1; |
| 70 | +$egFundraiserStatisticsMaximum = 10000; |
| 71 | + |
50 | 72 | // Automatically use a local or special database connection |
51 | 73 | function efContributionReportingConnection() { |
52 | 74 | global $wgContributionReportingDBserver, $wgContributionReportingDBname; |
Index: trunk/extensions/ContributionReporting/FundraiserStatistics_body.php |
— | — | @@ -0,0 +1,156 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Special Page for Contribution statistics extension |
| 5 | + * |
| 6 | + * @file |
| 7 | + * @ingroup Extensions |
| 8 | + */ |
| 9 | + |
| 10 | +// Special page ContributionStatistics |
| 11 | +class SpecialFundraiserStatistics extends SpecialPage { |
| 12 | + |
| 13 | + /* Functions */ |
| 14 | + |
| 15 | + public function __construct() { |
| 16 | + // Initialize special page |
| 17 | + parent::__construct( 'FundraiserStatistics' ); |
| 18 | + |
| 19 | + // Internationalization |
| 20 | + wfLoadExtensionMessages( 'ContributionReporting' ); |
| 21 | + } |
| 22 | + |
| 23 | + public function execute( $sub ) { |
| 24 | + global $wgRequest, $wgOut, $wgUser; |
| 25 | + global $egFundraiserStatisticsFundraisers; |
| 26 | + |
| 27 | + // Begin output |
| 28 | + $this->setHeaders(); |
| 29 | + |
| 30 | + $htmlOut = Xml::openElement( 'div', array( 'style' => 'margin-bottom: 10px;' ) ); |
| 31 | + $today = strtotime( date( 'M j Y' ) ); |
| 32 | + |
| 33 | + $columns = array(); |
| 34 | + foreach ( $egFundraiserStatisticsFundraisers as $fundraiser ) { |
| 35 | + $htmlOut .= Xml::element( 'span', |
| 36 | + array( |
| 37 | + 'style' => "background-color:{$fundraiser['color']};" . |
| 38 | + "border:outset 1px {$fundraiser['color']};" . |
| 39 | + "padding:5px;" |
| 40 | + ), |
| 41 | + $fundraiser['title'] |
| 42 | + ); |
| 43 | + |
| 44 | + // Get data for fundraiser |
| 45 | + $days = $this->getDailyTotals( $fundraiser['start'], $fundraiser['end'] ); |
| 46 | + |
| 47 | + // Determine maximimum for fundraiser |
| 48 | + $max = 0; |
| 49 | + foreach ( $days as $day ) { |
| 50 | + if ( $day[0] > $max ) { |
| 51 | + $max = $day[0]; |
| 52 | + } |
| 53 | + } |
| 54 | + |
| 55 | + $todayStyle = 'position:absolute;' . |
| 56 | + 'width:6px;' . |
| 57 | + 'height:6px;' . |
| 58 | + 'background-color:black;' . |
| 59 | + 'margin-top:3px;' . |
| 60 | + 'margin-left:-1px'; |
| 61 | + |
| 62 | + // Build columns |
| 63 | + $column = 0; |
| 64 | + foreach( $days as $day ) { |
| 65 | + $height = ( 200 / $max ) * $day[0]; |
| 66 | + if ( !isset( $columns[$column] ) ) { |
| 67 | + $columns[$column] = ''; |
| 68 | + } |
| 69 | + $style = "height:{$height}px;" . |
| 70 | + "width:4px;" . |
| 71 | + "background-color:{$fundraiser['color']};" . |
| 72 | + "border:outset 1px {$fundraiser['color']};"; |
| 73 | + $extra = ''; |
| 74 | + if( strtotime( $day[1] ) == $today ) { |
| 75 | + $extra = Xml::element( 'div', |
| 76 | + array( |
| 77 | + 'style' => $todayStyle |
| 78 | + ) |
| 79 | + ); |
| 80 | + } |
| 81 | + $columns[$column] .= Xml::tags( 'td', array( 'valign' => 'bottom' ), |
| 82 | + Xml::element( 'div', array( 'style' => $style ), '', false ) . $extra |
| 83 | + ); |
| 84 | + $column++; |
| 85 | + } |
| 86 | + } |
| 87 | + |
| 88 | + $htmlOut .= Xml::closeElement( 'div' ); |
| 89 | + |
| 90 | + // Show bar graph |
| 91 | + $htmlOut .= Xml::openElement( 'table', |
| 92 | + array( |
| 93 | + 'cellpadding' => 0, |
| 94 | + 'cellspacing' => 0, |
| 95 | + 'border' => 0 |
| 96 | + ) |
| 97 | + ); |
| 98 | + $htmlOut .= Xml::openElement( 'tr' ); |
| 99 | + foreach( $columns as $column ) { |
| 100 | + $htmlOut .= $column; |
| 101 | + $htmlOut .= Xml::tags( 'td', array( 'valign' => 'bottom' ), |
| 102 | + Xml::element( 'div', array( 'style' => "width:4px;" ), '', false ) |
| 103 | + ); |
| 104 | + } |
| 105 | + $htmlOut .= Xml::closeElement( 'tr' ); |
| 106 | + $htmlOut .= Xml::closeElement( 'table' ); |
| 107 | + |
| 108 | + $wgOut->addHTML( $htmlOut ); |
| 109 | + } |
| 110 | + |
| 111 | + /* Query Functions */ |
| 112 | + |
| 113 | + public function getDailyTotals( $start, $end ) { |
| 114 | + global $egFundraiserStatisticsMinimum; |
| 115 | + global $egFundraiserStatisticsMaximum; |
| 116 | + |
| 117 | + // Get connection |
| 118 | + $dbr = efContributionReportingConnection(); |
| 119 | + |
| 120 | + // Select sums and dates of contributions grouped by day |
| 121 | + $res = $dbr->select( 'public_reporting', |
| 122 | + array( |
| 123 | + 'sum(converted_amount)', |
| 124 | + "FROM_UNIXTIME(received, '%Y-%m-%d')" |
| 125 | + ), |
| 126 | + array_merge( |
| 127 | + array( |
| 128 | + 'converted_amount >= ' . $egFundraiserStatisticsMinimum, |
| 129 | + 'converted_amount <= ' . $egFundraiserStatisticsMaximum |
| 130 | + ), |
| 131 | + $this->dateConds( $dbr, $start, $end ) |
| 132 | + ), |
| 133 | + __METHOD__, |
| 134 | + array( |
| 135 | + 'ORDER BY' => 'received', |
| 136 | + 'GROUP BY' => "FROM_UNIXTIME(received, '%Y-%m-%d')" |
| 137 | + ) |
| 138 | + ); |
| 139 | + |
| 140 | + // Build day/value array |
| 141 | + $totals = array(); |
| 142 | + while ( $row = $dbr->fetchRow( $res ) ) { |
| 143 | + $totals[] = $row; |
| 144 | + } |
| 145 | + |
| 146 | + // Return results |
| 147 | + return $totals; |
| 148 | + } |
| 149 | + |
| 150 | + protected function dateConds( $dbr, $start, $end ) { |
| 151 | + return |
| 152 | + array( |
| 153 | + 'received >= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $start ) ) ), |
| 154 | + 'received <= ' . $dbr->addQuotes( wfTimestamp( TS_UNIX, strtotime( $end ) + 24 * 60 * 60 ) ) |
| 155 | + ); |
| 156 | + } |
| 157 | +} |
Index: trunk/extensions/ContributionReporting/ContributionReporting.i18n.php |
— | — | @@ -49,6 +49,9 @@ |
50 | 50 | 'contribstats-max' => 'Maximum (USD)', |
51 | 51 | 'contribstats-percentage-ytd' => 'Percentage (YTD)', |
52 | 52 | 'contribstats-total-ytd' => 'Total (YTD)', |
| 53 | + |
| 54 | + // Fundraiser Statistics |
| 55 | + 'fundraiserstatistics' => 'Fundraiser Statistics', |
53 | 56 | ); |
54 | 57 | |
55 | 58 | /** Message documentation (Message documentation) |