Index: trunk/extensions/Contest/Contest.i18n.php |
— | — | @@ -169,6 +169,8 @@ |
170 | 170 | 'contest-contestant-submit' => 'Save changes', |
171 | 171 | 'contest-contestant-comment-by' => 'Comment by $1', |
172 | 172 | 'contest-contestant-rate' => 'Rate this contestant', |
| 173 | + 'contest-contestant-not-voted' => 'You have not voted on this participant yet.', |
| 174 | + 'contest-contestant-voted' => 'Your current vote is $1.', |
173 | 175 | ); |
174 | 176 | |
175 | 177 | /** Message documentation (Message documentation) |
Index: trunk/extensions/Contest/specials/SpecialContestant.php |
— | — | @@ -78,8 +78,19 @@ |
79 | 79 | } |
80 | 80 | } |
81 | 81 | |
82 | | - if ( $success ) { |
83 | | - // TODO: rating shizzle |
| 82 | + if ( $success && !is_null( $this->getRequest()->getVal( 'contestant-rating' ) ) ) { |
| 83 | + $attribs = array( |
| 84 | + 'value' => $this->getRequest()->getInt( 'contestant-rating' ), |
| 85 | + 'contestant_id' => $contestant->getId(), |
| 86 | + 'user_id' => $this->getUser()->getId() |
| 87 | + ); |
| 88 | + |
| 89 | + if ( !is_null( $this->getRequest()->getVal( 'contestant-vote-id' ) ) ) { |
| 90 | + $attribs['id'] = $this->getRequest()->getInt( 'contestant-vote-id' ); |
| 91 | + } |
| 92 | + |
| 93 | + $vote = new ContestVote( $attribs ); |
| 94 | + $success = $vote->writeToDB() && $success; |
84 | 95 | } |
85 | 96 | |
86 | 97 | return $success; |
— | — | @@ -204,7 +215,51 @@ |
205 | 216 | |
206 | 217 | $out->addHTML( Html::element( 'h2', array(), wfMsg( 'contest-contestant-rate' ) ) ); |
207 | 218 | |
| 219 | + $vote = ContestVote::s()->selectRow( |
| 220 | + array( 'value', 'id' ), |
| 221 | + array( 'user_id' => $this->getUser()->getId(), 'contestant_id' => $contestant->getId() ) |
| 222 | + ); |
208 | 223 | |
| 224 | + if ( $vote === false ) { |
| 225 | + $message = wfMsg( 'contest-contestant-not-voted' ); |
| 226 | + } |
| 227 | + else { |
| 228 | + $message = wfMsgExt( |
| 229 | + 'contest-contestant-voted', |
| 230 | + 'parsemag', |
| 231 | + $this->getLang()->formatNum( $vote->getField( 'value' ) ) |
| 232 | + ); |
| 233 | + |
| 234 | + $out->addHTML( Html::hidden( 'contestant-vote-id', $vote->getId() ) ); |
| 235 | + } |
| 236 | + |
| 237 | + $out->addHTML( Html::element( 'p', array(), $message ) ); |
| 238 | + |
| 239 | + foreach ( ContestSettings::get( 'votevalues' ) as $value ) { |
| 240 | + $attribs = array( |
| 241 | + 'type' => 'radio', |
| 242 | + 'value' => $value, |
| 243 | + 'name' => 'contestant-rating', |
| 244 | + 'id' => 'contestant-rating-' . $value |
| 245 | + ); |
| 246 | + |
| 247 | + if ( $vote !== false && $value == $vote->getField( 'value' ) ) { |
| 248 | + $attribs['checked'] = 'checked'; |
| 249 | + } |
| 250 | + |
| 251 | + $out->addHTML( |
| 252 | + Html::element( |
| 253 | + 'input', |
| 254 | + $attribs |
| 255 | + ) . |
| 256 | + Html::element( |
| 257 | + 'label', |
| 258 | + array( 'for' => 'contestant-rating-' . $value ), |
| 259 | + $this->getLang()->formatNum( $value ) |
| 260 | + ) |
| 261 | + ); |
| 262 | + } |
| 263 | + |
209 | 264 | } |
210 | 265 | |
211 | 266 | /** |