r109202 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r109201‎ | r109202 | r109203 >
Date:20:03, 17 January 2012
Author:ariel
Status:ok
Tags:sopa 
Comment:
make the friggin dash in the zip work
Modified paths:
  • /trunk/extensions/CongressLookup/CongressLookup.db.php (modified) (history)

Diff [purge]

Index: trunk/extensions/CongressLookup/CongressLookup.db.php
@@ -21,7 +21,7 @@
2222 table or to have NULL for the rep id. */
2323 if ( ( !$row ) || ( !$row->clz5_rep_id ) ) {
2424 /* if we got the extra 4 digits, use them */
25 - $zip9 = intval( $zip );
 25+ $zip9 = intval( self::trimZip( $zip, 9 ) ); // remove the dash and pad if needed
2626 if ( $zip9 >= 10000 ) {
2727 $row = $dbr->selectRow( 'cl_zip9', 'clz9_rep_id', array( 'clz9_zip' => $zip9 ) );
2828 if ( $row ) {
@@ -131,14 +131,22 @@
132132 */
133133 public static function trimZip( $zip, $length ) {
134134 $zip = trim( $zip );
135 - if ( strlen( $zip ) < 5 ) {
136 - $zip = sprintf( "%05d", $zip );
 135+ if ( strpos( $zip, '-' ) === False ) {
 136+ if ( strlen( $zip ) < 5 ) {
 137+ $zip = sprintf( "%05d", $zip );
 138+ }
 139+ elseif ( strlen( $zip ) > 5 ) {
 140+ $zip = sprintf( "%09d", $zip );
 141+ }
137142 }
138 - elseif ( strlen( $zip ) > 5 ) {
139 - $zip = sprintf( "%09d", $zip );
 143+ else {
 144+ $zipPieces = explode( '-', $zip, 2 );
 145+ if (! $zipPieces[1]) {
 146+ $zipPieces[1] = 0;
 147+ }
 148+ $zip = sprintf( "%05d%04d", $zipPieces[0], $zipPieces[1] );
140149 }
141 - $zipPieces = explode( '-', $zip, 2 );
142 - $zip = substr( $zipPieces[0], 0, $length );
 150+ $zip = substr( $zip, 0, $length );
143151 return $zip;
144152 }
145153 }

Follow-up revisions

RevisionCommit summaryAuthorDate
r109237Revert r109153, r109202, r109225. Dropping support for 9-digit zip codes to p...awjrichards22:52, 17 January 2012
r109240Revert r109153, r109202, r109225. Dropping support for 9-digit zip codes to p...awjrichards23:01, 17 January 2012

Status & tagging log