r109241 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109240‎ | r109241 | r109242 >
Date:23:04, 17 January 2012
Author:awjrichards
Status:resolved (Comments)
Tags:
Comment:
Re-added accidentally deleted index creation line for cl_zip5; made CongressLookupDb::getRepresentative() support fetching multiple reps since we dropped zip9 support
Modified paths:
  • /trunk/extensions/CongressLookup/CongressLookup.db.php (modified) (history)
  • /trunk/extensions/CongressLookup/patches/CongressLookup.sql (modified) (history)

Diff [purge]

Index: trunk/extensions/CongressLookup/CongressLookup.db.php
@@ -16,42 +16,58 @@
1717 $zip = self::trimZip( $zip, 5 ); // Trim it to 5 digit
1818 $zip = intval( $zip ); // Convert into an integer
1919
20 - $row = $dbr->selectRow( 'cl_zip5', 'clz5_rep_id', array( 'clz5_zip' => $zip ) );
21 - if ( $row ) {
22 - $rep_id = $row->clz5_rep_id;
23 - $res = $dbr->select(
24 - 'cl_house',
25 - array(
26 - 'clh_bioguideid',
27 - 'clh_gender',
28 - 'clh_name',
29 - 'clh_title',
30 - 'clh_state',
31 - 'clh_district',
32 - 'clh_phone',
33 - 'clh_fax',
34 - 'clh_contactform',
35 - 'clh_twitter'
36 - ),
37 - array(
38 - 'clh_id' => $rep_id,
39 - ),
40 - __METHOD__
41 - );
42 - foreach ( $res as $row ) {
43 - $oneHouseRep = array(
44 - 'bioguideid' => $row->clh_bioguideid,
45 - 'gender' => $row->clh_gender,
46 - 'name' => $row->clh_name,
47 - 'title' => $row->clh_title,
48 - 'state' => $row->clh_state,
49 - 'district' => $row->clh_district,
50 - 'phone' => $row->clh_phone,
51 - 'fax' => $row->clh_fax,
52 - 'contactform' => $row->clh_contactform,
53 - 'twitter' => $row->clh_twitter,
 20+ /**
 21+ * Select all possible reps for this 5 digit zip code.
 22+ * In some cases, there is more than one representative for a given
 23+ * 5-digit zip code, since district lines are drawn to the 9-digit zip
 24+ * level. In the event that there are multiple reps for this 5 digit
 25+ * zip, we'll return them all. It will be up to the display layer
 26+ * to determine how to display this to the user.
 27+ */
 28+ $rep_results = $dbr->select(
 29+ 'cl_zip5',
 30+ 'clz5_rep_id',
 31+ array( 'clz5_zip' => $zip ),
 32+ __MEHOTD__
 33+ );
 34+
 35+ if ( $rep_results ) {
 36+ foreach ( $rep_results as $rep_row ) {
 37+ $rep_id = $rep_row->clz5_rep_id;
 38+ $res = $dbr->select(
 39+ 'cl_house',
 40+ array(
 41+ 'clh_bioguideid',
 42+ 'clh_gender',
 43+ 'clh_name',
 44+ 'clh_title',
 45+ 'clh_state',
 46+ 'clh_district',
 47+ 'clh_phone',
 48+ 'clh_fax',
 49+ 'clh_contactform',
 50+ 'clh_twitter'
 51+ ),
 52+ array(
 53+ 'clh_id' => $rep_id,
 54+ ),
 55+ __METHOD__
5456 );
55 - $repData[] = $oneHouseRep;
 57+ foreach ( $res as $row ) {
 58+ $oneHouseRep = array(
 59+ 'bioguideid' => $row->clh_bioguideid,
 60+ 'gender' => $row->clh_gender,
 61+ 'name' => $row->clh_name,
 62+ 'title' => $row->clh_title,
 63+ 'state' => $row->clh_state,
 64+ 'district' => $row->clh_district,
 65+ 'phone' => $row->clh_phone,
 66+ 'fax' => $row->clh_fax,
 67+ 'contactform' => $row->clh_contactform,
 68+ 'twitter' => $row->clh_twitter,
 69+ );
 70+ $repData[] = $oneHouseRep;
 71+ }
5672 }
5773 }
5874 return $repData;
Index: trunk/extensions/CongressLookup/patches/CongressLookup.sql
@@ -36,3 +36,4 @@
3737 `clz5_zip` int(5) unsigned NOT NULL,
3838 `clz5_rep_id` int(10) unsigned DEFAULT NULL
3939 ) /*$wgDBTableOptions*/;
 40+CREATE INDEX /*i*/clz5_zip ON /*$wgDBprefix*/cl_zip5 (clz5_zip);

Follow-up revisions

RevisionCommit summaryAuthorDate
r109245adding twitter IDs, fixing typokaldari23:18, 17 January 2012

Comments

#Comment by NeilK (talk | contribs)   00:10, 18 January 2012

There's a typo, here __MEHOTD__ -- marking fixme

Seems weird to do this with two queries, isn't that better done with joins? But okay.

Status & tagging log