Return to Snippet

Revision: 29021
at July 20, 2010 00:38 by iloveitaly


Initial Code
public function __get($key) {
	if($key == 'short_address') {
		// this is tricky b/c the map is international
		// if the location is US based then we want to display an identifier similiar to: St. Joe's in Downingtown PA
		// if the location is non-USA based (and either city or providence is not available) then we want to display: St. Joe's in Downingtown USA
		
		return $this->name.' in '.$this->city.' '.$this->providence.
			(empty($this->city) || empty($this->providence) ? ' '.$this->country : '');
	} else if($key == 'full_address') {
		// target format for US based addresses:
		//	300 Road Street
		//	Town PA 19335
		// target format for non-US based addresses
		//	address1
		//	City Providence Postal Code Country
		
		// the trims handle edge cases when there is not enough information to propertly display an address
		
		if($this->country == 'US') {
			return trim(trim($this->address1."\n".$this->address2)."\n".$this->city)." ".$this->providence." ".$this->postal_code;
		} else {
			return $this->address1."\n".$this->address2."\n".$this->city." ".$this->providence." ".$this->postal_code." ".$this->country;
		}
	}
	
	return parent::__get($key);
}

Initial URL

                                

Initial Description
Assumes that the record has a `name` field which represents the name of the location and always has a defined two character `country` field.

Initial Title
Short + Long Address Formatting From Address Information

Initial Tags
format

Initial Language
PHP