r96048 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r96047‎ | r96048 | r96049 >
Date:21:45, 1 September 2011
Author:jeroendedauw
Status:deferred
Tags:
Comment:
work on survey query api
Modified paths:
  • /trunk/extensions/Survey/api/ApiQuerySurveys.php (modified) (history)
  • /trunk/extensions/Survey/resources/jquery.survey.js (modified) (history)

Diff [purge]

Index: trunk/extensions/Survey/api/ApiQuerySurveys.php
@@ -35,36 +35,53 @@
3636 $this->dieUsage( wfMsgExt( 'survey-err-ids-xor-names' ), 'ids-xor-names' );
3737 }
3838
39 - $surveys = array();
40 -
41 - // TODO
4239
 40+ $this->addTables( 'surveys' );
 41+
 42+ $this->addFields( 'survey_id' );
 43+
4344 if ( isset( $params['ids'] ) ) {
44 - foreach ( $params['ids'] as $surveyId ) {
45 - $survey = Survey::newFromId( $surveyId, $params['incquestions'] == 1 );
46 -
47 - if ( $survey !== false ) {
48 - $surveys[] = $this->getSurveyData( $survey );
49 - }
50 - }
 45+ $this->addWhere( array( 'survey_id' => $params['ids'] ) );
5146 }
52 -
53 - if ( isset( $params['names'] ) ) {
54 - foreach ( $params['names'] as $surveyName ) {
55 - $survey = Survey::newFromName( $surveyName, $params['incquestions'] == 1 );
56 -
57 - if ( $survey !== false ) {
58 - $surveys[] = $this->getSurveyData( $survey );
59 - }
60 - }
 47+ else {
 48+ $this->addWhere( array( 'survey_name' => $params['names'] ) );
6149 }
 50+
 51+ if ( isset( $params['enabled'] ) ) {
 52+ $this->addWhere( array( 'survey_enabled' => $params['enabled'] ) );
 53+ }
 54+
 55+ if ( isset( $params['continue'] ) ) {
 56+ $this->addWhere( 'survey_id >= ' . wfGetDB( DB_SLAVE )->addQuotes( $params['continue'] ) );
 57+ }
 58+
 59+ $this->addOption( 'LIMIT', $params['limit'] + 1 );
 60+ $this->addOption( 'ORDER BY', 'survey_id ASC' );
 61+
 62+ $surveys = $this->select( __METHOD__ );
 63+ $count = 0;
 64+ $resultSurveys = array();
 65+
 66+ foreach ( $surveys as $survey ) {
 67+ if ( ++$count > $params['limit'] ) {
 68+ // We've reached the one extra which shows that
 69+ // there are additional pages to be had. Stop here...
 70+ $this->setContinueEnumParameter( 'continue', $survey->survey_id );
 71+ break;
 72+ }
 73+
 74+ $resultSurveys[] = $this->getSurveyData( Survey::newFromId(
 75+ $survey->survey_id,
 76+ $params['incquestions'] == 1
 77+ ) );
 78+ }
6279
63 - $this->getResult()->setIndexedTagName( $surveys, 'survey' );
 80+ $this->getResult()->setIndexedTagName( $resultSurveys, 'survey' );
6481
6582 $this->getResult()->addValue(
6683 null,
6784 'surveys',
68 - $surveys
 85+ $resultSurveys
6986 );
7087 }
7188
Index: trunk/extensions/Survey/resources/jquery.survey.js
@@ -61,11 +61,12 @@
6262 this.getSurveyQuestion = function( question ) {
6363 $q = $( '<div />' );
6464
65 - $q.append( '<hr />' );
6665 $q.append( $( '<p />' ).text( question.text ) );
6766
6867 $q.append( this.getQuestionInput( question ) )
6968
 69+ $q.append( '<hr />' );
 70+
7071 return $q;
7172 };
7273

Status & tagging log