Location: PHPKode > scripts > IMC Objects > imc-objects/class.imcPropertyADR.php
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4: */
// +----------------------------------------------------------------------+
// | PHP version 4                                                        |
// +----------------------------------------------------------------------+
// | Copyright (c) 1997-2003 The PHP Group                                |
// +----------------------------------------------------------------------+
// | This source file is subject to version 2.0 of the PHP license,       |
// | that is bundled with this package in the file LICENSE, and is        |
// | available through the world-wide-web at                              |
// | http://www.php.net/license/2_02.txt.                                 |
// | If you did not receive a copy of the PHP license and are unable to   |
// | obtain it through the world-wide-web, please send a note to          |
// | hide@address.com so we can mail you a copy immediately.               |
// +----------------------------------------------------------------------+
// | Authors: Andreas Haberstroh <hide@address.com>                      |
// +----------------------------------------------------------------------+
//
// $Id$

require_once('class.imcProperty.php');

/*
    Type name: ADR

    Type purpose: To specify the components of the delivery address for
    the vCard object.

    Type encoding: 8bit

    Type value: A single structured text value, separated by the
    SEMI-COLON character (ASCII decimal 59).

    Type special notes: The structured type value consists of a sequence
    of address components. The component values MUST be specified in
    their corresponding position. The structured type value corresponds,
    in sequence, to the post office box; the extended address; the street
    address; the locality (e.g., city); the region (e.g., state or
    province); the postal code; the country name. When a component value
    is missing, the associated component separator MUST still be
    specified.

    The text components are separated by the SEMI-COLON character (ASCII
    decimal 59). Where it makes semantic sense, individual text
    components can include multiple text values (e.g., a "street"
    component with multiple lines) separated by the COMMA character
    (ASCII decimal 44).

    The type can include the type parameter "TYPE" to specify the
    delivery address type. The TYPE parameter values can include "dom" to
    indicate a domestic delivery address; "intl" to indicate an
    international delivery address; "postal" to indicate a postal
    delivery address; "parcel" to indicate a parcel delivery address;
    "home" to indicate a delivery address for a residence; "work" to
    indicate delivery address for a place of work; and "pref" to indicate
    the preferred delivery address when more than one address is
    specified. These type parameter values can be specified as a
    parameter list (i.e., "TYPE=dom;TYPE=postal") or as a value list
    (i.e., "TYPE=dom,postal"). This type is based on semantics of the
    X.520 geographical and postal addressing attributes. The default is
    "TYPE=intl,postal,parcel,work". The default can be overridden to some
    other set of values by specifying one or more alternate values. For
    example, the default can be reset to "TYPE=dom,postal,work,home" to
    specify a domestic delivery address for postal delivery to a
    residence that is also used for work.

    Type example: In this example the post office box and the extended
    address are absent.

    ADR;TYPE=dom,home,postal,parcel:;;123 Main
        Street;Any Town;CA;91921-1234
*/
class   imcPropertyAdr  extends  imcProperty
{
    // {{{ imcPropertyN
    /**
    *   Default constructor.
    */
    function    imcPropertyAdr() {
        // normally, we don't have any endcoding
        $this->encoding_func = 'none';

        // make space for the 7 pieces of the ADR property
        $this->value = array('','','','','','','');
    }

    // {{{ setEncodedValue
    /**
    *   Decodes a ADR property value and splits it into the proper 
    *   fields of our value array.
    *   
    *   @param  string  ADR encoded value
    *   @see    getEncodedValue
    */
    function    setEncodedValue($string) {

        $adr = explode(";", $this->_decodeValue($string));

        $this->value[0] = $adr[0];
        $this->value[1] = $adr[1];
        $this->value[2] = $adr[2];
        $this->value[3] = $adr[3];
        $this->value[4] = $adr[4];
        $this->value[5] = $adr[5];
        $this->value[6] = $adr[6];

    }

    // {{{ getEncodedValue
    /**
    *   Encodes our value array into a ADR property value.
    *   
    *   @return string  ADR encoded value
    *   @see    setEncodedValue
    */
    function    getEncodedValue() {

        $value = implode(";", $this->value);
        // strip off the extra semicolons at the end of the value
        while ( $value[strlen($value) - 1] == ';' ) {
            $value = substr($value, 0, strlen($value) - 1);
        }
        return $value;
    }

