Index: trunk/extensions/CongressLookup/CongressLookup.db.php |
— | — | @@ -16,42 +16,58 @@ |
17 | 17 | $zip = self::trimZip( $zip, 5 ); // Trim it to 5 digit |
18 | 18 | $zip = intval( $zip ); // Convert into an integer |
19 | 19 | |
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__ |
54 | 56 | ); |
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 | + } |
56 | 72 | } |
57 | 73 | } |
58 | 74 | return $repData; |
Index: trunk/extensions/CongressLookup/patches/CongressLookup.sql |
— | — | @@ -36,3 +36,4 @@ |
37 | 37 | `clz5_zip` int(5) unsigned NOT NULL, |
38 | 38 | `clz5_rep_id` int(10) unsigned DEFAULT NULL |
39 | 39 | ) /*$wgDBTableOptions*/; |
| 40 | +CREATE INDEX /*i*/clz5_zip ON /*$wgDBprefix*/cl_zip5 (clz5_zip); |