Subversion Repositories googlemaps

[/] [trunk/] [extension/] [gmaplocation/] [datatypes/] [ezgmaplocation/] [ezgmaplocationtype.php] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1 joekepley
<?php
2
//
3
// Definition of eZGmapLocationType class
4
//
5
// SOFTWARE NAME: Blend Gmap Location Class
6 4 Cyberwolf
// SOFTWARE RELEASE: 0.5
7
// COPYRIGHT NOTICE: Copyright (C) 2006-2009 Blend Interactive
8 1 joekepley
// SOFTWARE LICENSE: GNU General Public License v2.0
9
// NOTICE: >
10
//   This program is free software; you can redistribute it and/or
11
//   modify it under the terms of version 2.0  of the GNU General
12
//   Public License as published by the Free Software Foundation.
13 4 Cyberwolf
//
14 1 joekepley
//   This program is distributed in the hope that it will be useful,
15
//   but WITHOUT ANY WARRANTY; without even the implied warranty of
16
//   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
//   GNU General Public License for more details.
18 4 Cyberwolf
//
19 1 joekepley
//   You should have received a copy of version 2.0 of the GNU General
20
//   Public License along with this program; if not, write to the Free
21
//   Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22
//   MA 02110-1301, USA.
23
//
24
//
25
 
26
 
27
/*! \file ezgmaplocationtype.php
28
*/
29
 
30
/*!
31
  \class eZGmapLocationType ezgmaplocationtype.php
32
  \ingroup eZDatatype
33
  \brief The class eZGmapLocationType does
34
 
35
*/
36
 
37
class eZGmapLocationType extends eZDataType
38
{
39 4 Cyberwolf
    const DATA_TYPE_STRING = "ezgmaplocation";
40
 
41 1 joekepley
    /*!
42
     Constructor
43
    */
44 4 Cyberwolf
    function __construct()
45 1 joekepley
    {
46 4 Cyberwolf
        $this->eZDataType( self::DATA_TYPE_STRING, ezi18n( 'extension/gmaplocation/datatypes', "GMaps Location", 'Datatype name' ),
47 1 joekepley
                           array( 'serialize_supported' => true ) );
48
    }
49
 
50 4 Cyberwolf
    function validateObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
51 1 joekepley
    {
52
        if ( $http->hasPostVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) ) and
53
             $http->hasPostVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) ) )
54
        {
55
 
56
            $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
57
            $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
58 4 Cyberwolf
            $classAttribute = $contentObjectAttribute->contentClassAttribute();
59 1 joekepley
            if ( $latitude == '' or
60
                 $longitude == '' )
61
            {
62 4 Cyberwolf
                if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
63 1 joekepley
                {
64
                    $contentObjectAttribute->setValidationError( ezi18n( 'kernel/classes/datatypes',
65 4 Cyberwolf
                                                                         'Missing Latitude/Longitude input.' ) );
66
                    return eZInputValidator::STATE_INVALID;
67 1 joekepley
                }
68
                else
69 4 Cyberwolf
                {
70
                    return eZInputValidator::STATE_ACCEPTED;
71
                }
72 1 joekepley
            }
73
        }
74 4 Cyberwolf
        else if ( !$classAttribute->attribute( 'is_information_collector' ) && $contentObjectAttribute->validateIsRequired() )
75
        {
76
            return eZInputValidator::STATE_INVALID;
77
 
78
        }
79 1 joekepley
        else
80
        {
81 4 Cyberwolf
            return eZInputValidator::STATE_ACCEPTED;
82 1 joekepley
        }
83
    }
84
 
85 4 Cyberwolf
    function fetchObjectAttributeHTTPInput( $http, $base, $contentObjectAttribute )
86 1 joekepley
    {
87
 
88
        $latitude = $http->postVariable( $base . '_data_gmaplocation_latitude_' . $contentObjectAttribute->attribute( 'id' ) );
89
        $longitude = $http->postVariable( $base . '_data_gmaplocation_longitude_' . $contentObjectAttribute->attribute( 'id' ) );
90
 
91
 
92
        $location = new eZGmapLocation( $latitude, $longitude );
93
 
94
        $contentObjectAttribute->setContent( $location );
95
        return true;
96
    }
