|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 00032 class Zend_Service_Amazon_Item 00033 { 00037 public $ASIN; 00038 00042 public $DetailPageURL; 00043 00047 public $SalesRank; 00048 00052 public $TotalReviews; 00053 00057 public $AverageRating; 00058 00062 public $SmallImage; 00063 00067 public $MediumImage; 00068 00072 public $LargeImage; 00073 00077 public $Subjects; 00078 00082 public $Offers; 00083 00087 public $CustomerReviews = array(); 00088 00092 public $SimilarProducts = array(); 00093 00097 public $Accessories = array(); 00098 00102 public $Tracks = array(); 00103 00107 public $ListmaniaLists = array(); 00108 00109 protected $_dom; 00110 00111 00121 public function __construct($dom) 00122 { 00123 if (null === $dom) { 00124 require_once 'Zend/Service/Amazon/Exception.php'; 00125 throw new Zend_Service_Amazon_Exception('Item element is empty'); 00126 } 00127 if (!$dom instanceof DOMElement) { 00128 require_once 'Zend/Service/Amazon/Exception.php'; 00129 throw new Zend_Service_Amazon_Exception('Item is not a valid DOM element'); 00130 } 00131 $xpath = new DOMXPath($dom->ownerDocument); 00132 $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2005-10-05'); 00133 $this->ASIN = $xpath->query('./az:ASIN/text()', $dom)->item(0)->data; 00134 00135 $result = $xpath->query('./az:DetailPageURL/text()', $dom); 00136 if ($result->length == 1) { 00137 $this->DetailPageURL = $result->item(0)->data; 00138 } 00139 00140 if ($xpath->query('./az:ItemAttributes/az:ListPrice', $dom)->length >= 1) { 00141 $this->CurrencyCode = (string) $xpath->query('./az:ItemAttributes/az:ListPrice/az:CurrencyCode/text()', $dom)->item(0)->data; 00142 $this->Amount = (int) $xpath->query('./az:ItemAttributes/az:ListPrice/az:Amount/text()', $dom)->item(0)->data; 00143 $this->FormattedPrice = (string) $xpath->query('./az:ItemAttributes/az:ListPrice/az:FormattedPrice/text()', $dom)->item(0)->data; 00144 } 00145 00146 $result = $xpath->query('./az:ItemAttributes/az:*/text()', $dom); 00147 if ($result->length >= 1) { 00148 foreach ($result as $v) { 00149 if (isset($this->{$v->parentNode->tagName})) { 00150 if (is_array($this->{$v->parentNode->tagName})) { 00151 array_push($this->{$v->parentNode->tagName}, (string) $v->data); 00152 } else { 00153 $this->{$v->parentNode->tagName} = array($this->{$v->parentNode->tagName}, (string) $v->data); 00154 } 00155 } else { 00156 $this->{$v->parentNode->tagName} = (string) $v->data; 00157 } 00158 } 00159 } 00160 00161 foreach (array('SmallImage', 'MediumImage', 'LargeImage') as $im) { 00162 $result = $xpath->query("./az:ImageSets/az:ImageSet[position() = 1]/az:$im", $dom); 00163 if ($result->length == 1) { 00167 require_once 'Zend/Service/Amazon/Image.php'; 00168 $this->$im = new Zend_Service_Amazon_Image($result->item(0)); 00169 } 00170 } 00171 00172 $result = $xpath->query('./az:SalesRank/text()', $dom); 00173 if ($result->length == 1) { 00174 $this->SalesRank = (int) $result->item(0)->data; 00175 } 00176 00177 $result = $xpath->query('./az:CustomerReviews/az:Review', $dom); 00178 if ($result->length >= 1) { 00182 require_once 'Zend/Service/Amazon/CustomerReview.php'; 00183 foreach ($result as $review) { 00184 $this->CustomerReviews[] = new Zend_Service_Amazon_CustomerReview($review); 00185 } 00186 $this->AverageRating = (float) $xpath->query('./az:CustomerReviews/az:AverageRating/text()', $dom)->item(0)->data; 00187 $this->TotalReviews = (int) $xpath->query('./az:CustomerReviews/az:TotalReviews/text()', $dom)->item(0)->data; 00188 } 00189 00190 $result = $xpath->query('./az:EditorialReviews/az:*', $dom); 00191 if ($result->length >= 1) { 00195 require_once 'Zend/Service/Amazon/EditorialReview.php'; 00196 foreach ($result as $r) { 00197 $this->EditorialReviews[] = new Zend_Service_Amazon_EditorialReview($r); 00198 } 00199 } 00200 00201 $result = $xpath->query('./az:SimilarProducts/az:*', $dom); 00202 if ($result->length >= 1) { 00206 require_once 'Zend/Service/Amazon/SimilarProduct.php'; 00207 foreach ($result as $r) { 00208 $this->SimilarProducts[] = new Zend_Service_Amazon_SimilarProduct($r); 00209 } 00210 } 00211 00212 $result = $xpath->query('./az:ListmaniaLists/*', $dom); 00213 if ($result->length >= 1) { 00217 require_once 'Zend/Service/Amazon/ListmaniaList.php'; 00218 foreach ($result as $r) { 00219 $this->ListmaniaLists[] = new Zend_Service_Amazon_ListmaniaList($r); 00220 } 00221 } 00222 00223 $result = $xpath->query('./az:Tracks/az:Disc', $dom); 00224 if ($result->length > 1) { 00225 foreach ($result as $disk) { 00226 foreach ($xpath->query('./*/text()', $disk) as $t) { 00227 // TODO: For consistency in a bugfix all tracks are appended to one single array 00228 // Erroreous line: $this->Tracks[$disk->getAttribute('number')] = (string) $t->data; 00229 $this->Tracks[] = (string) $t->data; 00230 } 00231 } 00232 } else if ($result->length == 1) { 00233 foreach ($xpath->query('./*/text()', $result->item(0)) as $t) { 00234 $this->Tracks[] = (string) $t->data; 00235 } 00236 } 00237 00238 $result = $xpath->query('./az:Offers', $dom); 00239 $resultSummary = $xpath->query('./az:OfferSummary', $dom); 00240 if ($result->length > 1 || $resultSummary->length == 1) { 00244 require_once 'Zend/Service/Amazon/OfferSet.php'; 00245 $this->Offers = new Zend_Service_Amazon_OfferSet($dom); 00246 } 00247 00248 $result = $xpath->query('./az:Accessories/*', $dom); 00249 if ($result->length > 1) { 00253 require_once 'Zend/Service/Amazon/Accessories.php'; 00254 foreach ($result as $r) { 00255 $this->Accessories[] = new Zend_Service_Amazon_Accessories($r); 00256 } 00257 } 00258 00259 $this->_dom = $dom; 00260 } 00261 00262 00268 public function asXml() 00269 { 00270 return $this->_dom->ownerDocument->saveXML($this->_dom); 00271 } 00272 }