Index: trunk/extensions/Contest/Contest.i18n.php |
— | — | @@ -180,6 +180,11 @@ |
181 | 181 | // Emails |
182 | 182 | 'contest-email-signup-title' => 'Thanks for joining the challenge!', |
183 | 183 | 'contest-email-reminder-title' => 'Only $1 {{PLURAL:$1|day|days}} until the end of the challenge!', |
| 184 | + |
| 185 | + // Special:MyContests |
| 186 | + 'contest-mycontests-no-contests' => 'You are not participating in any contest.', |
| 187 | + 'contest-mycontests-active-header' => 'Running contests', |
| 188 | + 'contest-mycontests-finished-header' => 'Passed contests', |
184 | 189 | ); |
185 | 190 | |
186 | 191 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Contest/Contest.alias.php |
— | — | @@ -23,4 +23,5 @@ |
24 | 24 | 'ContestSubmission' => array( 'ContestSubmission' ), |
25 | 25 | 'ContestWelcome' => array( 'ContestWelcome' ), |
26 | 26 | 'EditContest' => array( 'EditContest' ), |
| 27 | + 'MyContests' => array( 'MyContests' ), |
27 | 28 | ); |
Index: trunk/extensions/Contest/specials/SpecialMyContests.php |
— | — | @@ -0,0 +1,85 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * List of contests for a user. |
| 6 | + * |
| 7 | + * @since 0.1 |
| 8 | + * |
| 9 | + * @file SpecialMyContests.php |
| 10 | + * @ingroup Contest |
| 11 | + * |
| 12 | + * @licence GNU GPL v3 or later |
| 13 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 14 | + */ |
| 15 | +class SpecialMyContests extends SpecialContestPage { |
| 16 | + |
| 17 | + /** |
| 18 | + * Constructor. |
| 19 | + * |
| 20 | + * @since 0.1 |
| 21 | + */ |
| 22 | + public function __construct() { |
| 23 | + parent::__construct( 'MyContests', 'contestparticipant' ); |
| 24 | + } |
| 25 | + |
| 26 | + /** |
| 27 | + * Main method. |
| 28 | + * |
| 29 | + * @since 0.1 |
| 30 | + * |
| 31 | + * @param string $arg |
| 32 | + */ |
| 33 | + public function execute( $subPage ) { |
| 34 | + $subPage = str_replace( '_', ' ', $subPage ); |
| 35 | + |
| 36 | + if ( !parent::execute( $subPage ) ) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + $contestants = ContestContestant::s()->select( |
| 41 | + array( 'id', 'contest_id', 'challenge_id' ), |
| 42 | + array( 'user_id' => $this->getUser()->getId() ) |
| 43 | + ); |
| 44 | + |
| 45 | + $contestantCount = count( $contestants ); |
| 46 | + |
| 47 | + if ( $contestantCount == 0 ) { |
| 48 | + $this->getOutput()->addWikiMsg( 'contest-mycontests-no-contests' ); |
| 49 | + } |
| 50 | + else if ( $contestantCount == 1 ) { |
| 51 | + $contest = $contestants[0]->getContest( array( 'status', 'name' ) ); |
| 52 | + |
| 53 | + if ( $contest->getField( 'status' ) == Contest::STATUS_ACTIVE ) { |
| 54 | + $this->getOutput()->redirect( SpecialPage::getTitleFor( 'ContestSubmission', $contest->getField( 'name' ) )->getLocalURL() ); |
| 55 | + } |
| 56 | + else { |
| 57 | + $this->displayContestsTable( $contestants ); |
| 58 | + } |
| 59 | + } |
| 60 | + else { |
| 61 | + $this->displayContestsTable( $contestants ); |
| 62 | + } |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Displays a list of contests the user participates or participated in, |
| 67 | + * together with their user specific choices such as the contest challenge. |
| 68 | + * |
| 69 | + * @since 0.1 |
| 70 | + * |
| 71 | + * @param array $contestants |
| 72 | + */ |
| 73 | + protected function displayContestsTable( array /* of ContestContestant */ $contestants ) { |
| 74 | + $user = $this->getUser(); |
| 75 | + $out = $this->getOutput(); |
| 76 | + |
| 77 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-active-header' ) ) ); |
| 78 | + |
| 79 | + // TODO |
| 80 | + |
| 81 | + $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-mycontests-finished-header' ) ) ); |
| 82 | + |
| 83 | + // TODO |
| 84 | + } |
| 85 | + |
| 86 | +} |
Property changes on: trunk/extensions/Contest/specials/SpecialMyContests.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 87 | + native |
Index: trunk/extensions/Contest/Contest.php |
— | — | @@ -73,6 +73,7 @@ |
74 | 74 | $wgAutoloadClasses['SpecialContestSubmission'] = dirname( __FILE__ ) . '/specials/SpecialContestSubmission.php'; |
75 | 75 | $wgAutoloadClasses['SpecialContestWelcome'] = dirname( __FILE__ ) . '/specials/SpecialContestWelcome.php'; |
76 | 76 | $wgAutoloadClasses['SpecialEditContest'] = dirname( __FILE__ ) . '/specials/SpecialEditContest.php'; |
| 77 | +$wgAutoloadClasses['SpecialMyContests'] = dirname( __FILE__ ) . '/specials/SpecialMyContests.php'; |
77 | 78 | |
78 | 79 | // Special pages |
79 | 80 | $wgSpecialPages['Contest'] = 'SpecialContest'; |
— | — | @@ -82,6 +83,7 @@ |
83 | 84 | $wgSpecialPages['ContestSubmission'] = 'SpecialContestSubmission'; |
84 | 85 | $wgSpecialPages['ContestWelcome'] = 'SpecialContestWelcome'; |
85 | 86 | $wgSpecialPages['EditContest'] = 'SpecialEditContest'; |
| 87 | +$wgSpecialPages['MyContests'] = 'SpecialMyContests'; |
86 | 88 | |
87 | 89 | $wgSpecialPageGroups['Contest'] = 'other'; |
88 | 90 | $wgSpecialPageGroups['Contestant'] = 'other'; |
— | — | @@ -90,6 +92,7 @@ |
91 | 93 | $wgSpecialPageGroups['ContestSubmission'] = 'other'; |
92 | 94 | $wgSpecialPageGroups['ContestWelcome'] = 'other'; |
93 | 95 | $wgSpecialPageGroups['EditContest'] = 'other'; |
| 96 | +$wgSpecialPageGroups['MyContests'] = 'other'; |
94 | 97 | |
95 | 98 | // API |
96 | 99 | $wgAPIModules['deletecontest'] = 'ApiDeleteContest'; |
Index: trunk/extensions/Contest/includes/ContestDBObject.php |
— | — | @@ -543,7 +543,7 @@ |
544 | 544 | * |
545 | 545 | * @since 0.1 |
546 | 546 | * |
547 | | - * @param array|null $fields |
| 547 | + * @param array|string|null $fields |
548 | 548 | * @param array $conditions |
549 | 549 | * @param array $options |
550 | 550 | * |
— | — | @@ -575,7 +575,7 @@ |
576 | 576 | * |
577 | 577 | * @since 0.1 |
578 | 578 | * |
579 | | - * @param array|null $fields |
| 579 | + * @param array|string|null $fields |
580 | 580 | * @param array $conditions |
581 | 581 | * @param array $options |
582 | 582 | * |
Index: trunk/extensions/Contest/includes/ContestContestant.php |
— | — | @@ -144,11 +144,11 @@ |
145 | 145 | * |
146 | 146 | * @since 0.1 |
147 | 147 | * |
148 | | - * @param array|null $fields The fields to load, null for all fields. |
| 148 | + * @param array|string|null $fields The fields to load, null for all fields. |
149 | 149 | * |
150 | 150 | * @return Contest |
151 | 151 | */ |
152 | | - public function getContest( array $fields = null ) { |
| 152 | + public function getContest( $fields = null ) { |
153 | 153 | if ( !is_null( $this->contest ) ) { |
154 | 154 | return $this->contest; |
155 | 155 | } |