Index: trunk/extensions/Survey/Survey.i18n.php |
— | — | @@ -36,6 +36,14 @@ |
37 | 37 | 'survey-err-duplicate-name' => 'There already is a survey with name "$1"', |
38 | 38 | 'survey-err-ids-xor-names' => 'You need to provide either the ids or the names of the surveys to query', |
39 | 39 | |
| 40 | + // Question types |
| 41 | + 'survey-question-type-text' => 'Single line text field', |
| 42 | + 'survey-question-type-number' => 'Number', |
| 43 | + 'survey-question-type-select' => 'Dropdown menu', |
| 44 | + 'survey-question-type-radio' => 'Radio boxes', |
| 45 | + 'survey-question-type-textarea' => 'Multi line text field', |
| 46 | + 'survey-question-type-check' => 'Checkbox', |
| 47 | + |
40 | 48 | // Special:Surveys |
41 | 49 | 'surveys-special-addnew' => 'Add a new survey', |
42 | 50 | 'surveys-special-namedoc' => 'Enter the name for the new survey.', |
— | — | @@ -73,6 +81,13 @@ |
74 | 82 | 'surveys-surveystats-submissioncount' => 'Number of submissions', |
75 | 83 | 'surveys-surveystats-enabled' => 'Enabled', |
76 | 84 | 'surveys-surveystats-disabled' => 'Disabled', |
| 85 | + 'surveys-surveystats-questions' => 'Question statistics', |
| 86 | + 'surveys-surveystats-question-nr' => '#', |
| 87 | + 'surveys-surveystats-question-#' => '$1', |
| 88 | + 'surveys-surveystats-question-type' => 'Question type', |
| 89 | + 'surveys-surveystats-question-text' => 'Question text', |
| 90 | + 'surveys-surveystats-question-answercount' => 'Amount of answers', |
| 91 | + 'surveys-surveystats-question-answers' => 'Most provided answers', |
77 | 92 | |
78 | 93 | // Special:Survey |
79 | 94 | 'surveys-special-unknown-name' => 'There is no survey with the requested name.', |
— | — | @@ -81,12 +96,6 @@ |
82 | 97 | 'survey-special-label-button' => 'Add question', |
83 | 98 | 'survey-special-label-addquestion' => 'New question', |
84 | 99 | 'survey-special-label-add' => 'New question name', |
85 | | - 'survey-question-type-text' => 'Single line text field', |
86 | | - 'survey-question-type-number' => 'Number', |
87 | | - 'survey-question-type-select' => 'Dropdown menu', |
88 | | - 'survey-question-type-radio' => 'Radio boxes', |
89 | | - 'survey-question-type-textarea' => 'Multi line text field', |
90 | | - 'survey-question-type-check' => 'Checkbox', |
91 | 100 | 'survey-question-label-nr' => 'Question #$1', |
92 | 101 | 'survey-special-label-required' => 'Question is required', |
93 | 102 | 'survey-special-label-type' => 'Question type', |
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php |
— | — | @@ -48,11 +48,18 @@ |
49 | 49 | |
50 | 50 | protected function displayStats( Survey $survey ) { |
51 | 51 | $this->displaySummary( $this->getSummaryData( $survey ) ); |
52 | | - |
53 | | - // TODO: magic |
54 | | - //$this->displayQuestionStats(); |
| 52 | + $this->displayQuestions( $survey ); |
55 | 53 | } |
56 | 54 | |
| 55 | + /** |
| 56 | + * Gets the summary data. |
| 57 | + * |
| 58 | + * @since 0.1 |
| 59 | + * |
| 60 | + * @param Survey $survey |
| 61 | + * |
| 62 | + * @return array |
| 63 | + */ |
57 | 64 | protected function getSummaryData( Survey $survey ) { |
58 | 65 | $stats = array(); |
59 | 66 | |
— | — | @@ -64,6 +71,15 @@ |
65 | 72 | return $stats; |
66 | 73 | } |
67 | 74 | |
| 75 | + /** |
| 76 | + * Display a summary table with the provided data. |
| 77 | + * The keys are messages that get prepended with surveys-surveystats-. |
| 78 | + * message => value |
| 79 | + * |
| 80 | + * @since 0.1 |
| 81 | + * |
| 82 | + * @param array $stats |
| 83 | + */ |
68 | 84 | protected function displaySummary( array $stats ) { |
69 | 85 | $out = $this->getOutput(); |
70 | 86 | |
— | — | @@ -90,8 +106,72 @@ |
91 | 107 | $out->addHTML( Html::closeElement( 'table' ) ); |
92 | 108 | } |
93 | 109 | |
| 110 | + protected function displayQuestions( Survey $survey ) { |
| 111 | + $out = $this->getOutput(); |
| 112 | + |
| 113 | + $out->addHTML( '<h2>' . wfMsgHtml( 'surveys-surveystats-questions' ) . '</h2>' ); |
| 114 | + |
| 115 | + $out->addHTML( Html::openElement( 'table', array( 'class' => 'wikitable sortable survey-questions' ) ) ); |
| 116 | + |
| 117 | + $out->addHTML( |
| 118 | + '<thead><tr>' . |
| 119 | + '<th>' . wfMsgHtml( 'surveys-surveystats-question-nr' ) . '</th>' . |
| 120 | + '<th>' . wfMsgHtml( 'surveys-surveystats-question-type' ) . '</th>' . |
| 121 | + '<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-text' ) . '</th>' . |
| 122 | + '<th>' . wfMsgHtml( 'surveys-surveystats-question-answercount' ) . '</th>' . |
| 123 | + //'<th class="unsortable">' . wfMsgHtml( 'surveys-surveystats-question-answers' ) . '</th>' . |
| 124 | + '</tr></thead>' |
| 125 | + ); |
| 126 | + |
| 127 | + $out->addHTML( '<tbody>' ); |
| 128 | + |
| 129 | + foreach ( $survey->getQuestions() as /* SurveyQuestion */ $question ) { |
| 130 | + $this->displayQuestionStats( $question ); |
| 131 | + } |
| 132 | + |
| 133 | + $out->addHTML( '</tbody>' ); |
| 134 | + |
| 135 | + $out->addHTML( Html::closeElement( 'table' ) ); |
| 136 | + } |
| 137 | + |
94 | 138 | protected function displayQuestionStats( SurveyQuestion $question ) { |
| 139 | + static $qNr = 0; |
95 | 140 | |
| 141 | + $out = $this->getOutput(); |
| 142 | + |
| 143 | + $out->addHTML( '<tr>' ); |
| 144 | + |
| 145 | + $out->addHTML( Html::element( |
| 146 | + 'td', |
| 147 | + array( 'data-sort-value' => ++$qNr ), |
| 148 | + wfMsgExt( 'surveys-surveystats-question-#', 'parsemag', $qNr ) |
| 149 | + ) ); |
| 150 | + |
| 151 | + $out->addHTML( Html::element( |
| 152 | + 'td', |
| 153 | + array(), |
| 154 | + wfMsg( SurveyQuestion::getTypeMessage( $question->getField( 'type' ) ) ) |
| 155 | + ) ); |
| 156 | + |
| 157 | + $out->addHTML( Html::element( |
| 158 | + 'td', |
| 159 | + array(), |
| 160 | + $question->getField( 'text' ) |
| 161 | + ) ); |
| 162 | + |
| 163 | + $out->addHTML( Html::element( |
| 164 | + 'td', |
| 165 | + array(), |
| 166 | + SurveyAnswer::count( array( 'question_id' => $question->getId() ) ) |
| 167 | + ) ); |
| 168 | + |
| 169 | +// $out->addHTML( Html::element( |
| 170 | +// 'td', |
| 171 | +// array(), |
| 172 | +// '...' |
| 173 | +// ) ); |
| 174 | + |
| 175 | + $out->addHTML( '</tr>' ); |
96 | 176 | } |
97 | 177 | |
98 | 178 | } |
Index: trunk/extensions/Survey/includes/SurveyQuestion.php |
— | — | @@ -147,4 +147,31 @@ |
148 | 148 | return self::select( null, $conditions ); |
149 | 149 | } |
150 | 150 | |
| 151 | + /** |
| 152 | + * Gets the message for a question type. |
| 153 | + * The message key, not the internationalized string. |
| 154 | + * |
| 155 | + * @since 0.1 |
| 156 | + * |
| 157 | + * @param integer $type |
| 158 | + * |
| 159 | + * @return string |
| 160 | + */ |
| 161 | + public static function getTypeMessage( $type ) { |
| 162 | + static $messageMap = false; |
| 163 | + |
| 164 | + if ( $messageMap === false ) { |
| 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', |
| 172 | + ); |
| 173 | + } |
| 174 | + |
| 175 | + return 'survey-question-type-' . $messageMap[$type]; |
| 176 | + } |
| 177 | + |
151 | 178 | } |