97
 
98 4 Cyberwolf
    function storeObjectAttribute( $contentObjectAttribute )
99 1 joekepley
    {
100 4 Cyberwolf
        $location = $contentObjectAttribute->content();
101 1 joekepley
        $contentObjectAttribute->setAttribute( "data_text", $location->xmlString() );
102
    }
103
 
104 4 Cyberwolf
    function objectAttributeContent( $contentObjectAttribute )
105 1 joekepley
    {
106
        $location = new eZGmapLocation( '', '', '' );
107
        $location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
108
        return $location;
109
    }
110
 
111
    function metaData( $contentObjectAttribute )
112
    {
113
        return $contentObjectAttribute->attribute( "data_text" );
114
    }
115
 
116 4 Cyberwolf
    function title( $contentObjectAttribute, $name = null )
117 1 joekepley
    {
118
        $location = new eZGmapLocation( '', '', '' );
119
        $location->decodeXML( $contentObjectAttribute->attribute( "data_text" ) );
120
        return $location->attribute('latitude') . ', ' . $location->attribute('longitude');
121
    }
122
 
123 4 Cyberwolf
    function hasObjectAttributeContent( $contentObjectAttribute )
124 1 joekepley
    {
125
        return true;
126
    }
127
 
128
    /*!
129
     Sets the default value.
130
    */
131 4 Cyberwolf
    function initializeObjectAttribute( $contentObjectAttribute, $currentVersion, $originalContentObjectAttribute )
132 1 joekepley
    {
133
        if ( $currentVersion == false )
134
        {
135 4 Cyberwolf
            $location = $contentObjectAttribute->content();
136
            $contentClassAttribute = $contentObjectAttribute->contentClassAttribute();
137 1 joekepley
            if ( !$location )
138
            {
139
                $location = new eZGmapLocation( $contentClassAttribute->attribute( 'data_text1' ), '', '' );
140
            }
141
            else
142
            {
143
                $location->setLatitude('');
144
                $location->setLongitude('');
145
            }
146
            $contentObjectAttribute->setAttribute( "data_text", $location->xmlString() );
147
            $contentObjectAttribute->setContent( $location );
148
        }
149
    }
150
 
151
    /*!
152
     \reimp
153
    */
154 4 Cyberwolf
    function serializeContentObjectAttribute( $package, $objectAttribute )
155 1 joekepley
    {
156 4 Cyberwolf
        $node = $this->createContentObjectAttributeDOMNode( $objectAttribute );
157 1 joekepley
 
158 4 Cyberwolf
        $dom = new DOMDocument( '1.0', 'utf-8' );
159
        $success = $dom->loadXML( $objectAttribute->attribute( 'data_text' ) );
160
 
161
        if ( $success )
162
        {
163
            $importedNode = $node->ownerDocument->importNode( $dom->documentElement, true );
164
            $node->appendChild( $importedNode );
165 1 joekepley
        }
166 4 Cyberwolf
        else
167
        {
168
            eZDebug::writeError( 'Error parsing XML from data_text', __METHOD__ );
169
        }
170 1 joekepley
 
171 4 Cyberwolf
        return $node;
172 1 joekepley
    }
173
 
174
    /*!
175
     \reimp
176
    */
177 4 Cyberwolf
    function unserializeContentObjectAttribute( $package, $objectAttribute, $attributeNode )
178 1 joekepley
    {
179 4 Cyberwolf
        $locationNode = $attributeNode->getElementsByTagName( 'ezgmaplocation' )->item( 0 );
180 1 joekepley
 
181 4 Cyberwolf
        eZDebug::writeDebug( $locationNode->ownerDocument->saveXML( $locationNode ) );
182 1 joekepley
 
183 4 Cyberwolf
        if ( $locationNode )
184
        {
185
            $objectAttribute->setAttribute( 'data_text', $locationNode->ownerDocument->saveXML( $locationNode ) );
186
        }
187 1 joekepley
    }
188
}
189
 
190 4 Cyberwolf
eZDataType::register( eZGmapLocationType::DATA_TYPE_STRING, "eZGmapLocationType" );
191 1 joekepley
 
192
?>