Subversion Repositories googlemaps

[/] [trunk/] [extension/] [gmaplocation/] [datatypes/] [ezgmaplocation/] [ezgmaplocationtype.php] - Diff between revs 1 and 4

Show entire file | Ignore whitespace | Details | Blame | View Log

Rev 1 Rev 4
Line 1... Line 1...
<?php
<?php
//
//
// Definition of eZGmapLocationType class
// Definition of eZGmapLocationType class
//
//
// SOFTWARE NAME: Blend Gmap Location Class
// SOFTWARE NAME: Blend Gmap Location Class
// SOFTWARE RELEASE: 0.3
// SOFTWARE RELEASE: 0.5
// COPYRIGHT NOTICE: Copyright (C) 2006 Blend Interactive
// COPYRIGHT NOTICE: Copyright (C) 2006-2009 Blend Interactive
// SOFTWARE LICENSE: GNU General Public License v2.0
// SOFTWARE LICENSE: GNU General Public License v2.0
// NOTICE: >
// NOTICE: >
//   This program is free software; you can redistribute it and/or
//   This program is free software; you can redistribute it and/or
//   modify it under the terms of version 2.0  of the GNU General
//   modify it under the terms of version 2.0  of the GNU General
//   Public License as published by the Free Software Foundation.
//   Public License as published by the Free Software Foundation.
//
//
//   This program is distributed in the hope that it will be useful,
//   This program is distributed in the hope that it will be useful,
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//   GNU General Public License for more details.
//   GNU General Public License for more details.
//
//
//   You should have received a copy of version 2.0 of the GNU General
//   You should have received a copy of version 2.0 of the GNU General
//   Public License along with this program; if not, write to the Free
//   Public License along with this program; if not, write to the Free
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
//   MA 02110-1301, USA.
//   MA 02110-1301, USA.
//
//
Line 31... Line 31...
  \class eZGmapLocationType ezgmaplocationtype.php
  \class eZGmapLocationType ezgmaplocationtype.php
  \ingroup eZDatatype
  \ingroup eZDatatype
  \brief The class eZGmapLocationType does
  \brief The class eZGmapLocationType does
 
 
*/
*/
include_once( "kernel/classes/ezdatatype.php" );
 
include_once( "extension/gmaplocation/datatypes/ezgmaplocation/ezgmaplocation.php" );
 
 
 
define( "EZ_GMAPLOCATION_DEFAULT_NAME_VARIABLE", "_ezgmaplocation_default_name_" );
 
 
 
 
 
define( "EZ_DATATYPESTRING_GMAPLOCATION", "ezgmaplocation" );
 
 
 
class eZGmapLocationType extends eZDataType
class eZGmapLocationType extends eZDataType
{
{
 
    const DATA_TYPE_STRING = "ezgmaplocation";
 
 
    /*!
    /*!
     Constructor
     Constructor
    */
    */
    function eZGmapLocationType()
    function __construct()
    {
    {
        $this->eZDataType( EZ_DATATYPESTRING_GMAPLOCATION, ezi18n( 'extension/gmaplocation/datatypes', "GMaps Location", 'Datatype name' ),
        $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'extension/gmaplocation/datatypes', "GMaps Location", 'Datatype name' ),
                           array( 'serialize_supported' => true ) );
                           array( 'serialize_supported' => true ) );
    }
    }
 
 
    function validateObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
    function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
    {
        if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) and
        if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) and
             $http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) )
             $http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) )
        {
        {
 
 
            $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
            $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
            $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
            $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
            $classAttribute =& $contentObjectAttribute->contentClassAttribute();
            $classAttribute = $contentObjectAttribute->contentClassAttribute();
            if ( $latitude == '' or
            if ( $latitude == '' or
                 $longitude == '' )
                 $longitude == '' )
            {
            {
                if ( ( !$classAttribute->attribute( 'is_information_collector' ) and
                if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
                       $contentObjectAttribute->validateIsRequired() ) )
 
                {
                {
                //TODO: In this case, we should directly call for geocoding.
 
                    $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
                    $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
                                                     'Missing Latitude/Longitude input.' ) );
                                                                         'Missing Latitude/Longitude input.' ) );
                    return EZ_INPUT_VALIDATOR_STATE_INVALID;
                    return eZInputValidator::STATE_INVALID;
                }
                }
                else
                else
                    return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
                {
 
                    return eZInputValidator::STATE_ACCEPTED;
 
                }
            }
            }
 
        }
 
        else if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
 
        {
 
            return eZInputValidator::STATE_INVALID;
 
 
        }
        }
        else
        else
        {
        {
            return EZ_INPUT_VALIDATOR_STATE_ACCEPTED;
            return eZInputValidator::STATE_ACCEPTED;
        }
        }
 
 
 
 
    }
    }
 
 
    function fetchObjectAttributeHTTPInput( &$http, $base, &$contentObjectAttribute )
    function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
    {
    {
 
 
        $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
        $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
        $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
        $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
 
 
Line 95... Line 93...
 
 
        $contentObjectAttribute->setContent( $location );
        $contentObjectAttribute->setContent( $location );
        return true;
        return true;
    }
    }
 
 
    function storeObjectAttribute( &$contentObjectAttribute )
    function storeObjectAttribute( $contentObjectAttribute )
    {
    {
        $location =& $contentObjectAttribute->content();
        $location = $contentObjectAttribute->content();
        $contentObjectAttribute->setAttribute( "data_text", $location->xmlString() );
        $contentObjectAttribute->setAttribute( "data_text", $location->xmlString() );
    }
    }
 
 
    function &objectAttributeContent( &$contentObjectAttribute )
    function objectAttributeContent( $contentObjectAttribute )
    {
    {
        $location = new eZGmapLocation( '', '', '' );
        $location = new eZGmapLocation( '', '', '' );
        $location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
        $location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
        return $location;
        return $location;
    }
    }
