Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -46,7 +46,7 @@ |
47 | 47 | } |
48 | 48 | |
49 | 49 | if ( $survey === false ) { |
50 | | - $survey = new Survey( null, $subPage ); |
| 50 | + $survey = new Survey( array( 'name' => $subPage ) ); |
51 | 51 | } |
52 | 52 | |
53 | 53 | $this->showSurvey( $survey ); |
— | — | @@ -74,8 +74,8 @@ |
75 | 75 | $survey = Survey::newFromId( $wgRequest->getInt( 'survey-id' ), null, false ); |
76 | 76 | } |
77 | 77 | |
78 | | - $survey->setName( $wgRequest->getText( 'survey-name' ) ); |
79 | | - $survey->setEnabled( $wgRequest->getCheck( 'survey-enabled' ) ); |
| 78 | + $survey->setField( 'name', $wgRequest->getText( 'survey-name' ) ); |
| 79 | + $survey->setField( 'enabled', $wgRequest->getCheck( 'survey-enabled' ) ); |
80 | 80 | |
81 | 81 | $survey->setQuestions( $this->getSubmittedQuestions() ); |
82 | 82 | |
— | — | @@ -127,16 +127,16 @@ |
128 | 128 | $questionId = "new-$questionId"; |
129 | 129 | } |
130 | 130 | else { |
131 | | - $questionId = $questionId; |
| 131 | + $questionDbId = $questionId; |
132 | 132 | } |
133 | 133 | |
134 | | - $question = new SurveyQuestion( |
135 | | - $questionDbId, |
136 | | - 0, |
137 | | - $wgRequest->getText( "survey-question-text-$questionId" ), |
138 | | - $wgRequest->getInt( "survey-question-type-$questionId" ), |
139 | | - $wgRequest->getCheck( "survey-question-required-$questionId" ) |
140 | | - ); |
| 134 | + $question = new SurveyQuestion( array( |
| 135 | + 'id' => $questionDbId, |
| 136 | + 'removed' => 0, |
| 137 | + 'text' => $wgRequest->getText( "survey-question-text-$questionId" ), |
| 138 | + 'type' => $wgRequest->getInt( "survey-question-type-$questionId" ), |
| 139 | + 'required' => $wgRequest->getCheck( "survey-question-required-$questionId" ) |
| 140 | + ) ); |
141 | 141 | |
142 | 142 | return $question; |
143 | 143 | } |
Index: trunk/extensions/Survey/includes/SurveyDBClass.php |
— | — | @@ -30,9 +30,12 @@ |
31 | 31 | * @param array|null $fields |
32 | 32 | */ |
33 | 33 | public function __construct( $fields ) { |
34 | | - if ( !is_null( $fields ) ) { |
| 34 | + if ( is_array( $fields ) ) { |
35 | 35 | $this->setFields( $fields ); |
36 | 36 | } |
| 37 | + else { |
| 38 | + throw new Exception(''); |
| 39 | + } |
37 | 40 | } |
38 | 41 | |
39 | 42 | /** |
— | — | @@ -203,11 +206,11 @@ |
204 | 207 | * @return boolean Success indicator |
205 | 208 | */ |
206 | 209 | public function writeToDB() { |
207 | | - if ( $this->hadIdField() ) { |
208 | | - return $this->insertIntoDB(); |
| 210 | + if ( $this->hasIdField() ) { |
| 211 | + return $this->updateInDB(); |
209 | 212 | } |
210 | 213 | else { |
211 | | - return $this->updateInDB(); |
| 214 | + return $this->insertIntoDB(); |
212 | 215 | } |
213 | 216 | } |
214 | 217 | |
— | — | @@ -379,6 +382,17 @@ |
380 | 383 | public function getId() { |
381 | 384 | return $this->getField( static::getIDField() ); |
382 | 385 | } |
| 386 | + |
| 387 | + /** |
| 388 | + * Sets the objects database id. |
| 389 | + * |
| 390 | + * @since 0.1 |
| 391 | + * |
| 392 | + * @param integere|null $id |
| 393 | + */ |
| 394 | + public function setId( $id ) { |
| 395 | + return $this->setField( static::getIDField(), $id ); |
| 396 | + } |
383 | 397 | |
384 | 398 | /** |
385 | 399 | * Gets if a certain field is set. |
— | — | @@ -442,14 +456,16 @@ |
443 | 457 | $values = array(); |
444 | 458 | |
445 | 459 | foreach ( static::getFieldTypes() as $name => $type ) { |
446 | | - $value = $this->fields[$name]; |
447 | | - |
448 | | - switch ( $type ) { |
449 | | - case 'array': |
450 | | - $value = serialize( (array)$value ); |
| 460 | + if ( array_key_exists( $name, $this->fields ) ) { |
| 461 | + $value = $this->fields[$name]; |
| 462 | + |
| 463 | + switch ( $type ) { |
| 464 | + case 'array': |
| 465 | + $value = serialize( (array)$value ); |
| 466 | + } |
| 467 | + |
| 468 | + $values[static::getFieldPrefix() . $name] = $value; |
451 | 469 | } |
452 | | - |
453 | | - $values[static::getFieldPrefix() . $name] = $value; |
454 | 470 | } |
455 | 471 | |
456 | 472 | return $values; |
Index: trunk/extensions/Survey/includes/Survey.class.php |
— | — | @@ -134,7 +134,7 @@ |
135 | 135 | $dbw->begin(); |
136 | 136 | |
137 | 137 | foreach ( $this->questions as /* SurveyQuestion */ $question ) { |
138 | | - $question->setSurveyId( $this->getId() ); |
| 138 | + $question->setId( $this->getId() ); |
139 | 139 | $success = $question->writeToDB() && $success; |
140 | 140 | } |
141 | 141 | |