r103884 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r103883‎ | r103884 | r103885 >
Date:02:22, 22 November 2011
Author:kaldari
Status:ok (Comments)
Tags:fundraising 
Comment:
adding daily total reporting system
Modified paths:
  • /trunk/extensions/ContributionReporting/ContributionReporting.php (modified) (history)
  • /trunk/extensions/ContributionReporting/DailyTotal_body.php (added) (history)

Diff [purge]

Index: trunk/extensions/ContributionReporting/ContributionReporting.php
@@ -41,12 +41,14 @@
4242 $wgAutoloadClasses['SpecialContributionStatistics'] = $dir . 'ContributionStatistics_body.php';
4343 $wgAutoloadClasses['SpecialFundraiserStatistics'] = $dir . 'FundraiserStatistics_body.php';
4444 $wgAutoloadClasses['SpecialContributionTrackingStatistics'] = $dir . 'ContributionTrackingStatistics_body.php';
 45+$wgAutoloadClasses['SpecialDailyTotal'] = $dir . 'DailyTotal_body.php';
4546
4647 $wgSpecialPages['ContributionHistory'] = 'ContributionHistory';
4748 $wgSpecialPages['ContributionTotal'] = 'ContributionTotal';
4849 $wgSpecialPages['ContributionStatistics'] = 'SpecialContributionStatistics';
4950 $wgSpecialPages['FundraiserStatistics'] = 'SpecialFundraiserStatistics';
5051 $wgSpecialPages['ContributionTrackingStatistics'] = 'SpecialContributionTrackingStatistics';
 52+$wgSpecialPages['DailyTotal'] = 'SpecialDailyTotal';
5153 $wgSpecialPageGroups['ContributionHistory'] = 'contribution';
5254 $wgSpecialPageGroups['ContributionTotal'] = 'contribution';
5355 $wgSpecialPageGroups['ContributionStatistics'] = 'contribution';
Index: trunk/extensions/ContributionReporting/DailyTotal_body.php
@@ -0,0 +1,87 @@
 2+<?php
 3+/**
 4+ * Special Page for Contribution statistics extension
 5+ *
 6+ * @file
 7+ * @ingroup Extensions
 8+ */
 9+
 10+class SpecialDailyTotal extends IncludableSpecialPage {
 11+
 12+ protected $sharedMaxAge = 300; // Cache for 5 minutes on the server side
 13+ protected $maxAge = 300; // Cache for 5 minutes on the client side
 14+ public $timezone;
 15+
 16+ /* Functions */
 17+
 18+ public function __construct() {
 19+ parent::__construct( 'DailyTotal' );
 20+ }
 21+
 22+ public function execute( $sub ) {
 23+ global $wgRequest, $wgOut;
 24+
 25+ $this->timezone = $wgRequest->getVal( 'timezone', '0' );
 26+ // Make sure it's a number and reasonable
 27+ if ( is_nan( $this->timezone ) || abs( $this->timezone ) > 100 ) {
 28+ $this->timezone = 0;
 29+ }
 30+
 31+ /* Setup */
 32+ $wgOut->disable();
 33+ $this->sendHeaders();
 34+
 35+ $start = date( 'Y-m-d' ); // Get the current date
 36+ $total = $this->query( $start );
 37+
 38+ $content = "wgFundraisingDailyTotal = $total;";
 39+ echo $content;
 40+ }
 41+
 42+ /* Private Functions */
 43+
 44+ private function query( $start ) {
 45+ global $wgMemc, $egFundraiserStatisticsMinimum, $egFundraiserStatisticsMaximum, $egFundraiserStatisticsCacheTimeout;
 46+
 47+ $key = wfMemcKey( 'fundraiserstatistics', $this->timezone, $start );
 48+ $cache = $wgMemc->get( $key );
 49+ if ( $cache != false && $cache != -1 ) {
 50+ return $cache;
 51+ }
 52+ $timeShift = $this->timezone * 60 * 60;
 53+ // Use database
 54+ //$dbr = efContributionReportingConnection();
 55+ $dbr = wfGetDB( DB_MASTER );
 56+ $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 ) ),
 59+ 'converted_amount >= ' . $egFundraiserStatisticsMinimum,
 60+ 'converted_amount <= ' . $egFundraiserStatisticsMaximum
 61+ );
 62+ $select = $dbr->select( 'public_reporting',
 63+ array(
 64+ "DATE_FORMAT(FROM_UNIXTIME(received),'%Y-%m-%d')",
 65+ 'sum(converted_amount)'
 66+ ),
 67+ $conditions,
 68+ __METHOD__,
 69+ array(
 70+ 'ORDER BY' => 'received'
 71+ )
 72+ );
 73+ $row = $dbr->fetchRow( $select );
 74+ $total = $row['sum(converted_amount)'];
 75+
 76+ if ( $total ) {
 77+ $wgMemc->set( $key, $total, $egFundraiserStatisticsCacheTimeout );
 78+ return $total;
 79+ }
 80+ return null;
 81+ }
 82+
 83+ private function sendHeaders() {
 84+ global $wgJsMimeType;
 85+ header( "Content-type: $wgJsMimeType; charset=utf-8" );
 86+ header( "Cache-Control: public, s-maxage=$this->sharedMaxAge, max-age=$this->maxAge" );
 87+ }
 88+}

Follow-up revisions

RevisionCommit summaryAuthorDate
r103947follow-up to r103884, daily and yearly totalskaldari19:37, 22 November 2011
r103998MFT r103884, r103947, r103959, r103967, r103991, r103996awjrichards01:24, 23 November 2011
r104000MFT r103884, r103947, r103959, r103967, r103991, r103996awjrichards01:51, 23 November 2011

Comments

#Comment by Jpostlethwaite (talk | contribs)   04:32, 22 November 2011

Please add doc blocks to methods :)


	/**
	 * Send the document headers
	 */
	private function sendHeaders() {

Status & tagging log