Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -44,6 +44,10 @@ |
45 | 45 | 'survey-question-type-textarea' => 'Multi line text field', |
46 | 46 | 'survey-question-type-check' => 'Checkbox', |
47 | 47 | |
| 48 | + 'survey-navigation-edit' => '[[Special:Survey/$1|Edit this survey]]', |
| 49 | + 'survey-navigation-take' => '[[Special:TakeSurvey/$1|Take this survey]]', |
| 50 | + 'survey-navigation-list' => '[[Special:Surveys|Surveys list]]', |
| 51 | + |
48 | 52 | // Special:Surveys |
49 | 53 | 'surveys-special-addnew' => 'Add a new survey', |
50 | 54 | 'surveys-special-namedoc' => 'Enter the name for the new survey.', |
— | — | @@ -88,6 +92,7 @@ |
89 | 93 | 'surveys-surveystats-question-text' => 'Question text', |
90 | 94 | 'surveys-surveystats-question-answercount' => 'Amount of answers', |
91 | 95 | 'surveys-surveystats-question-answers' => 'Most provided answers', |
| 96 | + 'surveys-surveystats-question-answer' => '$1 ($2 {{PLURAL:$3|answer|answers}})', |
92 | 97 | |
93 | 98 | // Special:Survey |
94 | 99 | 'surveys-special-unknown-name' => 'There is no survey with the requested name.', |
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php |
— | — | @@ -38,7 +38,9 @@ |
39 | 39 | $subPage = trim( $subPage ); |
40 | 40 | |
41 | 41 | if ( Survey::has( array( 'name' => $subPage ) ) ) { |
42 | | - $this->displayStats( Survey::newFromName( $subPage ) ); |
| 42 | + $survey = Survey::newFromName( $subPage ); |
| 43 | + $this->displayNavigation( $survey ); |
| 44 | + $this->displayStats( $survey ); |
43 | 45 | } |
44 | 46 | else { |
45 | 47 | $this->showError( 'surveys-surveystats-nosuchsurvey' ); |
— | — | @@ -47,6 +49,23 @@ |
48 | 50 | } |
49 | 51 | |
50 | 52 | /** |
| 53 | + * Display links to edit and take the survey. |
| 54 | + * |
| 55 | + * @since 0.1 |
| 56 | + * |
| 57 | + * @param Survey $survey |
| 58 | + */ |
| 59 | + protected function displayNavigation( Survey $survey ) { |
| 60 | + $links = array( |
| 61 | + wfMsgExt( 'survey-navigation-edit', 'parseinline', $survey->getField( 'name' ) ), |
| 62 | + wfMsgExt( 'survey-navigation-take', 'parseinline', $survey->getField( 'name' ) ), |
| 63 | + wfMsgExt( 'survey-navigation-list', 'parseinline' ) |
| 64 | + ); |
| 65 | + |
| 66 | + $this->getOutput()->addHTML( Html::rawElement( 'p', array(), implode( ' - ', $links ) ) ); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
51 | 70 | * Display the statistics that go with the survey. |
52 | 71 | * |
53 | 72 | * @since 0.1 |
— | — | @@ -136,7 +155,7 @@ |
137 | 156 | '<th>' . wfMsgHtml( 'surveys-surveystats-question-type' ) . '</th>' . |
138 | 157 | '<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-text' ) . '</th>' . |
139 | 158 | '<th>' . wfMsgHtml( 'surveys-surveystats-question-answercount' ) . '</th>' . |
140 | | - //'<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-answers' ) . '</th>' . |
| 159 | + '<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-answers' ) . '</th>' . |
141 | 160 | '</tr></thead>' |
142 | 161 | ); |
143 | 162 | |
— | — | @@ -189,13 +208,46 @@ |
190 | 209 | SurveyAnswer::count( array( 'question_id' => $question->getId() ) ) |
191 | 210 | ) ); |
192 | 211 | |
193 | | -// $out->addHTML( Html::element( |
194 | | -// 'td', |
195 | | -// array(), |
196 | | -// '...' |
197 | | -// ) ); |
| 212 | + $out->addHTML( Html::rawElement( |
| 213 | + 'td', |
| 214 | + array(), |
| 215 | + $this->getAnswerList( $question ) |
| 216 | + ) ); |
198 | 217 | |
199 | 218 | $out->addHTML( '</tr>' ); |
200 | 219 | } |
201 | 220 | |
| 221 | + protected function getAnswerList( SurveyQuestion $question ) { |
| 222 | + if ( $question->isRestrictiveType() ) { |
| 223 | + $list = '<ul>'; |
| 224 | + |
| 225 | + $answers = array(); |
| 226 | + |
| 227 | + foreach ( $question->getField( 'answers' ) as $answer ) { |
| 228 | + $answers[$answer] = SurveyAnswer::count( array( 'text' => $answer ) ); |
| 229 | + } |
| 230 | + |
| 231 | + asort( $answers, SORT_NUMERIC ); |
| 232 | + |
| 233 | + foreach ( array_reverse( $answers ) as $answer => $answerCount ) { |
| 234 | + $list .= Html::element( |
| 235 | + 'li', |
| 236 | + array(), |
| 237 | + wfMsgExt( |
| 238 | + 'surveys-surveystats-question-answer', |
| 239 | + 'parsemag', |
| 240 | + $answer, |
| 241 | + $GLOBALS['wgLang']->formatNum( $answerCount ), |
| 242 | + $answerCount |
| 243 | + ) |
| 244 | + ); |
| 245 | + } |
| 246 | + |
| 247 | + return $list . '</ul>'; |
| 248 | + } |
| 249 | + else { |
| 250 | + return ''; |
| 251 | + } |
| 252 | + } |
| 253 | + |
202 | 254 | } |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -162,16 +162,28 @@ |
163 | 163 | |
164 | 164 | if ( $messageMap === false ) { |
165 | 165 | $messageMap = array( |
166 | | - self::$TYPE_TEXT = 'text', |
167 | | - self::$TYPE_NUMBER = 'number', |
168 | | - self::$TYPE_SELECT = 'select', |
169 | | - self::$TYPE_RADIO = 'radio', |
170 | | - self::$TYPE_TEXTAREA = 'textarea', |
171 | | - self::$TYPE_CHECK = 'check', |
| 166 | + self::$TYPE_TEXT => 'text', |
| 167 | + self::$TYPE_NUMBER => 'number', |
| 168 | + self::$TYPE_SELECT => 'select', |
| 169 | + self::$TYPE_RADIO => 'radio', |
| 170 | + self::$TYPE_TEXTAREA => 'textarea', |
| 171 | + self::$TYPE_CHECK => 'check', |
172 | 172 | ); |
173 | 173 | } |
174 | 174 | |
175 | 175 | return 'survey-question-type-' . $messageMap[$type]; |
176 | 176 | } |
177 | 177 | |
| 178 | + /** |
| 179 | + * Returns if the type of the question is restrictive, |
| 180 | + * ie if the question input only allows certain answers. |
| 181 | + * |
| 182 | + * @since 0.1 |
| 183 | + * |
| 184 | + * @return boolean |
| 185 | + */ |
| 186 | + public function isRestrictiveType() { |
| 187 | + return in_array( $this->getField( 'type' ), array( self::$TYPE_SELECT, self::$TYPE_RADIO ) ); |
| 188 | + } |
| 189 | + |
178 | 190 | } |