Line 113... Line 111...
    function metaData( $contentObjectAttribute )
    function metaData( $contentObjectAttribute )
    {
    {
        return $contentObjectAttribute->attribute( "data_text" );
        return $contentObjectAttribute->attribute( "data_text" );
    }
    }
 
 
    function title( &$contentObjectAttribute )
    function title( $contentObjectAttribute, $name = null )
    {
    {
        $location = new eZGmapLocation( '', '', '' );
        $location = new eZGmapLocation( '', '', '' );
        $location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
        $location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
        return $location->attribute('latitude') . ', ' . $location->attribute('longitude');
        return $location->attribute('latitude') . ', ' . $location->attribute('longitude');
    }
    }
 
 
    function hasObjectAttributeContent( &$contentObjectAttribute )
    function hasObjectAttributeContent( $contentObjectAttribute )
    {
    {
        return true;
        return true;
    }
    }
 
 
    /*!
    /*!
     Sets the default value.
     Sets the default value.
    */
    */
    function initializeObjectAttribute( &$contentObjectAttribute, $currentVersion, &$originalContentObjectAttribute )
    function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
    {
    {
        if ( $currentVersion == false )
        if ( $currentVersion == false )
        {
        {
            $location =& $contentObjectAttribute->content();
            $location = $contentObjectAttribute->content();
            $contentClassAttribute =& $contentObjectAttribute->contentClassAttribute();
            $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
            if ( !$location )
            if ( !$location )
            {
            {
                $location = new eZGmapLocation( $contentClassAttribute->attribute( 'data_text1' ), '', '' );
                $location = new eZGmapLocation( $contentClassAttribute->attribute( 'data_text1' ), '', '' );
            }
            }
            else
            else
Line 151... Line 149...
    }
    }
 
 
    /*!
    /*!
     \reimp
     \reimp
    */
    */
    function fetchClassAttributeHTTPInput( &$http, $base, &$classAttribute )
    function serializeContentObjectAttribute( $package, $objectAttribute )
    {
    {
        $defaultValueName = $base . EZ_GMAPLOCATION_DEFAULT_NAME_VARIABLE . $classAttribute->attribute( 'id' );
        $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
        if ( $http->hasPostVariable( $defaultValueName ) )
 
 
        $dom = new DOMDocument( '1.0', 'utf-8' );
 
        $success = $dom->loadXML( $objectAttribute->attribute( 'data_text' ) );
 
 
 
        if ( $success )
        {
        {
            $defaultValueValue = $http->postVariable( $defaultValueName );
            $importedNode = $node->ownerDocument->importNode( $dom->documentElement, true );
 
            $node->appendChild( $importedNode );
            if ($defaultValueValue == ""){
        }
                $defaultValueValue = "";
        else
            }
        {
            $classAttribute->setAttribute( 'data_text1', $defaultValueValue );
            eZDebug::writeError( 'Error parsing XML from data_text', __METHOD__ );
            return true;
 
        }
        }
        return false;
 
    }
 
 
 
    /*!
        return $node;
     \reimp
 
    */
 
    function serializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
 
    {
 
        $defaultName = $classAttribute->attribute( 'data_text1' );
 
        $attributeParametersNode->appendChild( eZDOMDocument::createElementTextNode( 'default-name', $defaultName ) );
 
    }
    }
 
 
    /*!
    /*!
     \reimp
     \reimp
    */
    */
    function unserializeContentClassAttribute( &$classAttribute, &$attributeNode, &$attributeParametersNode )
    function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
    {
    {
        $defaultName = $attributeParametersNode->elementTextContentByName( 'default-name' );
        $locationNode = $attributeNode->getElementsByTagName( 'ezgmaplocation' )->item( 0 );
        $classAttribute->setAttribute( 'data_text1', $defaultName );
 
    }
 
 
 
    /*!
        eZDebug::writeDebug( $locationNode->ownerDocument->saveXML( $locationNode ) );
     \reimp
 
    */
 
    function serializeContentObjectAttribute( &$package, &$objectAttribute )
 
    {
 
        $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
 
 
 
        $xml = new eZXML();
        if ( $locationNode )
        $domDocument = $xml->domTree( $objectAttribute->attribute( 'data_text' ) );
        {
        $node->appendChild( $domDocument->root() );
            $objectAttribute->setAttribute( 'data_text', $locationNode->ownerDocument->saveXML( $locationNode ) );
 
        }
        return $node;
 
    }
 
 
 
    /*!
 
     \reimp
 
    */
 
    function unserializeContentObjectAttribute( &$package, &$objectAttribute, $attributeNode )
 
    {
 
        $rootNode = $attributeNode->firstChild();
 
        $xmlString = $rootNode->attributeValue( 'local_name' ) == 'data-text' ? $rootNode->toString( 0 ) : '';
 
        $objectAttribute->setAttribute( 'data_text', $xmlString );
 
    }
    }
}
}
 
 
eZDataType::register( EZ_DATATYPESTRING_GMAPLOCATION, "ezgmaplocationtype" );
eZDataType::register( eZGmapLocationType::DATA_TYPE_STRING, "eZGmapLocationType" );
 
 
?>
?>