r104711 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r104710‎ | r104711 | r104712 >
Date:18:01, 30 November 2011
Author:gregchiasson
Status:deferred
Tags:
Comment:
AFTv5: Render all feedback options on the feedback page, and fix the select rollups.
Modified paths:
  • /trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php (modified) (history)
  • /trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php (modified) (history)

Diff [purge]

Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php
@@ -153,8 +153,7 @@
154154 * @param $revision int the revision id
155155 */
156156 public function updateRollupTables( $page, $revision ) {
157 -# foreach( array( 'rating', 'boolean', 'select' ) as $type ) {
158 - foreach( array( 'rating', 'boolean' ) as $type ) {
 157+ foreach( array( 'rating', 'boolean', 'option_id' ) as $type ) {
159158 $this->updateRollup( $page, $revision, $type );
160159 }
161160 }
@@ -166,9 +165,9 @@
167166 * @param $revision int the revision id
168167 * @param $type string the type (rating, select, or boolean)
169168 */
170 - private function updateRollup($pageId, $revId, $type) {
 169+ private function updateRollup( $pageId, $revId, $type ) {
171170 # sanity check
172 - if ( $type != 'rating' && $type != 'select' && $type != 'boolean' ) {
 171+ if ( $type != 'rating' && $type != 'option_id' && $type != 'boolean' ) {
173172 return 0;
174173 }
175174
@@ -179,13 +178,13 @@
180179 $page_data = array();
181180 $rev_data = array();
182181 $rev_table = 'aft_article_revision_feedback_'
183 - . ( $type == 'select' ? 'select' : 'ratings' )
 182+ . ( $type == 'option_id' ? 'select' : 'ratings' )
184183 . '_rollup';
185184 $page_table = 'aft_article_feedback_'
186 - . ( $type == 'select' ? 'select' : 'ratings' )
 185+ . ( $type == 'option_id' ? 'select' : 'ratings' )
187186 . '_rollup';
188187
189 - if ( $type == 'select' ) {
 188+ if ( $type == 'option_id' ) {
190189 $page_prefix = 'afsr_';
191190 $rev_prefix = 'arfsr_';
192191 $select = array( 'aa_field_id', 'aa_response_option_id', 'COUNT(aa_response_option_id) AS earned', '0 AS submits' );
@@ -226,7 +225,7 @@
227226 }
228227
229228 foreach ( $rows as $row ) {
230 - if( $type == 'select' ) {
 229+ if( $type == 'option_id' ) {
231230 $key = $row->aa_response_option_id;
232231 $field = 'option_id';
233232 $value = $row->aa_response_option_id;
@@ -267,15 +266,14 @@
268267 $dbw->delete( $rev_table, array(
269268 $rev_prefix . 'page_id' => $pageId,
270269 $rev_prefix . 'revision_id' => $revId,
271 - $rev_prefix . 'rating_id' => array_keys( $page_data ),
 270+ $rev_prefix . $field => array_keys( $page_data ),
272271 ) );
273272 $dbw->insert( $rev_table, $rev_data );
274273 $dbw->delete( $page_table, array(
275 - $page_prefix . 'page_id' => $pageId,
276 - $page_prefix . 'rating_id' => array_keys( $page_data ),
 274+ $page_prefix . 'page_id' => $pageId,
 275+ $page_prefix . $field => array_keys( $page_data ),
277276 ) );
278277 $dbw->insert( $page_table, array_values ( $page_data ) );
279 -
280278 $dbw->commit();
281279 }
282280
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php
@@ -52,8 +52,6 @@
5353
5454 }
5555
56 - # TODO: When there's an overall rating field, use that.
57 - # Using "completeness" for now, because I needed something to test with.
5856 public function fetchOverallRating( $pageId ) {
5957 $rv = array();
6058 $dbr = wfGetDB( DB_SLAVE );
@@ -65,14 +63,14 @@
6664 ),
6765 array( 'arr_page_id' => $pageId,
6866 'arr_rating_id = afi_id',
69 - "afi_name IN ('found', 'complete')"
 67+ "afi_name IN ('found', 'rating')"
7068 )
7169 );
7270
7371 foreach( $rows as $row ) {
7472 if( $row->afi_name == 'found' ) {
7573 $rv['found'] = ( int ) ( 100 * $row->rating );
76 - } elseif( $row->afi_name == 'complete' ) {
 74+ } elseif( $row->afi_name == 'rating' ) {
7775 # Or should this be round/ceil/floor/float?
7876 $rv['rating'] = ( int ) $row->rating;
7977 }
@@ -134,8 +132,9 @@
135133
136134 $rows = $dbr->select(
137135 array( 'aft_article_feedback', 'aft_article_answer',
138 - 'aft_article_field' ),
139 - array( 'af_id', 'af_bucket_id', 'afi_name',
 136+ 'aft_article_field', 'aft_article_field_option'
 137+ ),
 138+ array( 'af_id', 'af_bucket_id', 'afi_name', 'afo_name',
140139 'aa_response_text', 'aa_response_boolean',
141140 'aa_response_rating', 'aa_response_option_id',
142141 'afi_data_type', 'af_created', 'af_user_text'
@@ -144,12 +143,16 @@
145144 __METHOD__,
146145 array( 'ORDER BY' => $order ),
147146 array(
148 - 'aft_article_answer' => array(
 147+ 'aft_article_field' => array(
 148+ 'JOIN', 'afi_id = aa_field_id'
 149+ ),
 150+ 'aft_article_answer' => array(
149151 'LEFT JOIN', 'af_id = aa_feedback_id'
150152 ),
151 - 'aft_article_field' => array(
152 - 'JOIN', 'afi_id = aa_field_id'
153 - ),
 153+ 'aft_article_field_option' => array(
 154+ 'LEFT JOIN',
 155+ 'aa_response_option_id = afo_option_id'
 156+ )
154157 )
155158 );
156159
@@ -196,10 +199,26 @@
197200 .'</blockquote>';
198201 }
199202
200 - private function renderBucket2( $record ) { }
201 - private function renderBucket3( $record ) { }
202 - private function renderBucket4( $record ) { }
 203+ private function renderBucket2( $record ) {
 204+ $name = $record[0]->af_user_text;
 205+ $type = $record['tag']->afo_name;
 206+ return "$name had a $type:"
 207+ .'<blockquote>'.$record['comment']->aa_response_text
 208+ .'</blockquote>';
 209+ }
203210
 211+ private function renderBucket3( $record ) {
 212+ $name = $record[0]->af_user_text;
 213+ $rating = $record['rating']->aa_response_rating;
 214+ return "$name rated this page $rating/5:"
 215+ .'<blockquote>'.$record['comment']->aa_response_text
 216+ .'</blockquote>';
 217+ }
 218+
 219+ private function renderBucket4( $record ) {
 220+ return 'User was presented with the CTA-only form.';
 221+ }
 222+
204223 private function renderBucket5( $record ) {
205224 $name = $record[0]->af_user_text;
206225 $rv = "$name had this to say about robocop:<ul>";
@@ -213,8 +232,13 @@
214233 return $rv;
215234 }
216235
 236+ private function renderBucket0( $record ) {
 237+ # Future-proof this for when the bucket ID changes.
 238+ return $this->renderBucket6( $record );
 239+ }
 240+
217241 private function renderBucket6( $record ) {
218 - return 'User was presented with the CTA-only form.';
 242+ return 'User was not shown a feedback form.';
219243 }
220244
221245 /**

Status & tagging log