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.  */
  27.  
  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. {
  74.     /**
  75.      * Constructs a new ezcFeedContentModule object.
  76.      *
  77.      * @param string $level The level of the data container ('feed' or 'item')
  78.      */
  79.     public function __construct$level 'feed' )
  80.     {
  81.         parent::__construct$level );
  82.     }
  83.  
  84.     /**
  85.      * Sets the property $name to $value.
  86.      *
  87.      * @throws ezcBasePropertyNotFoundException
  88.      *          if the property $name is not defined
  89.      *
  90.      * @param string $name The property name
  91.      * @param mixed $value The property value
  92.      * @ignore
  93.      */
  94.     public function __set$name$value )
  95.     {
  96.         if $this->isElementAllowed$name ) )
  97.         {
  98.             $node $this->add$name );
  99.             $node->text $value;
  100.         }
  101.         else
  102.         {
  103.             parent::__set$name$value );
  104.         }
  105.     }
  106.  
  107.     /**
  108.      * Returns the value of property $name.
  109.      *
  110.      * @throws ezcBasePropertyNotFoundException
  111.      *          if the property $name is not defined
  112.      *
  113.      * @param string $name The property name
  114.      * @return mixed 
  115.      * @ignore
  116.      */
  117.     public function __get$name )
  118.     {
  119.         if $this->isElementAllowed$name ) )
  120.         {
  121.             return $this->properties[$name];
  122.         }
  123.         else
  124.         {
  125.             return parent::__get$name );
  126.         }
  127.     }
  128.  
  129.     /**
  130.      * Returns if the property $name is set.
  131.      *
  132.      * @param string $name The property name
  133.      * @return bool 
  134.      * @ignore
  135.      */
  136.     public function __isset$name )
  137.     {
  138.         if $this->isElementAllowed$name ) )
  139.         {
  140.             return isset$this->properties[$name);
  141.         }
  142.         else
  143.         {
  144.             return parent::__isset$name );
  145.         }
  146.     }
  147.  
  148.     /**
  149.      * Returns true if the element $name is allowed in the current module at the
  150.      * current level (feed or item), and false otherwise.
  151.      *
  152.      * @param string $name The element name to check if allowed in the current module and level (feed or item)
  153.      * @return bool 
  154.      */
  155.     public function isElementAllowed$name )
  156.     {
  157.         switch $this->level )
  158.         {
  159.             case 'feed':
  160.                 if in_array$namearray'alt''lat''long' ) ) )
  161.                 {
  162.                     return true;
  163.                 }
  164.                 break;
  165.  
  166.             case 'item':
  167.                 if in_array$namearray'alt''lat''long' ) ) )
  168.                 {
  169.                     return true;
  170.                 }
  171.                 break;
  172.         }
  173.         return false;
  174.     }
  175.  
  176.     /**
  177.      * Adds a new ezcFeedElement element with name $name to this module and
  178.      * returns it.
  179.      *
  180.      * @throws ezcFeedUnsupportedElementException
  181.      *          if trying to add an element which is not supported.
  182.      *
  183.      * @param string $name The element name
  184.      * @return ezcFeedElement 
  185.      */
  186.     public function add$name )
  187.     {
  188.         if $this->isElementAllowed$name ) )
  189.         {
  190.             switch $name )
  191.             {
  192.                 case 'alt':
  193.                 case 'lat':
  194.                 case 'long':
  195.                     $node new ezcFeedTextElement();
  196.                     break;
  197.             }
  198.  
  199.             $this->properties[$name$node;
  200.             return $node;
  201.         }
  202.         else
  203.         {
  204.             throw new ezcFeedUnsupportedElementException$name );
  205.         }
  206.     }
  207.  
  208.     /**
  209.      * Adds the module elements to the $xml XML document, in the container $root.
  210.      *
  211.      * @param DOMDocument $xml The XML document in which to add the module elements
  212.      * @param DOMNode $root The parent node which will contain the module elements
  213.      */
  214.     public function generateDOMDocument $xmlDOMNode $root )
  215.     {
  216.         $elements array'alt''lat''long' );
  217.         foreach $elements as $element )
  218.         {
  219.             if isset$this->$element ) )
  220.             {
  221.                 $elementTag $xml->createElement$this->getNamespacePrefix(':' $element );
  222.                 $root->appendChild$elementTag );
  223.  
  224.                 $elementTag->nodeValue $this->$element->__toString();
  225.             }
  226.         }
  227.     }
  228.  
  229.     /**
  230.      * Parses the XML element $node and creates a feed element in the current
  231.      * module with name $name.
  232.      *
  233.      * @param string $name The name of the element belonging to the module
  234.      * @param DOMElement $node The XML child from which to take the values for $name
  235.      */
  236.     public function parse$nameDOMElement $node )
  237.     {
  238.         if $this->isElementAllowed$name ) )
  239.         {
  240.             $element $this->add$name );
  241.             $value $node->textContent;
  242.  
  243.             switch $name )
  244.             {
  245.                 case 'alt':
  246.                 case 'lat':
  247.                 case 'long':
  248.                     $element->text $value;
  249.                     break;
  250.             }
  251.         }
  252.     }
  253.  
  254.     /**
  255.      * Returns the module name (Geo').
  256.      *
  257.      * @return string 
  258.      */
  259.     public static function getModuleName()
  260.     {
  261.         return 'Geo';
  262.     }
  263.  
  264.     /**
  265.      * Returns the namespace for this module ('http://www.w3.org/2003/01/geo/wgs84_pos#').
  266.      *
  267.      * @return string 
  268.      */
  269.     public static function getNamespace()
  270.     {
  271.         return 'http://www.w3.org/2003/01/geo/wgs84_pos#';
  272.     }
  273.  
  274.     /**
  275.      * Returns the namespace prefix for this module ('geo').
  276.      *
  277.      * @return string 
  278.      */
  279.     public static function getNamespacePrefix()
  280.     {
  281.         return 'geo';
  282.     }
  283. }
  284. ?>
Documentation generated by phpDocumentor 1.4.3