- Developper API  2.0.5
developerApi_2.0.5/Variety.php
Go to the documentation of this file.
00001 <?php
00011 class Variety
00012 {
00013         private $name;
00014         private $amount;        
00015 
00016         private static $xmlNodesName = array(
00017                 "name",
00018                 "amount"
00019         );
00020     
00027         public function __construct($name,$amount)
00028         {
00029                 $this->name = $name;
00030                 $this->amount = $amount;                
00031         }
00032 
00037         public function getName()
00038         {
00039                 return (!empty($this->name)) ? $this->name : false;
00040         }
00041 
00046         public function getAmount()
00047         {
00048                 return (!empty($this->amount)) ? $this->amount : false;
00049         }
00050     
00056         public final static function getVarietyFromSXMLElement($node)
00057         {
00058                 if(!Variety::isSXMLNodeProperty($node))
00059                 {
00060                         error("Shop creation failed for element: ".$node->getName());
00061                         return false;
00062                 }       
00063                 
00064                 $name = $node->xpath("name");           
00065                 if(count($name) > 0)
00066                         $name = (string) $name[0];
00067                 else
00068                         $name = "";
00069 
00070                 $amount = $node->xpath("amount");               
00071                 if(count($amount) > 0)
00072                         $amount = (string) $amount[0];
00073                 else
00074                         $amount = "";
00075 
00076                         
00077                 $variety = new Variety($name,$amount);
00078                 return $variety;                        
00079         }
00080 
00086         public final static function isSXMLNodeProperty($node)
00087         {
00088                 if(!hasChildren($node))
00089                         return false;
00090                 else
00091                 {
00092                         foreach($node->children() as $child)
00093                         {
00094                                 $name = $child->getName();
00095 
00096                                 if( ! in_array($name,Variety::$xmlNodesName) )
00097                                         return false;                           
00098                         }
00099 
00100                         return true;
00101                 }
00102         }
00103 }
00104 
00105 ?>