Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -67,6 +67,12 @@ |
68 | 68 | |
69 | 69 | // Special:SurveyStats |
70 | 70 | 'surveys-surveystats-nosuchsurvey' => 'The requested survey does not exist. A list of available surveys can be found on [[Special:Surveys]]', |
| 71 | + 'surveys-surveystats-name' => 'Survey name', |
| 72 | + 'surveys-surveystats-status' => 'Survey status', |
| 73 | + 'surveys-surveystats-questioncount' => 'Number of questions', |
| 74 | + 'surveys-surveystats-submissioncount' => 'Number of submissions', |
| 75 | + 'surveys-surveystats-enabled' => 'Enabled', |
| 76 | + 'surveys-surveystats-disabled' => 'Disabled', |
71 | 77 | |
72 | 78 | // Special:Survey |
73 | 79 | 'surveys-special-unknown-name' => 'There is no survey with the requested name.', |
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php |
— | — | @@ -47,7 +47,51 @@ |
48 | 48 | } |
49 | 49 | |
50 | 50 | protected function displayStats( Survey $survey ) { |
51 | | - // TODO |
| 51 | + $this->displaySummary( $this->getSummaryData( $survey ) ); |
| 52 | + |
| 53 | + // TODO: magic |
| 54 | + //$this->displayQuestionStats(); |
52 | 55 | } |
53 | 56 | |
| 57 | + protected function getSummaryData( Survey $survey ) { |
| 58 | + $stats = array(); |
| 59 | + |
| 60 | + $stats['name'] = $survey->getField( 'name' ); |
| 61 | + $stats['status'] = wfMsg( 'surveys-surveystats-' . ( $survey->getField( 'enabled' ) ? 'enabled' : 'disabled' ) ); |
| 62 | + $stats['questioncount'] = count( $survey->getQuestions() ) ; |
| 63 | + $stats['submissioncount'] = SurveySubmission::count( array( 'survey_id' => $survey->getId() ) ); |
| 64 | + |
| 65 | + return $stats; |
| 66 | + } |
| 67 | + |
| 68 | + protected function displaySummary( array $stats ) { |
| 69 | + $out = $this->getOutput(); |
| 70 | + |
| 71 | + $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable survey-stats' ) ) ); |
| 72 | + |
| 73 | + foreach ( $stats as $stat => $value ) { |
| 74 | + $out->addHTML( '<tr>' ); |
| 75 | + |
| 76 | + $out->addHTML( Html::element( |
| 77 | + 'th', |
| 78 | + array( 'class' => 'survey-stat-name' ), |
| 79 | + wfMsg( 'surveys-surveystats-' . $stat ) |
| 80 | + ) ); |
| 81 | + |
| 82 | + $out->addHTML( Html::element( |
| 83 | + 'td', |
| 84 | + array( 'class' => 'survey-stat-value' ), |
| 85 | + $value |
| 86 | + ) ); |
| 87 | + |
| 88 | + $out->addHTML( '</tr>' ); |
| 89 | + } |
| 90 | + |
| 91 | + $out->addHTML( Html::closeElement( 'table' ) ); |
| 92 | + } |
| 93 | + |
| 94 | + protected function displayQuestionStats( SurveyQuestion $question ) { |
| 95 | + |
| 96 | + } |
| 97 | + |
54 | 98 | } |
Index: trunk/extensions/Survey/includes/SurveyDBClass.php |
— | — | @@ -137,7 +137,7 @@ |
138 | 138 | |
139 | 139 | /** |
140 | 140 | * Selects the the specified fields of the records matching the provided |
141 | | - * conditions. |
| 141 | + * conditions. Field names get prefixed. |
142 | 142 | * |
143 | 143 | * @since 0.1 |
144 | 144 | * |
— | — | @@ -148,8 +148,16 @@ |
149 | 149 | * @return array of self |
150 | 150 | */ |
151 | 151 | public static function select( $fields = null, array $conditions = array(), array $options = array() ) { |
152 | | - $result = static::rawSelect( $fields, $conditions, $options ); |
| 152 | + if ( is_null( $fields ) ) { |
| 153 | + $fields = array_keys( static::getFieldTypes() ); |
| 154 | + } |
153 | 155 | |
| 156 | + $result = static::rawSelect( |
| 157 | + static::getPrefixedFields( $fields ), |
| 158 | + static::getPrefixedValues( $conditions ), |
| 159 | + $options |
| 160 | + ); |
| 161 | + |
154 | 162 | $objects = array(); |
155 | 163 | |
156 | 164 | foreach ( $result as $record ) { |
— | — | @@ -161,6 +169,7 @@ |
162 | 170 | |
163 | 171 | /** |
164 | 172 | * Selects the the specified fields of the first matching record. |
| 173 | + * Field names get prefixed. |
165 | 174 | * |
166 | 175 | * @since 0.1 |
167 | 176 | * |
— | — | @@ -180,6 +189,7 @@ |
181 | 190 | |
182 | 191 | /** |
183 | 192 | * Returns if there is at least one record matching the provided conditions. |
| 193 | + * Condition field names get prefixed. |
184 | 194 | * |
185 | 195 | * @since 0.1 |
186 | 196 | * |
— | — | @@ -192,8 +202,29 @@ |
193 | 203 | } |
194 | 204 | |
195 | 205 | /** |
| 206 | + * Returns the amount of matching records. |
| 207 | + * Condition field names get prefixed. |
| 208 | + * |
| 209 | + * @since 0.1 |
| 210 | + * |
| 211 | + * @param array $conditions |
| 212 | + * @param array $options |
| 213 | + * |
| 214 | + * @return integer |
| 215 | + */ |
| 216 | + public static function count( array $conditions = array(), array $options = array() ) { |
| 217 | + $res = static::rawSelect( |
| 218 | + array( 'COUNT(*) AS rowcount' ), |
| 219 | + static::getPrefixedValues( $conditions ), |
| 220 | + $options |
| 221 | + )->fetchObject(); |
| 222 | + |
| 223 | + return $res->rowcount; |
| 224 | + } |
| 225 | + |
| 226 | + /** |
196 | 227 | * Selects the the specified fields of the records matching the provided |
197 | | - * conditions. |
| 228 | + * conditions. Field names do NOT get prefixed. |
198 | 229 | * |
199 | 230 | * @since 0.1 |
200 | 231 | * |
— | — | @@ -203,17 +234,13 @@ |
204 | 235 | * |
205 | 236 | * @return ResultWrapper |
206 | 237 | */ |
207 | | - public static function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) { |
208 | | - if ( is_null( $fields ) ) { |
209 | | - $fields = array_keys( static::getFieldTypes() ); |
210 | | - } |
211 | | - |
| 238 | + public static function rawSelect( $fields = null, array $conditions = array(), array $options = array() ) { |
212 | 239 | $dbr = wfGetDB( DB_SLAVE ); |
213 | 240 | |
214 | 241 | return $dbr->select( |
215 | 242 | static::getDBTable(), |
216 | | - static::getPrefixedFields( $fields ), |
217 | | - count( $conditions ) == 0 ? '' : static::getPrefixedValues( $conditions ), |
| 243 | + $fields, |
| 244 | + count( $conditions ) == 0 ? '' : $conditions, |
218 | 245 | '', |
219 | 246 | $options |
220 | 247 | ); |
Index: trunk/extensions/Survey/includes/SurveyTag.php |
— | — | @@ -48,7 +48,8 @@ |
49 | 49 | } |
50 | 50 | |
51 | 51 | $this->parameters['class'] = 'surveytag'; |
52 | | - $this->parameters['survey-data-token'] = $GLOBALS['wgUser']->editToken(); |
| 52 | + $this->parameters['survey-data-token'] = |
| 53 | + $GLOBALS['wgUser']->editToken( serialize( array( 'submitsurvey', $GLOBALS['wgUser']->getName() ) ) ); |
53 | 54 | } else { |
54 | 55 | throw new MWException( 'Invalid parameters for survey tag.' ); |
55 | 56 | } |
Index: trunk/extensions/Survey/api/ApiSubmitSurvey.php |
— | — | @@ -64,7 +64,7 @@ |
65 | 65 | } |
66 | 66 | |
67 | 67 | public function getTokenSalt() { |
68 | | - return 'submitsurvey'; |
| 68 | + return serialize( array( 'submitsurvey', $GLOBALS['wgUser']->getName() ) ); |
69 | 69 | } |
70 | 70 | |
71 | 71 | public function mustBePosted() { |