Index: trunk/extensions/Contest/includes/Contest.class.php |
— | — | @@ -1,11 +1,11 @@ |
2 | 2 | <?php |
3 | 3 | |
4 | 4 | /** |
5 | | - * Abstract base class for representing objects that are stored in some DB table. |
6 | 5 | * |
| 6 | + * |
7 | 7 | * @since 0.1 |
8 | 8 | * |
9 | | - * @file ContestDBObject.php |
| 9 | + * @file Contest.class.php |
10 | 10 | * @ingroup Contest |
11 | 11 | * |
12 | 12 | * @licence GNU GPL v3 or later |
— | — | @@ -39,6 +39,8 @@ |
40 | 40 | |
41 | 41 | /** |
42 | 42 | * Get a new instance of the class from an array. |
| 43 | + * This method ought to be in the basic class and |
| 44 | + * return a new static(), but this requires LSB/PHP>=5.3. |
43 | 45 | * |
44 | 46 | * @since 0.1 |
45 | 47 | * |
— | — | @@ -150,9 +152,10 @@ |
151 | 153 | * @return array of ContestChallange |
152 | 154 | */ |
153 | 155 | public function getChallanges() { |
154 | | - // TODO |
155 | | - |
156 | | - return array(); |
| 156 | + return ContestChallange::s()->select( |
| 157 | + null, |
| 158 | + array( 'contest_id' => $this->getId() ) |
| 159 | + ); |
157 | 160 | } |
158 | 161 | |
159 | 162 | } |
\ No newline at end of file |
Index: trunk/extensions/Contest/includes/ContestChallange.php |
— | — | @@ -0,0 +1,103 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Contest challange object. |
| 6 | + * Each contest (can) has a list of associated challanges. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file ContestChallange.php |
| 11 | + * @ingroup Contest |
| 12 | + * |
| 13 | + * @licence GNU GPL v3 or later |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ContestChallange extends ContestDBObject { |
| 17 | + |
| 18 | + /** |
| 19 | + * Method to get an instance so methods that ought to be static, |
| 20 | + * but can't be due to PHP 5.2 not having LSB, can be called on |
| 21 | + * it. This also allows easy identifying of code that needs to |
| 22 | + * be changed once PHP 5.3 becomes an acceptable requirement. |
| 23 | + * |
| 24 | + * @since 0.1 |
| 25 | + * |
| 26 | + * @return ContestDBObject |
| 27 | + */ |
| 28 | + public static function s() { |
| 29 | + static $instance = false; |
| 30 | + |
| 31 | + if ( $instance === false ) { |
| 32 | + $instance = new self( array() ); |
| 33 | + } |
| 34 | + |
| 35 | + return $instance; |
| 36 | + } |
| 37 | + |
| 38 | + /** |
| 39 | + * Get a new instance of the class from an array. |
| 40 | + * This method ought to be in the basic class and |
| 41 | + * return a new static(), but this requires LSB/PHP>=5.3. |
| 42 | + * |
| 43 | + * @since 0.1 |
| 44 | + * |
| 45 | + * @param array $data |
| 46 | + * @param boolean $loadDefaults |
| 47 | + * |
| 48 | + * @return ContestDBObject |
| 49 | + */ |
| 50 | + public function newFromArray( array $data, $loadDefaults = false ) { |
| 51 | + return new self( $data, $loadDefaults ); |
| 52 | + } |
| 53 | + |
| 54 | + /** |
| 55 | + * @see parent::getFieldTypes |
| 56 | + * |
| 57 | + * @since 0.1 |
| 58 | + * |
| 59 | + * @return string |
| 60 | + */ |
| 61 | + public function getDBTable() { |
| 62 | + return 'contest_challanges'; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @see parent::getFieldTypes |
| 67 | + * |
| 68 | + * @since 0.1 |
| 69 | + * |
| 70 | + * @return string |
| 71 | + */ |
| 72 | + protected function getFieldPrefix() { |
| 73 | + return 'challange_'; |
| 74 | + } |
| 75 | + |
| 76 | + /** |
| 77 | + * @see parent::getFieldTypes |
| 78 | + * |
| 79 | + * @since 0.1 |
| 80 | + * |
| 81 | + * @return array |
| 82 | + */ |
| 83 | + protected function getFieldTypes() { |
| 84 | + return array( |
| 85 | + 'id' => 'id', |
| 86 | + 'contest_id' => 'id', |
| 87 | + 'text' => 'str', |
| 88 | + ); |
| 89 | + } |
| 90 | + |
| 91 | + /** |
| 92 | + * @see parent::getDefaults |
| 93 | + * |
| 94 | + * @since 0.1 |
| 95 | + * |
| 96 | + * @return array |
| 97 | + */ |
| 98 | + public function getDefaults() { |
| 99 | + return array( |
| 100 | + 'text' => '', |
| 101 | + ); |
| 102 | + } |
| 103 | + |
| 104 | +} |
Property changes on: trunk/extensions/Contest/includes/ContestChallange.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 105 | + native |
Index: trunk/extensions/Contest/Contest.php |
— | — | @@ -52,6 +52,9 @@ |
53 | 53 | $wgAutoloadClasses['ApiDeleteContest'] = dirname( __FILE__ ) . '/api/ApiDeleteContest.php'; |
54 | 54 | |
55 | 55 | $wgAutoloadClasses['Contest'] = dirname( __FILE__ ) . '/includes/Contest.class.php'; |
| 56 | +$wgAutoloadClasses['ContestChallange'] = dirname( __FILE__ ) . '/includes/ContestChallange.php'; |
| 57 | +$wgAutoloadClasses['ContestComment'] = dirname( __FILE__ ) . '/includes/ContestComment.php'; |
| 58 | +$wgAutoloadClasses['ContestContestant'] = dirname( __FILE__ ) . '/includes/ContestContestant.php'; |
56 | 59 | $wgAutoloadClasses['ContestDBObject'] = dirname( __FILE__ ) . '/includes/ContestDBObject.php'; |
57 | 60 | |
58 | 61 | $wgAutoloadClasses['SpecialContest'] = dirname( __FILE__ ) . '/specials/SpecialContest.php'; |