Index: trunk/extensions/Survey/specials/SpecialSurvey.php |
— | — | @@ -75,7 +75,10 @@ |
76 | 76 | $survey = Survey::newFromId( $wgRequest->getInt( 'survey-id' ), null, false ); |
77 | 77 | } |
78 | 78 | |
79 | | - $survey->setField( 'name', $wgRequest->getText( 'survey-name' ) ); |
| 79 | + foreach ( array( 'name', 'header', 'footer', 'thanks' ) as $field ) { |
| 80 | + $survey->setField( $field, $wgRequest->getText( 'survey-' . $field ) ); |
| 81 | + } |
| 82 | + |
80 | 83 | $survey->setField( 'enabled', $wgRequest->getCheck( 'survey-enabled' ) ); |
81 | 84 | |
82 | 85 | $survey->setQuestions( $this->getSubmittedQuestions() ); |
Index: trunk/extensions/Survey/includes/SurveyDBClass.php |
— | — | @@ -20,7 +20,7 @@ |
21 | 21 | * @since 0.1 |
22 | 22 | * @var array |
23 | 23 | */ |
24 | | - protected $fields; |
| 24 | + protected $fields = array(); |
25 | 25 | |
26 | 26 | /** |
27 | 27 | * Constructor. |
— | — | @@ -33,6 +33,10 @@ |
34 | 34 | public function __construct( $fields, $loadDefaults = false ) { |
35 | 35 | $this->setField( static::getIDField(), null ); |
36 | 36 | |
| 37 | + if ( !is_array( $fields ) ) { |
| 38 | + $fields = array(); |
| 39 | + } |
| 40 | + |
37 | 41 | if ( $loadDefaults ) { |
38 | 42 | $fields = array_merge( static::getDefaults(), $fields ); |
39 | 43 | } |
— | — | @@ -47,9 +51,11 @@ |
48 | 52 | * field name => type |
49 | 53 | * |
50 | 54 | * Allowed types: |
| 55 | + * * id |
51 | 56 | * * str |
52 | 57 | * * int |
53 | 58 | * * bool |
| 59 | + * * array |
54 | 60 | * |
55 | 61 | * @since 0.1 |
56 | 62 | * |
— | — | @@ -270,7 +276,7 @@ |
271 | 277 | ); |
272 | 278 | |
273 | 279 | if ( $sucecss ) { |
274 | | - $this->removeField( static::getIDField() ); |
| 280 | + $this->setField( static::getIDField(), null ); |
275 | 281 | } |
276 | 282 | |
277 | 283 | return $sucecss; |
— | — | @@ -339,6 +345,10 @@ |
340 | 346 | if ( is_string( $value ) ) { |
341 | 347 | $value = unserialize( $value ); |
342 | 348 | } |
| 349 | + case 'id': |
| 350 | + if ( is_string( $value ) ) { |
| 351 | + $value = (int)$value; |
| 352 | + } |
343 | 353 | } |
344 | 354 | |
345 | 355 | $this->fields[$name] = $value; |
— | — | @@ -363,7 +373,6 @@ |
364 | 374 | return $this->fields[$name]; |
365 | 375 | } |
366 | 376 | else { |
367 | | - var_dump($this->fields); |
368 | 377 | throw new MWException( 'Attempted to get not-set field ' . $name ); |
369 | 378 | } |
370 | 379 | } |
Index: trunk/extensions/Survey/includes/SurveySubmission.php |
— | — | @@ -14,84 +14,50 @@ |
15 | 15 | class SurveySubmission extends SurveyDBClass { |
16 | 16 | |
17 | 17 | /** |
18 | | - * The ID of the survey this submission is for. |
19 | | - * |
20 | | - * @since 0.1 |
21 | | - * @var integer |
| 18 | + * @see SurveyDBClass::getDBTable() |
22 | 19 | */ |
23 | | - protected $surveyId; |
| 20 | + protected static function getDBTable() { |
| 21 | + return 'survey_submissions'; |
| 22 | + } |
24 | 23 | |
25 | 24 | /** |
26 | | - * The ID of the page this submission was made on. |
| 25 | + * Gets the db field prefix. |
27 | 26 | * |
28 | 27 | * @since 0.1 |
29 | | - * @var integer |
30 | | - */ |
31 | | - protected $pageId; |
32 | | - |
33 | | - /** |
34 | | - * The name of the user that made the submission (username or ip). |
35 | 28 | * |
36 | | - * @since 0.1 |
37 | | - * @var string |
| 29 | + * @return string |
38 | 30 | */ |
39 | | - protected $userName; |
| 31 | + protected static function getFieldPrefix() { |
| 32 | + return 'submission_'; |
| 33 | + } |
40 | 34 | |
41 | 35 | /** |
42 | | - * Timestamp idnicating when the submission was made. |
| 36 | + * Returns an array with the fields and their types this object contains. |
| 37 | + * This corresponds directly to the fields in the database, without prefix. |
43 | 38 | * |
44 | | - * @since 0.1 |
45 | | - * @var string |
46 | | - */ |
47 | | - protected $timeStamp; |
48 | | - |
49 | | - |
50 | | - /** |
51 | | - * Constructor. |
| 39 | + * survey_id: |
| 40 | + * The ID of the survey this submission is for. |
52 | 41 | * |
53 | | - * @since 0.1 |
| 42 | + * page_id: |
| 43 | + * The ID of the page this submission was made on. |
54 | 44 | * |
55 | | - * @param integer|null $id |
56 | | - * @param integer $surveyId |
57 | | - * @param string $userName |
58 | | - * @param integer $pageId |
59 | | - * @param string $timeStamp |
60 | | - */ |
61 | | - public function __construct( $id, $surveyId, $userName, $pageId, $timeStamp ) { |
62 | | - $this->id = is_null( $id ) ? $id : (int)$id; |
63 | | - $this->surveyId = (int)$surveyId; |
64 | | - $this->userName = $userName; |
65 | | - $this->pageId = (int)$pageId; |
66 | | - $this->timeStamp = $timeStamp; |
67 | | - } |
68 | | - |
69 | | - /** |
70 | | - * @see SurveyDBClass::getDBTable() |
71 | | - */ |
72 | | - protected function getDBTable() { |
73 | | - return 'survey_submissions'; |
74 | | - } |
75 | | - |
76 | | - /** |
77 | | - * @see SurveyDBClass::getIDField() |
78 | | - */ |
79 | | - protected function getIDField() { |
80 | | - return 'submission_id'; |
81 | | - } |
82 | | - |
83 | | - /** |
84 | | - * Gets the fields => values to write to the survey_sumissions table. |
| 45 | + * user_name: |
| 46 | + * The name of the user that made the submission (username or ip). |
85 | 47 | * |
| 48 | + * time: |
| 49 | + * Timestamp idnicating when the submission was made. |
| 50 | + * |
86 | 51 | * @since 0.1 |
87 | 52 | * |
88 | 53 | * @return array |
89 | 54 | */ |
90 | | - protected function getWriteValues() { |
| 55 | + protected static function getFieldTypes() { |
91 | 56 | return array( |
92 | | - 'submission_survey_id' => $this->surveyId, |
93 | | - 'submission_user_name' => $this->userName, |
94 | | - 'submission_page_id' => $this->pageId, |
95 | | - 'submission_time' => $this->timeStamp, |
| 57 | + 'id' => 'id', |
| 58 | + 'survey_id' => 'id', |
| 59 | + 'page_id' => 'id', |
| 60 | + 'user_name' => 'str', |
| 61 | + 'time' => 'str', |
96 | 62 | ); |
97 | 63 | } |
98 | 64 | |
Index: trunk/extensions/Survey/includes/SurveyAnswer.php |
— | — | @@ -14,72 +14,46 @@ |
15 | 15 | class SurveyAnswer extends SurveyDBClass { |
16 | 16 | |
17 | 17 | /** |
18 | | - * The answer text. |
19 | | - * |
20 | | - * @since 0.1 |
21 | | - * @var string |
| 18 | + * @see SurveyDBClass::getDBTable() |
22 | 19 | */ |
23 | | - protected $text; |
| 20 | + protected static function getDBTable() { |
| 21 | + return 'survey_answers'; |
| 22 | + } |
24 | 23 | |
25 | 24 | /** |
26 | | - * The ID of the submission this answer is part of. |
| 25 | + * Gets the db field prefix. |
27 | 26 | * |
28 | 27 | * @since 0.1 |
29 | | - * @var integer |
30 | | - */ |
31 | | - protected $submissionId; |
32 | | - |
33 | | - /** |
34 | | - * The ID of the question this answer corresponds to. |
35 | 28 | * |
36 | | - * @since 0.1 |
37 | | - * @var integer |
| 29 | + * @return string |
38 | 30 | */ |
39 | | - protected $questionId; |
| 31 | + protected static function getFieldPrefix() { |
| 32 | + return 'answer_'; |
| 33 | + } |
40 | 34 | |
41 | 35 | /** |
42 | | - * Constructor. |
| 36 | + * Returns an array with the fields and their types this object contains. |
| 37 | + * This corresponds directly to the fields in the database, without prefix. |
43 | 38 | * |
44 | | - * @since 0.1 |
| 39 | + * text: |
| 40 | + * The answer text. |
45 | 41 | * |
46 | | - * @param integer|null $id |
47 | | - * @param integer $submissionId |
48 | | - * @param integer $questionId |
49 | | - * @param string $text |
50 | | - */ |
51 | | - public function __construct( $id, $submissionId, $questionId, $text ) { |
52 | | - $this->id = is_null( $id ) ? $id : (int)$id; |
53 | | - $this->submissionId = (int)$submissionId; |
54 | | - $this->questionId = (int)$questionId; |
55 | | - $this->text = $text; |
56 | | - } |
57 | | - |
58 | | - /** |
59 | | - * @see SurveyDBClass::getDBTable() |
60 | | - */ |
61 | | - protected function getDBTable() { |
62 | | - return 'survey_answers'; |
63 | | - } |
64 | | - |
65 | | - /** |
66 | | - * @see SurveyDBClass::getIDField() |
67 | | - */ |
68 | | - protected function getIDField() { |
69 | | - return 'answer_id'; |
70 | | - } |
71 | | - |
72 | | - /** |
73 | | - * Gets the fields => values to write to the survey_answers table. |
| 42 | + * submission_id: |
| 43 | + * The ID of the submission this answer is part of. |
74 | 44 | * |
| 45 | + * question_id: |
| 46 | + * The ID of the question this answer corresponds to. |
| 47 | + * |
75 | 48 | * @since 0.1 |
76 | 49 | * |
77 | 50 | * @return array |
78 | 51 | */ |
79 | | - protected function getWriteValues() { |
| 52 | + protected static function getFieldTypes() { |
80 | 53 | return array( |
81 | | - 'answer_submission_id' => $this->submissionId, |
82 | | - 'answer_question_id' => $this->questionId, |
83 | | - 'answer_text' => $this->text, |
| 54 | + 'id' => 'id', |
| 55 | + 'text' => 'str', |
| 56 | + 'submission_id' => 'id', |
| 57 | + 'question_id' => 'id', |
84 | 58 | ); |
85 | 59 | } |
86 | 60 | |
Index: trunk/extensions/Survey/includes/Survey.class.php |
— | — | @@ -226,7 +226,7 @@ |
227 | 227 | $submissionsForSurvey = $dbr->select( |
228 | 228 | 'survey_submissions', |
229 | 229 | array( 'submission_id' ), |
230 | | - array( 'submission_survey_id' => $this->id ) |
| 230 | + array( 'submission_survey_id' => $this->getId() ) |
231 | 231 | ); |
232 | 232 | |
233 | 233 | $dbw = wfgetDB( DB_MASTER ); |
— | — | @@ -237,18 +237,18 @@ |
238 | 238 | |
239 | 239 | $sucecss = $dbw->delete( |
240 | 240 | 'survey_questions', |
241 | | - array( 'question_survey_id' => $this->id ) |
| 241 | + array( 'question_survey_id' => $this->getId() ) |
242 | 242 | ) && $sucecss; |
243 | 243 | |
244 | 244 | $sucecss = $dbw->delete( |
245 | 245 | 'survey_submissions', |
246 | | - array( 'submission_survey_id' => $this->id ) |
| 246 | + array( 'submission_survey_id' => $this->getId() ) |
247 | 247 | ) && $sucecss; |
248 | 248 | |
249 | 249 | foreach ( $submissionsForSurvey as $nr => $submission ) { |
250 | 250 | $sucecss = $dbw->delete( |
251 | 251 | 'survey_answers', |
252 | | - array( 'answer_submission_id' => $submission->submission_id ) |
| 252 | + array( 'answer_submission_id' => $submission->getId() ) |
253 | 253 | ) && $sucecss; |
254 | 254 | |
255 | 255 | if ( $nr % 500 == 0 ) { |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -52,7 +52,7 @@ |
53 | 53 | */ |
54 | 54 | protected static function getFieldTypes() { |
55 | 55 | return array( |
56 | | - 'id' => 'int', |
| 56 | + 'id' => 'id', |
57 | 57 | 'survey_id' => 'int', |
58 | 58 | 'text' => 'str', |
59 | 59 | 'type' => 'int', |
Index: trunk/extensions/Survey/api/ApiDeleteSurvey.php |
— | — | @@ -30,7 +30,7 @@ |
31 | 31 | $everythingOk = true; |
32 | 32 | |
33 | 33 | foreach ( $params['ids'] as $id ) { |
34 | | - $surey = new Survey( $id ); |
| 34 | + $surey = new Survey( array( 'id' => $id ) ); |
35 | 35 | $everythingOk = $surey->removeFromDB() && $everythingOk; |
36 | 36 | } |
37 | 37 | |