r96418 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96417‎ | r96418 | r96419 >
Date:12:07, 7 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on survey admin
Modified paths:
  • /trunk/extensions/Survey/includes/Survey.class.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyAnswer.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyDBClass.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyQuestion.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveySubmission.php (modified) (history)
  • /trunk/extensions/Survey/resources/ext.survey.js (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurvey.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/specials/SpecialSurvey.php
@@ -111,7 +111,7 @@
112112 }
113113
114114 /**
115 - * Create a
 115+ * Create and return a survey question object from the submitted data.
116116 *
117117 * @since 0.1
118118 *
Index: trunk/extensions/Survey/includes/SurveyDBClass.php
@@ -73,7 +73,7 @@
7474 * @throws MWException
7575 * @return string
7676 */
77 - protected static function getDBTable() {
 77+ public static function getDBTable() {
7878 throw new MWException( 'Class did not implement getDBTable' );
7979 }
8080
@@ -206,6 +206,16 @@
207207 );
208208 }
209209
 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+
210220 /**
211221 * Writes the answer to the database, either updating it
212222 * when it already exists, or inserting it when it doesn't.
@@ -334,6 +344,7 @@
335345 switch ( $fields[$name] ) {
336346 case 'int':
337347 $value = (int)$value;
 348+ break;
338349 case 'bool':
339350 if ( is_string( $value ) ) {
340351 $value = $value !== '0';
@@ -341,14 +352,17 @@
342353 else if ( is_int( $value ) ) {
343354 $value = $value !== 0;
344355 }
 356+ break;
345357 case 'array':
346358 if ( is_string( $value ) ) {
347359 $value = unserialize( $value );
348360 }
 361+ break;
349362 case 'id':
350363 if ( is_string( $value ) ) {
351364 $value = (int)$value;
352365 }
 366+ break;
353367 }
354368
355369 $this->fields[$name] = $value;
Index: trunk/extensions/Survey/includes/SurveySubmission.php
@@ -16,7 +16,7 @@
1717 /**
1818 * @see SurveyDBClass::getDBTable()
1919 */
20 - protected static function getDBTable() {
 20+ public static function getDBTable() {
2121 return 'survey_submissions';
2222 }
2323
Index: trunk/extensions/Survey/includes/SurveyAnswer.php
@@ -16,7 +16,7 @@
1717 /**
1818 * @see SurveyDBClass::getDBTable()
1919 */
20 - protected static function getDBTable() {
 20+ public static function getDBTable() {
2121 return 'survey_answers';
2222 }
2323
Index: trunk/extensions/Survey/includes/Survey.class.php
@@ -16,7 +16,7 @@
1717 /**
1818 * @see SurveyDBClass::getDBTable()
1919 */
20 - protected static function getDBTable() {
 20+ public static function getDBTable() {
2121 return 'surveys';
2222 }
2323
@@ -122,6 +122,14 @@
123123 }
124124
125125 /**
 126+ * The questions that go with this survey.
 127+ *
 128+ * @since 0.1
 129+ * @var array of SurveyQuestion
 130+ */
 131+ protected $questions;
 132+
 133+ /**
126134 * Constructor.
127135 *
128136 * @since 0.1
@@ -145,7 +153,7 @@
146154 }
147155
148156 /**
149 - * Writes the survey to the database, either updating it
 157+ * Writes the surveyand it's questions to the database, either updating it
150158 * when it already exists, or inserting it when it doesn't.
151159 *
152160 * @since 0.1
@@ -155,12 +163,34 @@
156164 public function writeToDB() {
157165 $success = parent::writeToDB();
158166
 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+
159184 $dbw = wfGetDB( DB_MASTER );
160185
161186 $dbw->begin();
 187+
 188+ SurveyQuestion::update(
 189+ array( 'removed' => 1 ),
 190+ array( 'survey_id' => $this->getId() )
 191+ );
162192
163193 foreach ( $this->questions as /* SurveyQuestion */ $question ) {
164 - $question->setId( $this->getId() );
 194+ $question->setField( 'survey_id', $this->getId() );
165195 $success = $question->writeToDB() && $success;
166196 }
167197
Index: trunk/extensions/Survey/includes/SurveyQuestion.php
@@ -21,7 +21,7 @@
2222 /**
2323 * @see SurveyDBClass::getDBTable()
2424 */
25 - protected static function getDBTable() {
 25+ public static function getDBTable() {
2626 return 'survey_questions';
2727 }
2828
Index: trunk/extensions/Survey/resources/ext.survey.js
@@ -75,7 +75,7 @@
7676 options[survey.msg( 'survey-question-type-' + msg )] = types[msg];
7777 }
7878
79 - return survey.htmlSelect( options, value, attributes );
 79+ return survey.htmlSelect( options, parseInt( value ), attributes );
8080 };
8181
8282 } );

Status & tagging log