r98711 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r98710‎ | r98711 | r98712 >
Date:20:19, 2 October 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
added submission count stuff
Modified paths:
  • /trunk/extensions/Contest/Contest.i18n.php (modified) (history)
  • /trunk/extensions/Contest/includes/Contest.class.php (modified) (history)
  • /trunk/extensions/Contest/includes/ContestContestant.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSignup.php (modified) (history)
  • /trunk/extensions/Contest/specials/SpecialContestSubmission.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Contest/specials/SpecialContestSubmission.php
@@ -67,9 +67,6 @@
6868 case Contest::STATUS_ACTIVE:
6969 $this->handleEnabledPage( $contest );
7070 break;
71 - case Contest::STATUS_DRAFT:
72 - // TODO
73 - break;
7471 case Contest::STATUS_FINISHED:
7572 $this->showWarning( 'contest-submission-finished' );
7673 $out->addHTML( '<br /><br /><br /><br />' );
Index: trunk/extensions/Contest/specials/SpecialContestSignup.php
@@ -99,7 +99,9 @@
100100 $this->showEnabledPage( $contest, $challangeId );
101101 break;
102102 case Contest::STATUS_DRAFT:
103 - // TODO
 103+ $this->showWarning( 'contest-signup-draft' );
 104+ $out->addHTML( '<br /><br /><br /><br />' );
 105+ $out->returnToMain();
104106 break;
105107 case Contest::STATUS_FINISHED:
106108 $this->showWarning( 'contest-signup-finished' );
Index: trunk/extensions/Contest/includes/Contest.class.php
@@ -312,4 +312,38 @@
313313 return $success;
314314 }
315315
 316+ /**
 317+ * Add an amount (can be negative) to the total submissions for this contest.
 318+ *
 319+ * @since 0.1
 320+ *
 321+ * @param integer $amount
 322+ *
 323+ * @return boolean Success indicator
 324+ */
 325+ public function addToSubmissionCount( $amount ) {
 326+ if ( $amount == 0 ) {
 327+ return true;
 328+ }
 329+
 330+ $absoluteAmount = abs( $amount );
 331+ $isNegative = $amount < 0;
 332+
 333+ $dbw = wfGetDB( DB_MASTER );
 334+
 335+ $countField = $this->getPrefixedField( 'submission_count' );
 336+
 337+ $success = $dbw->update(
 338+ $this->getDBTable(),
 339+ array( "$countField=$countField" . ( $isNegative ? '-' : '+' ) . $absoluteAmount ),
 340+ array( $this->getPrefixedField( 'id' ) => $this->getId() )
 341+ );
 342+
 343+ if ( $success && $this->hasField( 'submission_count' ) ) {
 344+ $this->setField( 'submission_count', $this->getField( 'submission_count' ) + $amount );
 345+ }
 346+
 347+ return $success;
 348+ }
 349+
316350 }
\ No newline at end of file
Index: trunk/extensions/Contest/includes/ContestContestant.php
@@ -124,14 +124,22 @@
125125 *
126126 * @since 0.1
127127 *
 128+ * @param array|null $fields The fields to load, null for all fields.
 129+ *
128130 * @return Contest
129131 */
130 - public function getContest() {
131 - if ( is_null( $this->contest ) ) {
132 - $this->contest = Contest::s()->selectRow( null, array( 'id' => $this->getField( 'contest_id' ) ) );
 132+ public function getContest( array $fields = null ) {
 133+ if ( !is_null( $this->contest ) ) {
 134+ return $this->contest;
133135 }
134136
135 - return $this->contest;
 137+ $contest = Contest::s()->selectRow( $fields, array( 'id' => $this->getField( 'contest_id' ) ) );
 138+
 139+ if ( is_null( $this->contest ) && is_null( $fields ) ) {
 140+ $this->contest = $contest;
 141+ }
 142+
 143+ return $contest;
136144 }
137145
138146 /**
@@ -420,5 +428,18 @@
421429 );
422430 }
423431
 432+ /**
 433+ * (non-PHPdoc)
 434+ * @see ContestDBObject::insertIntoDB()
 435+ */
 436+ protected function insertIntoDB() {
 437+ $success = parent::insertIntoDB();
 438+
 439+ if ( $success ) {
 440+ $this->getContest( array( 'id' ) )->addToSubmissionCount( 1 );
 441+ }
 442+
 443+ return $success;
 444+ }
424445
425446 }
Index: trunk/extensions/Contest/Contest.i18n.php
@@ -109,6 +109,7 @@
110110 'contest-signup-readrules' => 'I confirm that I have read, and agree to, [[$1|the contest rules]]',
111111 'contest-signup-challange' => 'What challenge do you want to take on?',
112112 'contest-signup-finished' => 'This contest has ended.',
 113+ 'contest-signup-draft' => 'This contest has not started yet. Please be patient.',
113114 'contest-signup-country' => 'Your country',
114115
115116 // Special:ContestSubmission

Status & tagging log