Index: trunk/extensions/Survey/api/ApiQuerySurveys.php |
— | — | @@ -35,36 +35,53 @@ |
36 | 36 | $this->dieUsage( wfMsgExt( 'survey-err-ids-xor-names' ), 'ids-xor-names' ); |
37 | 37 | } |
38 | 38 | |
39 | | - $surveys = array(); |
40 | | - |
41 | | - // TODO |
42 | 39 | |
| 40 | + $this->addTables( 'surveys' ); |
| 41 | + |
| 42 | + $this->addFields( 'survey_id' ); |
| 43 | + |
43 | 44 | 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'] ) ); |
51 | 46 | } |
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'] ) ); |
61 | 49 | } |
| 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 | + } |
62 | 79 | |
63 | | - $this->getResult()->setIndexedTagName( $surveys, 'survey' ); |
| 80 | + $this->getResult()->setIndexedTagName( $resultSurveys, 'survey' ); |
64 | 81 | |
65 | 82 | $this->getResult()->addValue( |
66 | 83 | null, |
67 | 84 | 'surveys', |
68 | | - $surveys |
| 85 | + $resultSurveys |
69 | 86 | ); |
70 | 87 | } |
71 | 88 | |
Index: trunk/extensions/Survey/resources/jquery.survey.js |
— | — | @@ -61,11 +61,12 @@ |
62 | 62 | this.getSurveyQuestion = function( question ) { |
63 | 63 | $q = $( '<div />' ); |
64 | 64 | |
65 | | - $q.append( '<hr />' ); |
66 | 65 | $q.append( $( '<p />' ).text( question.text ) ); |
67 | 66 | |
68 | 67 | $q.append( this.getQuestionInput( question ) ) |
69 | 68 | |
| 69 | + $q.append( '<hr />' ); |
| 70 | + |
70 | 71 | return $q; |
71 | 72 | }; |
72 | 73 | |