Index: trunk/extensions/CongressLookup/CongressLookup.php |
— | — | @@ -47,6 +47,7 @@ |
48 | 48 | $dir = dirname( __FILE__ ) . '/'; |
49 | 49 | |
50 | 50 | $wgAutoloadClasses['SpecialCongressLookup'] = $dir . 'SpecialCongressLookup.php'; |
| 51 | +$wgAutoloadClasses['CongressLookupDB'] = $dir . 'CongressLookup.db.php'; |
51 | 52 | $wgExtensionMessagesFiles['CongressLookup'] = $dir . 'CongressLookup.i18n.php'; |
52 | 53 | $wgExtensionMessagesFiles['CongressLookupAlias'] = $dir . 'CongressLookup.alias.php'; |
53 | 54 | $wgSpecialPages['CongressLookup'] = 'SpecialCongressLookup'; |
Index: trunk/extensions/CongressLookup/SpecialCongressLookup.php |
— | — | @@ -23,12 +23,30 @@ |
24 | 24 | // Pull in query string parameters |
25 | 25 | $zip = $wgRequest->getVal( 'zip' ); |
26 | 26 | |
27 | | - /* Setup */ |
| 27 | + // Setup |
28 | 28 | $wgOut->setSquidMaxage( $wgCongressLookupMaxAge ); |
29 | 29 | $this->setHeaders(); |
30 | 30 | |
31 | | - /* Display */ |
32 | | - // TODO: Do some work here. |
| 31 | + if ( $zip ) { |
| 32 | + $zip = $this->trimZip( $zip ); |
| 33 | + showMatches( $zip ); |
| 34 | + } |
33 | 35 | } |
34 | 36 | |
| 37 | + /** |
| 38 | + * Given a zip code, output HTML-formatted data for the representatives for that area |
| 39 | + * @param $zip string: A zip code |
| 40 | + * @return true |
| 41 | + */ |
| 42 | + private function showMatches( $zip ) { |
| 43 | + global $wgOut; |
| 44 | + |
| 45 | + $myRepresentative = array(); |
| 46 | + $mySenators = array(); |
| 47 | + $myRepresentative = CongressLookupDB->getRepresentative(); |
| 48 | + $mySenators = CongressLookupDB->getSenators(); |
| 49 | + |
| 50 | + // TODO: stuffz. |
| 51 | + } |
| 52 | + |
35 | 53 | } |
Index: trunk/extensions/CongressLookup/CongressLookup.db.php |
— | — | @@ -0,0 +1,53 @@ |
| 2 | +<?php |
| 3 | +/** |
| 4 | + * Static methods that retrieve information from the database. |
| 5 | + */ |
| 6 | +class CongressLookupDB { |
| 7 | + |
| 8 | + /** |
| 9 | + * Given a zip code, return the data for that zip code's congressional representative |
| 10 | + * @param $zip string |
| 11 | + * @return array |
| 12 | + */ |
| 13 | + public static function getRepresentative( $zip ) { |
| 14 | + $dbr = wfGetDB( DB_SLAVE ); |
| 15 | + |
| 16 | + $zip = $this->trimZip( $zip, 5 ); // Trim it to 5 digit |
| 17 | + $zip = intval( $zip ); // Convert into an integer |
| 18 | + |
| 19 | + $row = $dbr->selectRow( 'cl_zip5', 'rep_id', array( 'zip' => $zip ) ); |
| 20 | + if ( $row ) { |
| 21 | + // TODO: stuffz. |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + /** |
| 26 | + * Given a zip code, return the data for that zip code's senators |
| 27 | + * @param $zip string |
| 28 | + * @return array |
| 29 | + */ |
| 30 | + public static function getSenators( $zip ) { |
| 31 | + $dbr = wfGetDB( DB_SLAVE ); |
| 32 | + |
| 33 | + $zip = $this->trimZip( $zip, 3 ); // Trim it to 3 digit |
| 34 | + $zip = intval( $zip ); // Convert into an integer |
| 35 | + |
| 36 | + $row = $dbr->selectRow( 'cl_zip3', 'state', array( 'zip' => $zip ) ); |
| 37 | + if ( $row ) { |
| 38 | + // TODO: stuffz. |
| 39 | + } |
| 40 | + } |
| 41 | + |
| 42 | + /** |
| 43 | + * Helper method. Trim a zip code, but leave it as a string. |
| 44 | + * @param $zip string: Raw zip code |
| 45 | + * @param $length integer: How many digits we want to return (from the left) |
| 46 | + * @return string The trimmed zip code |
| 47 | + */ |
| 48 | + public static function trimZip( $zip, $length ) { |
| 49 | + $zip = trim( $zip ); |
| 50 | + $zipPieces = explode( '-', $zip, 2 ); |
| 51 | + $zip = substr( $zipPieces[0], 0, $length ); |
| 52 | + return $zip; |
| 53 | + } |
| 54 | +} |
Property changes on: trunk/extensions/CongressLookup/CongressLookup.db.php |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 55 | + native |