Index: trunk/extensions/ArticleFeedbackv5/api/ApiArticleFeedbackv5.php |
— | — | @@ -153,8 +153,7 @@ |
154 | 154 | * @param $revision int the revision id |
155 | 155 | */ |
156 | 156 | 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 ) { |
159 | 158 | $this->updateRollup( $page, $revision, $type ); |
160 | 159 | } |
161 | 160 | } |
— | — | @@ -166,9 +165,9 @@ |
167 | 166 | * @param $revision int the revision id |
168 | 167 | * @param $type string the type (rating, select, or boolean) |
169 | 168 | */ |
170 | | - private function updateRollup($pageId, $revId, $type) { |
| 169 | + private function updateRollup( $pageId, $revId, $type ) { |
171 | 170 | # sanity check |
172 | | - if ( $type != 'rating' && $type != 'select' && $type != 'boolean' ) { |
| 171 | + if ( $type != 'rating' && $type != 'option_id' && $type != 'boolean' ) { |
173 | 172 | return 0; |
174 | 173 | } |
175 | 174 | |
— | — | @@ -179,13 +178,13 @@ |
180 | 179 | $page_data = array(); |
181 | 180 | $rev_data = array(); |
182 | 181 | $rev_table = 'aft_article_revision_feedback_' |
183 | | - . ( $type == 'select' ? 'select' : 'ratings' ) |
| 182 | + . ( $type == 'option_id' ? 'select' : 'ratings' ) |
184 | 183 | . '_rollup'; |
185 | 184 | $page_table = 'aft_article_feedback_' |
186 | | - . ( $type == 'select' ? 'select' : 'ratings' ) |
| 185 | + . ( $type == 'option_id' ? 'select' : 'ratings' ) |
187 | 186 | . '_rollup'; |
188 | 187 | |
189 | | - if ( $type == 'select' ) { |
| 188 | + if ( $type == 'option_id' ) { |
190 | 189 | $page_prefix = 'afsr_'; |
191 | 190 | $rev_prefix = 'arfsr_'; |
192 | 191 | $select = array( 'aa_field_id', 'aa_response_option_id', 'COUNT(aa_response_option_id) AS earned', '0 AS submits' ); |
— | — | @@ -226,7 +225,7 @@ |
227 | 226 | } |
228 | 227 | |
229 | 228 | foreach ( $rows as $row ) { |
230 | | - if( $type == 'select' ) { |
| 229 | + if( $type == 'option_id' ) { |
231 | 230 | $key = $row->aa_response_option_id; |
232 | 231 | $field = 'option_id'; |
233 | 232 | $value = $row->aa_response_option_id; |
— | — | @@ -267,15 +266,14 @@ |
268 | 267 | $dbw->delete( $rev_table, array( |
269 | 268 | $rev_prefix . 'page_id' => $pageId, |
270 | 269 | $rev_prefix . 'revision_id' => $revId, |
271 | | - $rev_prefix . 'rating_id' => array_keys( $page_data ), |
| 270 | + $rev_prefix . $field => array_keys( $page_data ), |
272 | 271 | ) ); |
273 | 272 | $dbw->insert( $rev_table, $rev_data ); |
274 | 273 | $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 ), |
277 | 276 | ) ); |
278 | 277 | $dbw->insert( $page_table, array_values ( $page_data ) ); |
279 | | - |
280 | 278 | $dbw->commit(); |
281 | 279 | } |
282 | 280 | |
Index: trunk/extensions/ArticleFeedbackv5/api/ApiViewFeedbackArticleFeedbackv5.php |
— | — | @@ -52,8 +52,6 @@ |
53 | 53 | |
54 | 54 | } |
55 | 55 | |
56 | | - # TODO: When there's an overall rating field, use that. |
57 | | - # Using "completeness" for now, because I needed something to test with. |
58 | 56 | public function fetchOverallRating( $pageId ) { |
59 | 57 | $rv = array(); |
60 | 58 | $dbr = wfGetDB( DB_SLAVE ); |
— | — | @@ -65,14 +63,14 @@ |
66 | 64 | ), |
67 | 65 | array( 'arr_page_id' => $pageId, |
68 | 66 | 'arr_rating_id = afi_id', |
69 | | - "afi_name IN ('found', 'complete')" |
| 67 | + "afi_name IN ('found', 'rating')" |
70 | 68 | ) |
71 | 69 | ); |
72 | 70 | |
73 | 71 | foreach( $rows as $row ) { |
74 | 72 | if( $row->afi_name == 'found' ) { |
75 | 73 | $rv['found'] = ( int ) ( 100 * $row->rating ); |
76 | | - } elseif( $row->afi_name == 'complete' ) { |
| 74 | + } elseif( $row->afi_name == 'rating' ) { |
77 | 75 | # Or should this be round/ceil/floor/float? |
78 | 76 | $rv['rating'] = ( int ) $row->rating; |
79 | 77 | } |
— | — | @@ -134,8 +132,9 @@ |
135 | 133 | |
136 | 134 | $rows = $dbr->select( |
137 | 135 | 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', |
140 | 139 | 'aa_response_text', 'aa_response_boolean', |
141 | 140 | 'aa_response_rating', 'aa_response_option_id', |
142 | 141 | 'afi_data_type', 'af_created', 'af_user_text' |
— | — | @@ -144,12 +143,16 @@ |
145 | 144 | __METHOD__, |
146 | 145 | array( 'ORDER BY' => $order ), |
147 | 146 | array( |
148 | | - 'aft_article_answer' => array( |
| 147 | + 'aft_article_field' => array( |
| 148 | + 'JOIN', 'afi_id = aa_field_id' |
| 149 | + ), |
| 150 | + 'aft_article_answer' => array( |
149 | 151 | 'LEFT JOIN', 'af_id = aa_feedback_id' |
150 | 152 | ), |
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 | + ) |
154 | 157 | ) |
155 | 158 | ); |
156 | 159 | |
— | — | @@ -196,10 +199,26 @@ |
197 | 200 | .'</blockquote>'; |
198 | 201 | } |
199 | 202 | |
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 | + } |
203 | 210 | |
| 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 | + |
204 | 223 | private function renderBucket5( $record ) { |
205 | 224 | $name = $record[0]->af_user_text; |
206 | 225 | $rv = "$name had this to say about robocop:<ul>"; |
— | — | @@ -213,8 +232,13 @@ |
214 | 233 | return $rv; |
215 | 234 | } |
216 | 235 | |
| 236 | + private function renderBucket0( $record ) { |
| 237 | + # Future-proof this for when the bucket ID changes. |
| 238 | + return $this->renderBucket6( $record ); |
| 239 | + } |
| 240 | + |
217 | 241 | private function renderBucket6( $record ) { |
218 | | - return 'User was presented with the CTA-only form.'; |
| 242 | + return 'User was not shown a feedback form.'; |
219 | 243 | } |
220 | 244 | |
221 | 245 | /** |