![]() |
- Developper API
2.0.5
|
00001 <?php 00011 class Review 00012 { 00013 private $author; 00014 private $source; 00015 private $content; 00016 private $mark; 00017 private $date; 00018 private $url; 00019 00020 private static $xmlNodesName = array( 00021 "author", 00022 "source", 00023 "content", 00024 "mark", 00025 "date", 00026 "url" 00027 ); 00028 00039 public function __construct($author,$source,$content,$mark,$date,$url) 00040 { 00041 $this->author = $author; 00042 $this->source = $source; 00043 $this->content = $content; 00044 $this->mark = $mark; 00045 $this->date = $date; 00046 $this->url = $url; 00047 } 00048 00053 public final function getAuthor() 00054 { 00055 return (!empty($this->author)) ? $this->author : false; 00056 } 00057 00062 public final function getSource() 00063 { 00064 return (!empty($this->source)) ? $this->source : false; 00065 } 00066 00071 public final function getContent() 00072 { 00073 return (!empty($this->content)) ? $this->content : false; 00074 } 00075 00080 public final function getMark() 00081 { 00082 return (!empty($this->mark)) ? $this->mark : false; 00083 } 00084 00089 public final function getDate() 00090 { 00091 return (!empty($this->date)) ? $this->date : false; 00092 } 00093 00098 public final function getUrl() 00099 { 00100 return (!empty($this->url)) ? $this->url : false; 00101 } 00102 00108 public final static function getReviewFromSXMLElement($node) 00109 { 00110 if(!Review::isSXMLNodeProperty($node)) 00111 { 00112 error("Review creation failed for element: ".$node->getName()); 00113 return false; 00114 } 00115 00116 $author = $node->xpath("author"); 00117 if(count($author) > 0) 00118 $author = (string) $author[0]; 00119 else 00120 $author = ""; 00121 00122 $source = $node->xpath("source"); 00123 if(count($source) > 0) 00124 $source = (string) $source[0]; 00125 else 00126 $source = ""; 00127 00128 $content = $node->xpath("content"); 00129 if(count($content) > 0) 00130 $content = (string) $content[0]; 00131 else 00132 $content = ""; 00133 00134 $mark = $node->xpath("mark"); 00135 if(count($mark) > 0) 00136 $mark = (string) $mark[0]; 00137 else 00138 $mark = ""; 00139 00140 $date = $node->xpath("date"); 00141 if(count($date) > 0) 00142 $date = (string) $date[0]; 00143 else 00144 $date = ""; 00145 00146 $url = $node->xpath("url"); 00147 if(count($url) > 0) 00148 $url = (string) $url[0]; 00149 else 00150 $url = ""; 00151 00152 $review = new Review($author,$source,$content,$mark,$date,$url); 00153 return $review; 00154 } 00155 00161 public final static function isSXMLNodeProperty($node) 00162 { 00163 if(!hasChildren($node)) 00164 return false; 00165 else 00166 { 00167 foreach($node->children() as $child) 00168 { 00169 $name = $child->getName(); 00170 00171 if( ! in_array($name,Review::$xmlNodesName) ) 00172 return false; 00173 } 00174 00175 return true; 00176 } 00177 } 00178 } 00179 ?>