![]() |
- Developper API
2.0.5
|
00001 <?php 00011 require_once("DataStructure.php"); 00012 00013 class Recipe extends DataStructure 00014 { 00015 private $video; 00016 00017 private static $xmlNodesName = array( 00018 "name", 00019 "url", 00020 "video", 00021 "type" 00022 ); 00023 00032 public function __construct($name,$type,$url,$video="") 00033 { 00034 parent::__construct($name,$type,$url); 00035 $this->video = $video; 00036 } 00037 00042 public final function hasVideo() 00043 { 00044 return (!empty($this->video)); 00045 } 00046 00051 public final function getVideo() 00052 { 00053 return (!empty($this->video)) ? $this->video : false; 00054 } 00055 00061 public final static function getRecipeFromSXMLElement($node) 00062 { 00063 if(!Recipe::isSXMLNodeProperty($node)) 00064 { 00065 error("Recipe Property creation failed for element: ".$node->getName()); 00066 return false; 00067 } 00068 00069 $name = $node->xpath("name"); 00070 00071 if(count($name) > 0) 00072 $name = (string) $name[0]; 00073 else 00074 $name = ""; 00075 00076 $url = $node->xpath("url"); 00077 if(count($url) > 0) 00078 $url = (string) $url[0]; 00079 else 00080 $url = ""; 00081 00082 $video = $node->xpath("video"); 00083 if(count($video) > 0) 00084 $video = (string) $video[0]; 00085 else 00086 $video = ""; 00087 00088 $type = $node->xpath("type"); 00089 if(count($type) > 0) 00090 $type = (string) $type[0]; 00091 else 00092 $type = ""; 00093 00094 $property = new Recipe($name,$type,$url,$video); 00095 return $property; 00096 } 00097 00103 public final static function isSXMLNodeProperty($node) 00104 { 00105 if(!hasChildren($node)) 00106 return false; 00107 else 00108 { 00109 foreach($node->children() as $child) 00110 { 00111 $name = $child->getName(); 00112 00113 if( ! in_array($name,Recipe::$xmlNodesName) ) 00114 return false; 00115 } 00116 00117 return true; 00118 } 00119 } 00120 } 00121 ?>