Index: trunk/extensions/Contest/includes/ContestComment.php |
— | — | @@ -0,0 +1,103 @@ |
| 2 | +<?php |
| 3 | + |
| 4 | +/** |
| 5 | + * Class representing a single contest comment. |
| 6 | + * Comments can be made by judges on submissions of contestants. |
| 7 | + * |
| 8 | + * @since 0.1 |
| 9 | + * |
| 10 | + * @file ContestComment.php |
| 11 | + * @ingroup Contest |
| 12 | + * |
| 13 | + * @licence GNU GPL v3 or later |
| 14 | + * @author Jeroen De Dauw < jeroendedauw@gmail.com > |
| 15 | + */ |
| 16 | +class ContestComment 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_comments'; |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * @see parent::getFieldTypes |
| 67 | + * |
| 68 | + * @since 0.1 |
| 69 | + * |
| 70 | + * @return string |
| 71 | + */ |
| 72 | + protected function getFieldPrefix() { |
| 73 | + return 'comment_'; |
| 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 | + 'contestant_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 | +} |