Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -111,7 +111,7 @@ |
112 | 112 | } |
113 | 113 | |
114 | 114 | /** |
115 | | - * Create a |
| 115 | + * Create and return a survey question object from the submitted data. |
116 | 116 | * |
117 | 117 | * @since 0.1 |
118 | 118 | * |
Index: trunk/extensions/Survey/includes/SurveyDBClass.php |
— | — | @@ -73,7 +73,7 @@ |
74 | 74 | * @throws MWException |
75 | 75 | * @return string |
76 | 76 | */ |
77 | | - protected static function getDBTable() { |
| 77 | + public static function getDBTable() { |
78 | 78 | throw new MWException( 'Class did not implement getDBTable' ); |
79 | 79 | } |
80 | 80 | |
— | — | @@ -206,6 +206,16 @@ |
207 | 207 | ); |
208 | 208 | } |
209 | 209 | |
| 210 | + public static function update( array $values, array $conditions = array() ) { |
| 211 | + $dbw = wfGetDB( DB_MASTER ); |
| 212 | + |
| 213 | + return $dbw->update( |
| 214 | + static::getDBTable(), |
| 215 | + static::getPrefixedValues( $values ), |
| 216 | + static::getPrefixedValues( $conditions ) |
| 217 | + ); |
| 218 | + } |
| 219 | + |
210 | 220 | /** |
211 | 221 | * Writes the answer to the database, either updating it |
212 | 222 | * when it already exists, or inserting it when it doesn't. |
— | — | @@ -334,6 +344,7 @@ |
335 | 345 | switch ( $fields[$name] ) { |
336 | 346 | case 'int': |
337 | 347 | $value = (int)$value; |
| 348 | + break; |
338 | 349 | case 'bool': |
339 | 350 | if ( is_string( $value ) ) { |
340 | 351 | $value = $value !== '0'; |
— | — | @@ -341,14 +352,17 @@ |
342 | 353 | else if ( is_int( $value ) ) { |
343 | 354 | $value = $value !== 0; |
344 | 355 | } |
| 356 | + break; |
345 | 357 | case 'array': |
346 | 358 | if ( is_string( $value ) ) { |
347 | 359 | $value = unserialize( $value ); |
348 | 360 | } |
| 361 | + break; |
349 | 362 | case 'id': |
350 | 363 | if ( is_string( $value ) ) { |
351 | 364 | $value = (int)$value; |
352 | 365 | } |
| 366 | + break; |
353 | 367 | } |
354 | 368 | |
355 | 369 | $this->fields[$name] = $value; |
Index: trunk/extensions/Survey/includes/SurveySubmission.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | /** |
18 | 18 | * @see SurveyDBClass::getDBTable() |
19 | 19 | */ |
20 | | - protected static function getDBTable() { |
| 20 | + public static function getDBTable() { |
21 | 21 | return 'survey_submissions'; |
22 | 22 | } |
23 | 23 | |
Index: trunk/extensions/Survey/includes/SurveyAnswer.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | /** |
18 | 18 | * @see SurveyDBClass::getDBTable() |
19 | 19 | */ |
20 | | - protected static function getDBTable() { |
| 20 | + public static function getDBTable() { |
21 | 21 | return 'survey_answers'; |
22 | 22 | } |
23 | 23 | |
Index: trunk/extensions/Survey/includes/Survey.class.php |
— | — | @@ -16,7 +16,7 @@ |
17 | 17 | /** |
18 | 18 | * @see SurveyDBClass::getDBTable() |
19 | 19 | */ |
20 | | - protected static function getDBTable() { |
| 20 | + public static function getDBTable() { |
21 | 21 | return 'surveys'; |
22 | 22 | } |
23 | 23 | |
— | — | @@ -122,6 +122,14 @@ |
123 | 123 | } |
124 | 124 | |
125 | 125 | /** |
| 126 | + * The questions that go with this survey. |
| 127 | + * |
| 128 | + * @since 0.1 |
| 129 | + * @var array of SurveyQuestion |
| 130 | + */ |
| 131 | + protected $questions; |
| 132 | + |
| 133 | + /** |
126 | 134 | * Constructor. |
127 | 135 | * |
128 | 136 | * @since 0.1 |
— | — | @@ -145,7 +153,7 @@ |
146 | 154 | } |
147 | 155 | |
148 | 156 | /** |
149 | | - * Writes the survey to the database, either updating it |
| 157 | + * Writes the surveyand it's questions to the database, either updating it |
150 | 158 | * when it already exists, or inserting it when it doesn't. |
151 | 159 | * |
152 | 160 | * @since 0.1 |
— | — | @@ -155,12 +163,34 @@ |
156 | 164 | public function writeToDB() { |
157 | 165 | $success = parent::writeToDB(); |
158 | 166 | |
| 167 | + if ( $success ) { |
| 168 | + $success = $this->writeQuestionsToDB(); |
| 169 | + } |
| 170 | + |
| 171 | + return $success; |
| 172 | + } |
| 173 | + |
| 174 | + /** |
| 175 | + * Writes the surveys questions to the database. |
| 176 | + * |
| 177 | + * @since 0.1 |
| 178 | + * |
| 179 | + * @return boolean Success indicator |
| 180 | + */ |
| 181 | + public function writeQuestionsToDB() { |
| 182 | + $success = true; |
| 183 | + |
159 | 184 | $dbw = wfGetDB( DB_MASTER ); |
160 | 185 | |
161 | 186 | $dbw->begin(); |
| 187 | + |
| 188 | + SurveyQuestion::update( |
| 189 | + array( 'removed' => 1 ), |
| 190 | + array( 'survey_id' => $this->getId() ) |
| 191 | + ); |
162 | 192 | |
163 | 193 | foreach ( $this->questions as /* SurveyQuestion */ $question ) { |
164 | | - $question->setId( $this->getId() ); |
| 194 | + $question->setField( 'survey_id', $this->getId() ); |
165 | 195 | $success = $question->writeToDB() && $success; |
166 | 196 | } |
167 | 197 | |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -21,7 +21,7 @@ |
22 | 22 | /** |
23 | 23 | * @see SurveyDBClass::getDBTable() |
24 | 24 | */ |
25 | | - protected static function getDBTable() { |
| 25 | + public static function getDBTable() { |
26 | 26 | return 'survey_questions'; |
27 | 27 | } |
28 | 28 | |
Index: trunk/extensions/Survey/resources/ext.survey.js |
— | — | @@ -75,7 +75,7 @@ |
76 | 76 | options[survey.msg( 'survey-question-type-' + msg )] = types[msg]; |
77 | 77 | } |
78 | 78 | |
79 | | - return survey.htmlSelect( options, value, attributes ); |
| 79 | + return survey.htmlSelect( options, parseInt( value ), attributes ); |
80 | 80 | }; |
81 | 81 | |
82 | 82 | } ); |