Index: trunk/extensions/Contest/includes/Contest.class.php |
— | — | @@ -13,14 +13,39 @@ |
14 | 14 | */ |
15 | 15 | class Contest extends ContestDBObject { |
16 | 16 | |
| 17 | + // Constants representing the states a contest can have. |
17 | 18 | const STATUS_DRAFT = 0; |
18 | 19 | const STATUS_ACTIVE = 1; |
19 | 20 | const STATUS_FINISHED = 2; |
20 | 21 | |
| 22 | + /** |
| 23 | + * List of challanges for this contest. |
| 24 | + * @see loadChallanges, setChallanges and writeChallangesToDB |
| 25 | + * |
| 26 | + * @since 0.1 |
| 27 | + * @var array of ContestChallange |
| 28 | + */ |
21 | 29 | protected $challanges = null; |
| 30 | + |
| 31 | + /** |
| 32 | + * List of contestants for this contest. |
| 33 | + * @see loadContestants, setContestants and writeContestantsToDB |
| 34 | + * |
| 35 | + * @since 0.1 |
| 36 | + * @var array of ContestContestant |
| 37 | + */ |
22 | 38 | protected $contestants = null; |
23 | 39 | |
24 | 40 | /** |
| 41 | + * Indicates if the contest was set from non-finished to finished. |
| 42 | + * This is used to take further action on save of the object. |
| 43 | + * |
| 44 | + * @since 0.1 |
| 45 | + * @var boolean |
| 46 | + */ |
| 47 | + protected $wasSetToFinished = false; |
| 48 | + |
| 49 | + /** |
25 | 50 | * Method to get an instance so methods that ought to be static, |
26 | 51 | * but can't be due to PHP 5.2 not having LSB, can be called on |
27 | 52 | * it. This also allows easy identifying of code that needs to |
— | — | @@ -240,6 +265,21 @@ |
241 | 266 | } |
242 | 267 | |
243 | 268 | /** |
| 269 | + * (non-PHPdoc) |
| 270 | + * @see ContestDBObject::writeToDB() |
| 271 | + */ |
| 272 | + public function writeToDB() { |
| 273 | + $success = parent::writeToDB(); |
| 274 | + |
| 275 | + if ( $success && $this->wasSetToFinished ) { |
| 276 | + $this->doFinishActions(); |
| 277 | + $this->wasSetToFinished = false; |
| 278 | + } |
| 279 | + |
| 280 | + return $success; |
| 281 | + } |
| 282 | + |
| 283 | + /** |
244 | 284 | * Write the contest and all set challanges and participants to the database. |
245 | 285 | * |
246 | 286 | * @since 0.1 |
— | — | @@ -247,8 +287,8 @@ |
248 | 288 | * @return boolean Success indicator |
249 | 289 | */ |
250 | 290 | public function writeAllToDB() { |
251 | | - $success = parent::writeToDB(); |
252 | | - |
| 291 | + $success = self::writeToDB(); |
| 292 | + |
253 | 293 | if ( $success ) { |
254 | 294 | $success = $this->writeChallangesToDB(); |
255 | 295 | } |
— | — | @@ -354,4 +394,24 @@ |
355 | 395 | return $success; |
356 | 396 | } |
357 | 397 | |
| 398 | + /** |
| 399 | + * (non-PHPdoc) |
| 400 | + * @see ContestDBObject::setField() |
| 401 | + */ |
| 402 | + public function setField( $name, $value ) { |
| 403 | + if ( $name == 'status' && $value == self::STATUS_FINISHED |
| 404 | + && $this->hasField( $name ) && $this->getField( $name ) != self::STATUS_FINISHED ) { |
| 405 | + $this->wasSetToFinished = true; |
| 406 | + } |
| 407 | + } |
| 408 | + |
| 409 | + /** |
| 410 | + * Do all actions that need to be done on contest finish. |
| 411 | + * |
| 412 | + * @since 0.1 |
| 413 | + */ |
| 414 | + public function doFinishActions() { |
| 415 | + // TODO |
| 416 | + } |
| 417 | + |
358 | 418 | } |