File indexing completed on 2024-12-22 05:37:02
0001 <?php 0002 0003 /** 0004 * Zend Framework 0005 * 0006 * LICENSE 0007 * 0008 * This source file is subject to the new BSD license that is bundled 0009 * with this package in the file LICENSE.txt. 0010 * It is also available through the world-wide-web at this URL: 0011 * http://framework.zend.com/license/new-bsd 0012 * If you did not receive a copy of the license and are unable to 0013 * obtain it through the world-wide-web, please send an email 0014 * to license@zend.com so we can send you a copy immediately. 0015 * 0016 * @category Zend 0017 * @package Zend_Service 0018 * @subpackage Amazon 0019 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0020 * @license http://framework.zend.com/license/new-bsd New BSD License 0021 * @version $Id$ 0022 */ 0023 0024 0025 /** 0026 * @category Zend 0027 * @package Zend_Service 0028 * @subpackage Amazon 0029 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com) 0030 * @license http://framework.zend.com/license/new-bsd New BSD License 0031 */ 0032 class Zend_Service_Amazon_Item 0033 { 0034 /** 0035 * @var string 0036 */ 0037 public $ASIN; 0038 0039 /** 0040 * @var string 0041 */ 0042 public $DetailPageURL; 0043 0044 /** 0045 * @var int 0046 */ 0047 public $SalesRank; 0048 0049 /** 0050 * @var int 0051 */ 0052 public $TotalReviews; 0053 0054 /** 0055 * @var int 0056 */ 0057 public $AverageRating; 0058 0059 /** 0060 * @var string 0061 */ 0062 public $SmallImage; 0063 0064 /** 0065 * @var string 0066 */ 0067 public $MediumImage; 0068 0069 /** 0070 * @var string 0071 */ 0072 public $LargeImage; 0073 0074 /** 0075 * @var string 0076 */ 0077 public $Subjects; 0078 0079 /** 0080 * @var Zend_Service_Amazon_OfferSet 0081 */ 0082 public $Offers; 0083 0084 /** 0085 * @var Zend_Service_Amazon_CustomerReview[] 0086 */ 0087 public $CustomerReviews = array(); 0088 0089 /** 0090 * @var Zend_Service_Amazon_SimilarProducts[] 0091 */ 0092 public $SimilarProducts = array(); 0093 0094 /** 0095 * @var Zend_Service_Amazon_Accessories[] 0096 */ 0097 public $Accessories = array(); 0098 0099 /** 0100 * @var array 0101 */ 0102 public $Tracks = array(); 0103 0104 /** 0105 * @var Zend_Service_Amazon_ListmaniaLists[] 0106 */ 0107 public $ListmaniaLists = array(); 0108 0109 protected $_dom; 0110 0111 0112 /** 0113 * Parse the given <Item> element 0114 * 0115 * @param null|DOMElement $dom 0116 * @return void 0117 * @throws Zend_Service_Amazon_Exception 0118 * 0119 * @group ZF-9547 0120 */ 0121 public function __construct($dom) 0122 { 0123 if (null === $dom) { 0124 // require_once 'Zend/Service/Amazon/Exception.php'; 0125 throw new Zend_Service_Amazon_Exception('Item element is empty'); 0126 } 0127 if (!$dom instanceof DOMElement) { 0128 // require_once 'Zend/Service/Amazon/Exception.php'; 0129 throw new Zend_Service_Amazon_Exception('Item is not a valid DOM element'); 0130 } 0131 $xpath = new DOMXPath($dom->ownerDocument); 0132 $xpath->registerNamespace('az', 'http://webservices.amazon.com/AWSECommerceService/2011-08-01'); 0133 $this->ASIN = $xpath->query('./az:ASIN/text()', $dom)->item(0)->data; 0134 0135 $result = $xpath->query('./az:DetailPageURL/text()', $dom); 0136 if ($result->length == 1) { 0137 $this->DetailPageURL = $result->item(0)->data; 0138 } 0139 0140 if ($xpath->query('./az:ItemAttributes/az:ListPrice', $dom)->length >= 1) { 0141 $this->CurrencyCode = (string) $xpath->query('./az:ItemAttributes/az:ListPrice/az:CurrencyCode/text()', $dom)->item(0)->data; 0142 $this->Amount = (int) $xpath->query('./az:ItemAttributes/az:ListPrice/az:Amount/text()', $dom)->item(0)->data; 0143 $this->FormattedPrice = (string) $xpath->query('./az:ItemAttributes/az:ListPrice/az:FormattedPrice/text()', $dom)->item(0)->data; 0144 } 0145 0146 $result = $xpath->query('./az:ItemAttributes/az:*/text()', $dom); 0147 if ($result->length >= 1) { 0148 foreach ($result as $v) { 0149 if (isset($this->{$v->parentNode->tagName})) { 0150 if (is_array($this->{$v->parentNode->tagName})) { 0151 array_push($this->{$v->parentNode->tagName}, (string) $v->data); 0152 } else { 0153 $this->{$v->parentNode->tagName} = array($this->{$v->parentNode->tagName}, (string) $v->data); 0154 } 0155 } else { 0156 $this->{$v->parentNode->tagName} = (string) $v->data; 0157 } 0158 } 0159 } 0160 0161 foreach (array('SmallImage', 'MediumImage', 'LargeImage') as $im) { 0162 $result = $xpath->query("./az:ImageSets/az:ImageSet[position() = 1]/az:$im", $dom); 0163 if ($result->length == 1) { 0164 /** 0165 * @see Zend_Service_Amazon_Image 0166 */ 0167 // require_once 'Zend/Service/Amazon/Image.php'; 0168 $this->$im = new Zend_Service_Amazon_Image($result->item(0)); 0169 } 0170 } 0171 0172 $result = $xpath->query('./az:SalesRank/text()', $dom); 0173 if ($result->length == 1) { 0174 $this->SalesRank = (int) $result->item(0)->data; 0175 } 0176 0177 $result = $xpath->query('./az:CustomerReviews/az:Review', $dom); 0178 if ($result->length >= 1) { 0179 /** 0180 * @see Zend_Service_Amazon_CustomerReview 0181 */ 0182 // require_once 'Zend/Service/Amazon/CustomerReview.php'; 0183 foreach ($result as $review) { 0184 $this->CustomerReviews[] = new Zend_Service_Amazon_CustomerReview($review); 0185 } 0186 $this->AverageRating = (float) $xpath->query('./az:CustomerReviews/az:AverageRating/text()', $dom)->item(0)->data; 0187 $this->TotalReviews = (int) $xpath->query('./az:CustomerReviews/az:TotalReviews/text()', $dom)->item(0)->data; 0188 } 0189 0190 $result = $xpath->query('./az:EditorialReviews/az:*', $dom); 0191 if ($result->length >= 1) { 0192 /** 0193 * @see Zend_Service_Amazon_EditorialReview 0194 */ 0195 // require_once 'Zend/Service/Amazon/EditorialReview.php'; 0196 foreach ($result as $r) { 0197 $this->EditorialReviews[] = new Zend_Service_Amazon_EditorialReview($r); 0198 } 0199 } 0200 0201 $result = $xpath->query('./az:SimilarProducts/az:*', $dom); 0202 if ($result->length >= 1) { 0203 /** 0204 * @see Zend_Service_Amazon_SimilarProduct 0205 */ 0206 // require_once 'Zend/Service/Amazon/SimilarProduct.php'; 0207 foreach ($result as $r) { 0208 $this->SimilarProducts[] = new Zend_Service_Amazon_SimilarProduct($r); 0209 } 0210 } 0211 0212 $result = $xpath->query('./az:ListmaniaLists/*', $dom); 0213 if ($result->length >= 1) { 0214 /** 0215 * @see Zend_Service_Amazon_ListmaniaList 0216 */ 0217 // require_once 'Zend/Service/Amazon/ListmaniaList.php'; 0218 foreach ($result as $r) { 0219 $this->ListmaniaLists[] = new Zend_Service_Amazon_ListmaniaList($r); 0220 } 0221 } 0222 0223 $result = $xpath->query('./az:Tracks/az:Disc', $dom); 0224 if ($result->length > 1) { 0225 foreach ($result as $disk) { 0226 foreach ($xpath->query('./*/text()', $disk) as $t) { 0227 // TODO: For consistency in a bugfix all tracks are appended to one single array 0228 // Erroreous line: $this->Tracks[$disk->getAttribute('number')] = (string) $t->data; 0229 $this->Tracks[] = (string) $t->data; 0230 } 0231 } 0232 } else if ($result->length == 1) { 0233 foreach ($xpath->query('./*/text()', $result->item(0)) as $t) { 0234 $this->Tracks[] = (string) $t->data; 0235 } 0236 } 0237 0238 $result = $xpath->query('./az:Offers', $dom); 0239 $resultSummary = $xpath->query('./az:OfferSummary', $dom); 0240 if ($result->length > 1 || $resultSummary->length == 1) { 0241 /** 0242 * @see Zend_Service_Amazon_OfferSet 0243 */ 0244 // require_once 'Zend/Service/Amazon/OfferSet.php'; 0245 $this->Offers = new Zend_Service_Amazon_OfferSet($dom); 0246 } 0247 0248 $result = $xpath->query('./az:Accessories/*', $dom); 0249 if ($result->length > 1) { 0250 /** 0251 * @see Zend_Service_Amazon_Accessories 0252 */ 0253 // require_once 'Zend/Service/Amazon/Accessories.php'; 0254 foreach ($result as $r) { 0255 $this->Accessories[] = new Zend_Service_Amazon_Accessories($r); 0256 } 0257 } 0258 0259 $this->_dom = $dom; 0260 } 0261 0262 0263 /** 0264 * Returns the item's original XML 0265 * 0266 * @return string 0267 */ 0268 public function asXml() 0269 { 0270 return $this->_dom->ownerDocument->saveXML($this->_dom); 0271 } 0272 }