## Apache Zeta Components Manual :: File Source for geo_module.php

## Source for file geo_module.php

Documentation is available at geo_module.php

1. <?php
2. /**
3. * File containing the ezcFeedGeoModule class.
4. *
5. * Licensed to the Apache Software Foundation (ASF) under one
6. * or more contributor license agreements. See the NOTICE file
7. * distributed with this work for additional information
8. * regarding copyright ownership. The ASF licenses this file
9. * to you under the Apache License, Version 2.0 (the
10. * "License"); you may not use this file except in compliance
11. * with the License. You may obtain a copy of the License at
12. *
13. * http://www.apache.org/licenses/LICENSE-2.0
14. *
15. * Unless required by applicable law or agreed to in writing,
16. * software distributed under the License is distributed on an
17. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
18. * KIND, either express or implied. See the License for the
19. * specific language governing permissions and limitations
20. * under the License.
21. *
22. * @package Feed
23. * @version //autogentag//
24. * @license http://www.apache.org/licenses/LICENSE-2.0 Apache License, Version 2.0
25. * @filesource
26. */
28. /**
29. * Support for the Geo module: data container, generator, parser.
30. *
31. * Specifications: {@link http://www.w3.org/2003/01/geo/}.
32. *
33. * Create example:
34. *
35. * <code>
36. * <?php
37. * // $feed is an ezcFeed object
38. * $item = $feed->add( 'item' );
39. * $module = $item->addModule( 'Geo' );
40. * $module->alt = 1000;
41. * $module->lat = 26.58;
42. * $module->long = -97.83;
43. * ?>
44. * </code>
45. *
46. * Parse example:
47. *
48. * <code>
49. * <?php
50. * // $item is an ezcFeedEntryElement object
51. * $alt = isset( $item->Geo->alt ) ? $item->Geo->alt->__toString() : null;
52. * $lat = isset( $item->Geo->lat ) ? $item->Geo->lat->__toString() : null;
53. * $long = isset( $item->Geo->long ) ? $item->Geo->long->__toString() : null;
54. * ?>
55. * </code>
56. *
57. * @property ezcFeedTextElement $alt
58. * Altitude in decimal meters above the local
59. * reference ellipsoid (eg. 509.2). Can also be
60. * negative.
61. * @property ezcFeedTextElement $lat
62. * {@link http://en.wikipedia.org/wiki/WGS84 WGS84} latitude
63. * on the globe as decimal degrees
64. * (eg. 25.03358300). Can also be negative.
65. * @property ezcFeedTextElement $long
66. * {@link http://en.wikipedia.org/wiki/WGS84 WGS84} longitude
67. * on the globe as decimal degrees
68. * (eg. 121.56430000). Can also be negative.
69. *
70. * @package Feed
71. * @version //autogentag//
72. */
73. class ezcFeedGeoModule extends ezcFeedModule
74. {
75. /**
76. * Constructs a new ezcFeedContentModule object.
77. *
78. * @param string $level The level of the data container ('feed' or 'item')
79. */
80. public function __construct ( $level = 'feed' )
81. {
82. parent:: __construct ( $level );
83. }
85. /**
86. * Sets the property $name to $value.
87. *
88. * @throws ezcBasePropertyNotFoundException
89. * if the property $name is not defined
90. *
91. * @param string $name The property name
92. * @param mixed $value The property value
93. * @ignore
94. */
95. public function __set( $name, $value )
96. {
97. if ( $this-> isElementAllowed ( $name ) )
98. {
99. $node = $this-> add ( $name );
100. $node->text = $value;
101. }
102. else
103. {
104. parent::__set( $name, $value );
105. }
106. }
108. /**
109. * Returns the value of property $name.
110. *
111. * @throws ezcBasePropertyNotFoundException
112. * if the property $name is not defined
113. *
114. * @param string $name The property name
115. * @return mixed
116. * @ignore
117. */
118. public function __get( $name )
119. {
120. if ( $this-> isElementAllowed ( $name ) )
121. {
122. return $this-> properties [$name];
123. }
124. else
125. {
126. return parent::__get( $name );
127. }
128. }
130. /**
131. * Returns if the property $name is set.
132. *
133. * @param string $name The property name
134. * @return bool
135. * @ignore
136. */
137. public function __isset( $name )
138. {
139. if ( $this-> isElementAllowed ( $name ) )
140. {
141. return isset( $this-> properties [$name] );
142. }
143. else
144. {
145. return parent::__isset( $name );
146. }
147. }
149. /**
150. * Returns true if the element $name is allowed in the current module at the
151. * current level (feed or item), and false otherwise.
152. *
153. * @param string $name The element name to check if allowed in the current module and level (feed or item)
154. * @return bool
155. */
156. public function isElementAllowed ( $name )
157. {
158. switch ( $this-> level )
159. {
160. case 'feed':
161. if ( in_array ( $name, array( 'alt', 'lat', 'long' ) ) )
162. {
163. return true;
164. }
165. break;
167. case 'item':
168. if ( in_array ( $name, array( 'alt', 'lat', 'long' ) ) )
169. {
170. return true;
171. }
172. break;
173. }
174. return false;
175. }
177. /**
178. * Adds a new ezcFeedElement element with name $name to this module and
179. * returns it.
180. *
181. * @throws ezcFeedUnsupportedElementException
182. * if trying to add an element which is not supported.
183. *
184. * @param string $name The element name
185. * @return ezcFeedElement
186. */
187. public function add ( $name )
188. {
189. if ( $this-> isElementAllowed ( $name ) )
190. {
191. switch ( $name )
192. {
193. case 'alt':
194. case 'lat':
195. case 'long':
196. $node = new ezcFeedTextElement ();
197. break;
198. }
200. $this-> properties [$name] = $node;
201. return $node;
202. }
203. else
204. {
205. throw new ezcFeedUnsupportedElementException ( $name );
206. }
207. }
209. /**
210. * Adds the module elements to the $xml XML document, in the container $root.
211. *
212. * @param DOMDocument $xml The XML document in which to add the module elements
213. * @param DOMNode $root The parent node which will contain the module elements
214. */
215. public function generate ( DOMDocument $xml, DOMNode $root )
216. {
217. $elements = array( 'alt', 'lat', 'long' );
218. foreach ( $elements as $element )
219. {
220. if ( isset( $this->$element ) )
221. {
222. $elementTag = $xml->createElement( $this-> getNamespacePrefix () . ':' . $element );
223. $root->appendChild( $elementTag );
225. $elementTag->nodeValue = $this->$element->__toString();
226. }
227. }
228. }
230. /**
231. * Parses the XML element $node and creates a feed element in the current
232. * module with name $name.
233. *
234. * @param string $name The name of the element belonging to the module
235. * @param DOMElement $node The XML child from which to take the values for $name
236. */
237. public function parse ( $name, DOMElement $node )
238. {
239. if ( $this-> isElementAllowed ( $name ) )
240. {
241. $element = $this-> add ( $name );
242. $value = $node->textContent;
244. switch ( $name )
245. {
246. case 'alt':
247. case 'lat':
248. case 'long':
249. $element->text = $value;
250. break;
251. }
252. }
253. }
255. /**
256. * Returns the module name (Geo').
257. *
258. * @return string
259. */
260. public static function getModuleName ()
261. {
262. return 'Geo';
263. }
265. /**
266. * Returns the namespace for this module ('http://www.w3.org/2003/01/geo/wgs84_pos#').
267. *
268. * @return string
269. */
270. public static function getNamespace ()
271. {
272. return 'http://www.w3.org/2003/01/geo/wgs84_pos#';
273. }
275. /**
276. * Returns the namespace prefix for this module ('geo').
277. *
278. * @return string
279. */
280. public static function getNamespacePrefix ()
281. {
282. return 'geo';
283. }
284. }
285. ?>

Documentation generated by phpDocumentor 1.4.3