r96756 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96755‎ | r96756 | r96757 >
Date:23:18, 10 September 2011
Author:jeroendedauw
Status:resolved (Comments)
Tags:
Comment:
work on special:surveystats
Modified paths:
  • /trunk/extensions/Survey/Survey.i18n.php (modified) (history)
  • /trunk/extensions/Survey/includes/SurveyQuestion.php (modified) (history)
  • /trunk/extensions/Survey/specials/SpecialSurveyStats.php (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/Survey.i18n.php
@@ -36,6 +36,14 @@
3737 'survey-err-duplicate-name' => 'There already is a survey with name "$1"',
3838 'survey-err-ids-xor-names' => 'You need to provide either the ids or the names of the surveys to query',
3939
 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+
4048 // Special:Surveys
4149 'surveys-special-addnew' => 'Add a new survey',
4250 'surveys-special-namedoc' => 'Enter the name for the new survey.',
@@ -73,6 +81,13 @@
7482 'surveys-surveystats-submissioncount' => 'Number of submissions',
7583 'surveys-surveystats-enabled' => 'Enabled',
7684 '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',
7792
7893 // Special:Survey
7994 'surveys-special-unknown-name' => 'There is no survey with the requested name.',
@@ -81,12 +96,6 @@
8297 'survey-special-label-button' => 'Add question',
8398 'survey-special-label-addquestion' => 'New question',
8499 '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',
91100 'survey-question-label-nr' => 'Question #$1',
92101 'survey-special-label-required' => 'Question is required',
93102 'survey-special-label-type' => 'Question type',
Index: trunk/extensions/Survey/specials/SpecialSurveyStats.php
@@ -48,11 +48,18 @@
4949
5050 protected function displayStats( Survey $survey ) {
5151 $this->displaySummary( $this->getSummaryData( $survey ) );
52 -
53 - // TODO: magic
54 - //$this->displayQuestionStats();
 52+ $this->displayQuestions( $survey );
5553 }
5654
 55+ /**
 56+ * Gets the summary data.
 57+ *
 58+ * @since 0.1
 59+ *
 60+ * @param Survey $survey
 61+ *
 62+ * @return array
 63+ */
5764 protected function getSummaryData( Survey $survey ) {
5865 $stats = array();
5966
@@ -64,6 +71,15 @@
6572 return $stats;
6673 }
6774
 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+ */
6884 protected function displaySummary( array $stats ) {
6985 $out = $this->getOutput();
7086
@@ -90,8 +106,72 @@
91107 $out->addHTML( Html::closeElement( 'table' ) );
92108 }
93109
 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+
94138 protected function displayQuestionStats( SurveyQuestion $question ) {
 139+ static $qNr = 0;
95140
 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>' );
96176 }
97177
98178 }
Index: trunk/extensions/Survey/includes/SurveyQuestion.php
@@ -147,4 +147,31 @@
148148 return self::select( null, $conditions );
149149 }
150150
 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+
151178 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r96781Follow up to r96756;jeroendedauw14:43, 11 September 2011

Comments

#Comment by Nikerabbit (talk | contribs)   09:50, 11 September 2011
+	'survey-question-type-number' => 'Number',

Please provide documentation whether this means a digit (8) or any number (88).

+	'surveys-surveystats-question-answercount' => 'Amount of answers',

Shouldn't that be number of answers, since answers are countable?

+	'surveys-surveystats-question-answers' => 'Most provided answers',

Would be nice to document the context where this message is used (why not for the rest of messages too).

#Comment by Jeroen De Dauw (talk | contribs)   14:44, 11 September 2011

Points 0 and 2 fixed by r96781. Not sure about the second one. Is amount not valid for some countable stuff?! Seems ok to me, but then again I'm not a native English speaker so could very well be wrong.

#Comment by Duplicatebug (talk | contribs)   23:24, 24 November 2011
+	'surveys-surveystats-question-#' => '$1',

Using a # inside the message key is a bad idea, because it is not possible to customize this message. # is and should not be a valid character in titles.

Status & tagging log