    /**
    *   Sets the offset of the value into the address array value
    *
    *   @param  string  Value to set
    *   @param  integer Offset in the array
    */
    function    _set_adr_offset( $value, $offset ) {

        if( !is_array($this->value) )
            $this->value = array('','','','','','','');

        $this->value[$offset] = $value;
    }

    /**
    *   Gets the offset of the value from the address array value
    *
    *   @param  integer Offset in the array
    *   @return string  Value to get
    */
    function    _get_adr_offset( $offset ) {

        if( !is_array($this->value) )
            $this->value = array('','','','','','','');

        return $this->value[$offset];
    }

    // {{{ setPostOfficeAddress
    /**
    *   Sets the Post Office Box value of the address
    *
    *   @param  string  Value to set
    *   @see    getPostOfficeAddress
    */
    function    setPostOfficeAddress( $adr ) {

        $this->_set_adr_offset($adr, 0 );
    }

    // {{{ getPostOfficeAddress
    /**
    *   Gets the Post Office Box value of the address
    *
    *   @return string  Value to get
    *   @see    setPostOfficeAddress
    */
    function    getPostOfficeAddress() {

        return $this->_get_adr_offset( 0 );
    }

    // {{{ setExtendedAddress
    /**
    *   Sets the Extended address value of the address.
    *   I have NO idea what an extended address is, other
    *   than a "second" address line.
    *
    *   @param  string  Value to set
    *   @see    getExtendedAddress
    */
    function    setExtendedAddress( $adr ) {

        $this->_set_adr_offset($adr, 1 );
    }

    // {{{ getExtendedAddress
    /**
    *   Gets the Extended address value of the address.
    *
    *   @return string  Value to get
    *   @see    setExtendedAddress
    */
    function    getExtendedAddress() {

        return $this->_get_adr_offset( 1 );
    }

    // {{{ setStreetAddress
    /**
    *   Sets the street value of the address.
    *
    *   @param  string  Value to set
    *   @see    getStreetAddress
    */
    function    setStreetAddress( $adr ) {
        $this->_set_adr_offset($adr, 2 );
    }

    // {{{ getStreetAddress
    /**
    *   Gets the street value of the address.
    *
    *   @return string  Value to get
    *   @see    setStreetAddress
    */
    function    getStreetAddress() {

        return $this->_get_adr_offset( 2 );
    }

    // {{{ setLocality
    /**
    *   Sets the locality value of the address.
    *   This is normally the City
    *
    *   @param  string  Value to set
    *   @see    getLocality
    */
    function    setLocality( $adr ) {

        $this->_set_adr_offset($adr, 3 );
    }

    // {{{ getLocality
    /**
    *   Gets the locality value of the address.
    *   This is normally the City
    *
    *   @return string  Value to get
    *   @see    setLocality
    */
    function    getLocality() {

        return $this->_get_adr_offset( 3 );
    }

    // {{{ setRegion
    /**
    *   Sets the region value of the address.
    *   This is normally the State
    *
    *   @param  string  Value to set
    *   @see    getRegion
    */
    function    setRegion($adr) {
        
        $this->_set_adr_offset($adr, 4 );
    }

    // {{{ getRegion
    /**
    *   Sets the region value of the address.
    *
    *   @return string  Value to get
    *   @see    setRegion
    */
    function    getRegion() {

        return $this->_get_adr_offset( 4 );
    }

    // {{{ setPostalCode
    /**
    *   Sets the postal code value of the address.
    *   This is normally the Zip code
    *
    *   @param  string  Value to set
    *   @see    getPostalCode
    */
    function    setPostalCode($adr) {

        $this->_set_adr_offset($adr, 5 );
    }

    // {{{ getPostalCode
    /**
    *   Gets the postal code value of the address.
    *
    *   @return string  Value to get
    *   @see    setPostalCode
    */
    function    getPostalCode() {

        return $this->_get_adr_offset( 5 );
    }

    // {{{ setCountry
    /**
    *   Sets the country value of the address.
    *
    *   @param  string  Value to set
    *   @see    getCountry
    */
    function    setCountry($adr) {

        $this->_set_adr_offset($adr, 6 );
    }

    // {{{ getCountry
    /**
    *   Gets the country value of the address.
    *
    *   @return string  Value to get
    *   @see    setCountry
    */
    function    getCountry() {

        return $this->_get_adr_offset( 6 );
    }

}

?>
Return current item: IMC Objects