Index: trunk/extensions/Contest/specials/SpecialContestant.php |
— | — | @@ -34,7 +34,7 @@ |
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
38 | | - $contestant = ContestContestant::s()->selectRow( null, array( 'id' => (int)$subPage ) ); |
| 38 | + $contestant = ContestContestant::s()->selectRow( 'id', array( 'id' => (int)$subPage ) ); |
39 | 39 | |
40 | 40 | if ( $contestant === false ) { |
41 | 41 | $this->getOutput()->redirect( SpecialPage::getTitleFor( 'Contests' )->getLocalURL() ); |
— | — | @@ -43,9 +43,10 @@ |
44 | 44 | if ( $this->getRequest()->wasPosted() |
45 | 45 | && $this->getUser()->matchEditToken( $this->getRequest()->getVal( 'wpEditToken' ) ) ) |
46 | 46 | { |
47 | | - $this->handleSubmission( $contestant ); |
| 47 | + $this->handleSubmission( $contestant->getId() ); |
48 | 48 | } |
49 | 49 | |
| 50 | + $contestant->loadFields(); |
50 | 51 | $this->showPage( $contestant ); |
51 | 52 | } |
52 | 53 | } |
— | — | @@ -56,17 +57,17 @@ |
57 | 58 | * |
58 | 59 | * @since 0.1 |
59 | 60 | * |
60 | | - * @param ContestContestant $contestant |
| 61 | + * @param integer $contestantId |
61 | 62 | * |
62 | 63 | * @return boolean Success indicator |
63 | 64 | */ |
64 | | - protected function handleSubmission( ContestContestant $contestant ) { |
| 65 | + protected function handleSubmission( $contestantId ) { |
65 | 66 | $success = true; |
66 | 67 | |
67 | 68 | if ( trim( $this->getRequest()->getText( 'new-comment-text' ) ) !== '' ) { |
68 | 69 | $comment = new ContestComment( array( |
69 | 70 | 'user_id' => $this->getUser()->getId(), |
70 | | - 'contestant_id' => $contestant->getId(), |
| 71 | + 'contestant_id' => $contestantId, |
71 | 72 | |
72 | 73 | 'text' => $this->getRequest()->getText( 'new-comment-text' ), |
73 | 74 | 'time' => wfTimestampNow() |
— | — | @@ -82,7 +83,7 @@ |
83 | 84 | if ( $success && !is_null( $this->getRequest()->getVal( 'contestant-rating' ) ) ) { |
84 | 85 | $attribs = array( |
85 | 86 | 'value' => $this->getRequest()->getInt( 'contestant-rating' ), |
86 | | - 'contestant_id' => $contestant->getId(), |
| 87 | + 'contestant_id' => $contestantId, |
87 | 88 | 'user_id' => $this->getUser()->getId() |
88 | 89 | ); |
89 | 90 | |
Index: trunk/extensions/Contest/includes/ContestDBObject.php |
— | — | @@ -43,6 +43,39 @@ |
44 | 44 | |
45 | 45 | $this->setFields( $fields ); |
46 | 46 | } |
| 47 | + |
| 48 | + /** |
| 49 | + * Load the specified fields from the database. |
| 50 | + * |
| 51 | + * @since 0.1 |
| 52 | + * |
| 53 | + * @param array|null $fields |
| 54 | + * @param boolean $override |
| 55 | + * |
| 56 | + * @return Success indicator |
| 57 | + */ |
| 58 | + public function loadFields( $fields = null, $override = true ) { |
| 59 | + if ( is_null( $this->getId() ) ) { |
| 60 | + return false; |
| 61 | + } |
| 62 | + |
| 63 | + if ( is_null( $fields ) ) { |
| 64 | + $fields = array_keys( $this->getFieldTypes() ); |
| 65 | + } |
| 66 | + |
| 67 | + $results = $this->rawSelect( |
| 68 | + $this->getPrefixedFields( $fields ), |
| 69 | + array( $this->getPrefixedField( 'id' ) => $this->getId() ), |
| 70 | + array( 'LIMIT' => 1 ) |
| 71 | + ); |
| 72 | + |
| 73 | + foreach ( $results as $result ) { |
| 74 | + $this->setFields( $this->getFieldsFromDBResult( $result ), $override ); |
| 75 | + return true; |
| 76 | + } |
| 77 | + |
| 78 | + return false; |
| 79 | + } |
47 | 80 | |
48 | 81 | /** |
49 | 82 | * Returns the name of the database table objects of this type are stored in. |
— | — | @@ -472,15 +505,17 @@ |
473 | 506 | } |
474 | 507 | |
475 | 508 | /** |
476 | | - * Get a new instance of the class from a database result. |
| 509 | + * Get an array with fields from a database result, |
| 510 | + * that can be fed directly to the constructor or |
| 511 | + * to setFields. |
477 | 512 | * |
478 | 513 | * @since 0.1 |
479 | 514 | * |
480 | 515 | * @param object $result |
481 | 516 | * |
482 | | - * @return ContestDBObject |
| 517 | + * @return array |
483 | 518 | */ |
484 | | - public function newFromDBResult( $result ) { |
| 519 | + protected function getFieldsFromDBResult( $result ) { |
485 | 520 | $result = (array)$result; |
486 | 521 | $data = array(); |
487 | 522 | $idFieldLength = strlen( $this->getFieldPrefix() ); |
— | — | @@ -488,9 +523,22 @@ |
489 | 524 | foreach ( $result as $name => $value ) { |
490 | 525 | $data[substr( $name, $idFieldLength )] = $value; |
491 | 526 | } |
492 | | - |
493 | | - return $this->newFromArray( $data ); |
| 527 | + |
| 528 | + return $data; |
494 | 529 | } |
| 530 | + |
| 531 | + /** |
| 532 | + * Get a new instance of the class from a database result. |
| 533 | + * |
| 534 | + * @since 0.1 |
| 535 | + * |
| 536 | + * @param object $result |
| 537 | + * |
| 538 | + * @return ContestDBObject |
| 539 | + */ |
| 540 | + public function newFromDBResult( $result ) { |
| 541 | + return $this->newFromArray( $this->getFieldsFromDBResult( $result ) ); |
| 542 | + } |
495 | 543 | |
496 | 544 | /** |
497 | 545 | * Removes the object from the database. |
Index: trunk/extensions/Contest/includes/Contest.class.php |
— | — | @@ -472,10 +472,9 @@ |
473 | 473 | * |
474 | 474 | **/ |
475 | 475 | public function getStatus() { |
| 476 | + $dbStatus = $this->getField( 'status' ); |
476 | 477 | |
477 | | - $dbStatus = $this->getField('status'); |
478 | | - |
479 | | - if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) { |
| 478 | + if ( $dbStatus === self::STATUS_ACTIVE && $this->getTimeLeft() <= 0 ) { |
480 | 479 | return self::STATUS_EXPIRED; |
481 | 480 | } else { |
482 | 481 | return $dbStatus; |