amazOOP amazOOP
[ class tree: amazOOP ] [ index: amazOOP ] [ all elements ]

Source for file other.class.php

Documentation is available at other.class.php

  1. <?php
  2.  
  3. /**
  4. * This file contains small, somewhat less important classes, that are created
  5. * when searching products through AWS.
  6. *
  7. * The classes that hold the most important information are {@link LiteDetails},
  8. * and {@link HeavyDetails}, which can be found in the {@link details.class.php} file.
  9. *
  10. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  11. * @copyright 2004 (c) Mauricio Diaz Orlich
  12. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  13. * @version 0.3RC1
  14. *
  15. * @package amazOOP
  16. */
  17.  
  18. /**
  19. * This is an abstract class from which the classes that are returned when querying AWS are created.
  20. *
  21. * As an abstract class, it should never be instantiated. You should take a look at {@link ProductInfo}
  22. * and {@link BlendedSearch} instead.
  23. *
  24. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  25. * @copyright 2004 (c) Mauricio Diaz Orlich
  26. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  27. * @version 0.3RC2
  28. *
  29. * @package amazOOP
  30. * @subpackage Responses
  31. */
  32. class AmazonResponse{
  33. /**#@+
  34. * @access private
  35. */
  36. /**
  37. * This is to indicate what type of search was made.
  38. * @var boolean
  39. */
  40. var $productInfo;
  41. /**
  42. * This is to indicate what type of search was made.
  43. * @var boolean
  44. */
  45. var $blendedSearch;
  46. /**
  47. * This is to indicate what type of search was made.
  48. * @var boolean
  49. */
  50. var $shoppingCart;
  51.  
  52. /**
  53. * The error message that is returned if the call fails.
  54. * @var string
  55. */
  56. var $errorMsg;
  57. /**
  58. * Details about current request.
  59. * @var array
  60. */
  61. var $request;
  62. /**
  63. * Number of product lines in current BlendedSearch.
  64. * @var integer
  65. */
  66. var $itemCount = 0;
  67. /**#@-*/
  68.  
  69. /**
  70. * Test to determine if the top node of the search is a {@link ProductInfo} node.
  71. *
  72. * This function is used to determine if the search returned a {@link ProductInfo}
  73. * node, as opposed to a {@link BlendedSearch} node.
  74. *
  75. * @return boolean this function returns true when called from this a {@link ProductInfo}
  76. * class and false when called from a {@link BlendedSearch} class.
  77. */
  78. function isProductInfo(){
  79. return $this->productInfo;
  80. }
  81.  
  82. /**
  83. * Test to determine if the top node of the search is a {@link BlendedSearch} node.
  84. *
  85. * This function is used to determine if the search returned a {@link BlendedSearch}
  86. * node, as opposed to a {@link ProductInfo} node.
  87. *
  88. * @return boolean this function returns false when called from this a {@link ProductInfo}
  89. * class and true when called from a {@link BlendedSearch} class.
  90. */
  91. function isBlendedSearch(){
  92. return $this->blendedSearch;
  93. }
  94.  
  95. /**
  96. * Test to determine if the top node of the search is a {@link ShoppingCartResponse} node.
  97. *
  98. * This function is used to determine if the search returned a {@link ShoppingCartResponse}
  99. * node, as opposed to a {@link ProductInfo} node, or a {@link BlendedSearch} node.
  100. *
  101. * @return boolean this function returns true when called from a {@link ShoppingCartResponse}
  102. * class, and false when called from a {@link ProductInfo}, or a {@link BlendedSearch} class.
  103. *
  104. * @since version 0.3RC2
  105. *
  106. */
  107. function isShoppingCart(){
  108. return $this->shoppingCart;
  109. }
  110.  
  111. /**
  112. * An error message returned by AWS.
  113. *
  114. * Currently this function returns a string with the error message returned by
  115. * AWS, if any. Hopefully, the next release of AWS will provide a numerical form
  116. * of the error messages also.
  117. *
  118. * @return string|booleanthe error message returned by AWS, or false if the is
  119. * no error message.
  120. */
  121. function getErrorMessage(){
  122. if(isset($this->errorMsg) && $this->errorMsg != "")
  123. return rawurldecode($this->errorMsg);
  124. else
  125. return false;
  126. }
  127.  
  128. /**
  129. * Gets an argument from the Request node of the AWS feed.
  130. *
  131. * These arguments include arguments submitted to Amazon when requesting
  132. * a new feed, plus some additional information added by AWS, such as
  133. * Request IDs.
  134. *
  135. * @return string|booleanthe value of the requested argument or false
  136. * if it does not exist.
  137. *
  138. * @modified 2004-05-15 15:44
  139. */
  140. function requestArgument($arg){
  141. if(isset($this->request[strtoupper($arg)]))
  142. return $this->request[strtoupper($arg)];
  143. else
  144. return false;
  145. }
  146. }
  147.  
  148. /**
  149. * This is one of the classes returned when querying AWS.
  150. *
  151. * This class is returned when you do one of the following queries:
  152. * - Actor
  153. * - Artist
  154. * - ASIN (*)
  155. * - ISBN (*)
  156. * - Author
  157. * - BrowseNode
  158. * - Director
  159. * - Keywords
  160. * - Manufacturer
  161. * - Power (not supported yet)
  162. * - Similarity
  163. * - UPC (*)
  164. *
  165. * (*) Will return at the most one product detail
  166. *
  167. * This class is also part of the results of a BlendedSearch
  168. *
  169. * @see AmazonQuery::query()
  170. * @see AmazonQuery::getCategory()
  171. *
  172. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  173. * @copyright 2004 (c) Mauricio Diaz Orlich
  174. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  175. * @version 0.3RC1
  176. *
  177. * @package amazOOP
  178. * @subpackage Responses
  179. */
  180. class ProductInfo extends AmazonResponse {
  181. /**#@+
  182. * @access private
  183. */
  184.  
  185. /**
  186. * Number of results (products) generated by search.
  187. * A search may genereate a large number of results,
  188. * nevertheless only a maximum of ten will be returned in each query.
  189. * To obtain the next set of results, you must requet the next page
  190. * of your serach.
  191. * @var integer
  192. */
  193. var $totalResults;
  194. /**
  195. * Number of pages of results generated by search.
  196. * @var integer
  197. */
  198. var $totalPages;
  199.  
  200. /**
  201. * An array of product [details]. The objects in the array can be of type
  202. * {@link LiteDetails} or {@link HeavyDetails}, depending of what type of
  203. * query you are doing.
  204. * @var LiteDetails|HeavyDetails.
  205. * @see LiteDetails
  206. * @see HeavyDetails
  207. * @see AmazonQuery::query()
  208. */
  209. var $details;
  210.  
  211. /**#@-*/
  212.  
  213. /**
  214. * Default constructor.
  215. *
  216. * Prepares the class.
  217. */
  218. function ProductInfo(){
  219. $this->productInfo = true;
  220. $this->blendedSearch = false;
  221. $this->shoppingCart = false;
  222. }
  223.  
  224. /**
  225. * The number of the first result returned.
  226. *
  227. * For example, if you are on page one, the first result is result number 1,
  228. * if you are in page 3, the first result is result 21, and so on...
  229. *
  230. * @return integer the number of the first result generated by the search.
  231. *
  232. * @see resultsHigh()
  233. */
  234. function resultsLow(){
  235. if($this->requestArgument('page')){
  236. $page = $this->requestArgument('page');
  237. return ((($page-1)*10)+1);
  238. }
  239. else
  240. return 0;
  241. }
  242.  
  243. /**
  244. * The number of the last result returned.
  245. *
  246. * For example, if you are on page one, the last result can be result number 10,
  247. * or a lower number. If you are in page 3, the last result is result can be 30,
  248. * or a lower number, and so on...
  249. *
  250. * @return integer the number of the last result generated by the search.
  251. *
  252. * @see resultsLow()
  253. */
  254. function resultsHigh(){
  255. if($this->requestArgument('page')){
  256. return (($this->resultsLow()+$this->itemCount)-1);
  257. }
  258. else
  259. return 0;
  260. }
  261.  
  262. /**
  263. * Number of results (products) generated by a search.
  264. * A search may genereate a large number of results,
  265. * nevertheless only a maximum of ten will be returned in each query.
  266. * To obtain the next set of results, you must requet the next page
  267. * of your serach.
  268. *
  269. * @return integer the total number of results generated by the search.
  270. */
  271. function getTotalResults(){
  272. if(isset($this->totalResults) && $this->totalResults != "")
  273. return rawurldecode($this->totalResults);
  274. elseif(!$this->getErrorMessage())
  275. return 1;
  276. else
  277. return 0;
  278. }
  279.  
  280. /**
  281. * Number of pages of results generated by a search.
  282. *
  283. * @return integer the number of pages of results generated by the search.
  284. */
  285. function getTotalPages(){
  286. if(isset($this->totalPages) && $this->totalPages != "")
  287. return rawurldecode($this->totalPages);
  288. elseif(!$this->getErrorMessage())
  289. return 1;
  290. else
  291. return 0;
  292. }
  293.  
  294. /**
  295. * Gets one of the objects containing product details.
  296. *
  297. * This object can be of type {@link LiteDetails} or {@link HeavyDetails}, depending
  298. * on what type of search you are making.
  299. *
  300. * @param integer $number the object you want to get from the list. If set to 0 (default),
  301. * a random object from the list is returned.
  302. *
  303. * @return LiteDetails|HeavyDetails|booleanthe details of the requested product from the list,
  304. * or false if the requested position of the list does not contain product details.
  305. *
  306. * @see LiteDetails
  307. * @see HeavyDetails
  308. */
  309. function getDetails($number = 0){
  310. if($number == 0)
  311. $number = rand(1, $this->itemCount);
  312.  
  313. if(isset($this->details[$number-1])){
  314. $details = &$this->details[$number-1];
  315.  
  316. $details->locale = $this->requestArgument('LOCALE');
  317. return $this->details[$number-1];
  318. }
  319. else
  320. return false;
  321. }
  322. }
  323.  
  324. /**
  325. * This is one of the classes returned when querying AWS.
  326. *
  327. * This class is only returned when you query AWS doing a BlendedSearch.
  328. *
  329. * @see AmazonQuery::query()
  330. *
  331. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  332. * @copyright 2004 (c) Mauricio Diaz Orlich
  333. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  334. * @version 0.3RC1
  335. *
  336. * @package amazOOP
  337. * @subpackage Responses
  338. */
  339. class BlendedSearch extends AmazonResponse {
  340. /**#@+
  341. * @access private
  342. */
  343. /**
  344. * Array of product lines.
  345. * @var array
  346. */
  347. var $productLines;
  348.  
  349. /**#@-*/
  350.  
  351. /**
  352. * Default constructor.
  353. *
  354. * Prepares the class.
  355. */
  356. function BlendedSearch(){
  357. $this->productInfo = false;
  358. $this->blendedSearch = true;
  359. $this->shoppingCart = false;
  360. }
  361.  
  362. /**
  363. * Gets one of the product lines returned by the Blended search.
  364. *
  365. * A Product Line is an object wich contains a {@link ProductLine::getMode() mode} and
  366. * a {@link ProductInfo} object.
  367. *
  368. * Product lines are returned by AWS in no particular order. As far as I know, up to 15
  369. * product lines can be returned in each search.
  370. *
  371. * @param integer $number the product line you want to get from the list. If set to 0 (default),
  372. * a random product line from the list is returned.
  373. *
  374. * @return ProductLine|booleanthe requested product line from the list,
  375. * or false if the requested position of the list does not contain a product line.
  376. *
  377. * @see ProductLine
  378. */
  379. function getProductLine($number = 0){
  380. if($number == 0)
  381. $number = rand(1, $this->itemCount);
  382.  
  383. if(isset($this->productLines[$number-1])){
  384. return $this->productLines[$number-1];
  385. }
  386. else
  387. return false;
  388. }
  389.  
  390. }
  391.  
  392. /**
  393. * This class contains a mode and a {@link ProductInfo} object.
  394. *
  395. * This class generated when you do a {@link BlendedSearch}. It contains a
  396. * {@link getMode() mode} corresponding to the AWS mode, and a {@link ProductInfo}
  397. * object which contains one or more product details of {@link LiteDetails} or
  398. * {@link HeavyDeatils} type, depending on the type you requested from Amazon.
  399. *
  400. * @see BlendedSearch
  401. * @see ProductInfo
  402. *
  403. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  404. * @copyright 2004 (c) Mauricio Diaz Orlich
  405. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  406. * @version 0.3RC1
  407. *
  408. * @package amazOOP
  409. */
  410. class ProductLine {
  411. /**#@+
  412. * @access private
  413. */
  414. /**
  415. * The product line's mode
  416. * @var string
  417. */
  418. var $mode;
  419. /**
  420. * A {@link ProductInfo} object containing detailed information about
  421. * the products returned by the search.
  422. * @var ProductInfo
  423. */
  424. var $productInfo;
  425. /**#@-*/
  426.  
  427. /**
  428. * Gets the mode for this product line.
  429. *
  430. * @return string this product line's mode.
  431. */
  432. function getMode(){
  433. return rawurldecode($this->mode);
  434. }
  435. /**
  436. * Gets the {@link ProductInfo} object containing more the products
  437. * returned by the search on this product line's mode.
  438. */
  439. function getProductInfo(){
  440. return $this->productInfo;
  441. }
  442. }
  443.  
  444. /**
  445. * This class contains information about the product's ranking
  446. * as well as customer and editorial reviews.
  447. *
  448. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  449. * @copyright 2004 (c) Mauricio Diaz Orlich
  450. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  451. * @version 0.3RC1
  452. *
  453. * @package amazOOP
  454. */
  455. class Reviews{
  456. /**#@+
  457. * @access private
  458. */
  459. /**
  460. * The average review given by Amazon customers.
  461. * This is a number between 0 and 5. Where 0 doesn't necessariliy mean
  462. * that the product is terrible, it can also mean that it hasn't been
  463. * reviewed yet.
  464. * @var float
  465. */
  466. var $avgReview;
  467. /**
  468. * The total number of reviews this item has received.
  469. * @var integer
  470. */
  471. var $totalReviews;
  472. /**
  473. * An array holding {@link CustomerReview} objects which obviously contain
  474. * customer reviews.
  475. * @var CustomerReview
  476. */
  477. var $customerReviews;
  478. /**#@-*/
  479.  
  480. /**
  481. * Gets the average review given by Amazon customers.
  482. *
  483. * This is a number between 0 and 5. Where 0 doesn't necessariliy mean
  484. * that the product is terrible, it can also mean that it hasn't been
  485. * reviewed yet.
  486. *
  487. * @return float the average review given to the product by Amazon customers.
  488. */
  489. function getAvgReview(){
  490. if(isset($this->avgReview) && $this->avgReview != "")
  491. return $this->avgReview;
  492. else
  493. return 0;
  494. }
  495.  
  496. /**
  497. * Gets the total number of reviews this item has received.
  498. *
  499. * @return integer the total number of reviews received by the product.
  500. */
  501. function getTotalReviews(){
  502. if(isset($this->totalReviews) && $this->totalReviews != "")
  503. return $this->totalReviews;
  504. else
  505. return 0;
  506. }
  507.  
  508. /**
  509. * Gets a Customer Review for the current product.
  510. *
  511. * A Customer Review is an object of type {@link CustomerReview} which contains the following
  512. * information:
  513. * - The customer's rating in the scale of 0-5
  514. * - A summary of the customer's review
  515. * - The customer's review
  516. *
  517. * Currently, AWS returns 0-3 reviews for each product.
  518. *
  519. * @param integer $number the product line you want to get from the list. If set to 0 (default),
  520. * a random product line from the list is returned.
  521. *
  522. * @return CustomerReview|booleanthe requested customer review from the list,
  523. * or false if the requested position of the list does not contain a review.
  524. *
  525. * @see CustomerReview
  526. */
  527. function getCustomerReview($number = 0){
  528. if($number == 0)
  529. $number = rand(1, sizeof($this->customerReviews));
  530.  
  531. if(isset($this->customerReviews[$number-1])){
  532. return $this->customerReviews[$number-1];
  533. }
  534. else
  535. return false;
  536. }
  537. }
  538.  
  539. /**
  540. * This class hold Amazon customer reviews.
  541. *
  542. * Each review consists of a 0-5 rating, a one-line summary of the review, and
  543. * the customer review.
  544. *
  545. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  546. * @copyright 2004 (c) Mauricio Diaz Orlich
  547. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  548. * @version 0.3RC1
  549. *
  550. * @package amazOOP
  551. */
  552. class CustomerReview{
  553. /**#@+
  554. * @access private
  555. */
  556. /**
  557. * The customer's rating in the scale of 0-5
  558. * @var float
  559. */
  560. var $rating;
  561. /**
  562. * A one-line summary of the customer's review
  563. * @var string
  564. */
  565. var $summary;
  566. /**
  567. * The whole review
  568. * @var string
  569. */
  570. var $comment;
  571. /**#@-*/
  572.  
  573. /**
  574. * Gets the customer's rating for this product
  575. *
  576. * @return float the customer's rating in the scale of 0-5
  577. */
  578. function getRating(){
  579. if(isset($this->rating) && $this->rating != "")
  580. return $this->rating;
  581. else
  582. return 0;
  583. }
  584.  
  585. /**
  586. * Get the summary of the customer's review.
  587. *
  588. * The summary consists of one line describing the review.
  589. *
  590. * @return string the summary of the customer's review.
  591. */
  592. function getSummary(){
  593. return rawurldecode($this->summary);
  594. }
  595.  
  596. /**
  597. * Gets the customer's review for this product.
  598. *
  599. * @param integer $words the number of words you want to get, or 0 if you want
  600. * the whole review.
  601. * @param string $end the character(s) to be appended at the end of the review
  602. * in case the whole text is not returned.
  603. *
  604. * @return string the customer's review for the current product, or at
  605. * least the number of words requested.
  606. */
  607. function getReview($words = 0, $end = "..."){
  608. if($words == 0)
  609. return rawurldecode($this->comment);
  610. else{
  611. $wordArray = preg_split("/[\s]/", rawurldecode($this->comment));
  612.  
  613. $res = "";
  614. $words = min($words, sizeof($wordArray));
  615. for($i = 0; $i < $words; $i++){
  616. $res .= $wordArray[$i];
  617. if($i != $words-1)
  618. $res .= " ";
  619. }
  620. if($words < sizeof($wordArray))
  621. $res .= $end;
  622. return $res;
  623. }
  624. }
  625. }
  626.  
  627. /**
  628. * This class contains information about a Browse Node.
  629. *
  630. * According to the AWS documentation, when a product returns a list of browse nodes,
  631. * all it returns is the name of browse nodes in which the product appears. However,
  632. * lately a node ID has also been returned, corresponding to the actual browse node
  633. * used at Amazon.
  634. *
  635. * Use this information as you wish.
  636. *
  637. * @author Mauricio Diaz <madd0@users.sourceforge.net>
  638. * @copyright 2004 (c) Mauricio Diaz Orlich
  639. * @license http://www.gnu.org/licenses/gpl.html GNU General Public License
  640. * @version 0.3RC1
  641. *
  642. * @package amazOOP
  643. */
  644. class BrowseNode{
  645. /**#@+
  646. * @access private
  647. */
  648. /**
  649. * The node ID of the current node. This is what is needed to query AWS
  650. * @var integer
  651. */
  652. var $nodeId;
  653. /**
  654. * The node's name. Nice to know, but not very useful
  655. * @var string
  656. */
  657. var $nodeName;
  658. /**#@-*/
  659.  
  660. /**
  661. * Checks whether AWS returned a node ID.
  662. *
  663. * @return boolean true if a node ID was returned, false otherwise.
  664. */
  665. function hasNodeId(){
  666. return (isset($this->nodeId) && $this->nodeId != "");
  667. }
  668.  
  669. /**
  670. * The node ID of the current node. This is what is needed to query AWS.
  671. *
  672. * @return integer|booleanthe node's ID, or false if no ID exists.
  673. */
  674. function getNodeId(){
  675. if($this->hasNodeId())
  676. return $this->nodeId;
  677. else
  678. return false;
  679. }
  680.  
  681. /**
  682. * The node's name. Nice to know, but not very useful...
  683. *
  684. * @param boolean $decoded whether you want the node's name to be returned
  685. * decoded or URL encoded.
  686. *
  687. * @return string|booleanthe node's name, or false if no name is set.
  688. */
  689. function getNodeName($decoded = true){
  690. if(isset($this->nodeName) && $this->nodeName != "")
  691. if($decoded)
  692. return rawurldecode($this->nodeName);
  693. else
  694. return $this->nodeName;
  695. else
  696. return false;
  697. }
  698. }
  699.  
  700. ?>
 
Documentation generated on Sat, 21 Aug 2004 17:40:41 +0200 by phpDocumentor 1.3.0RC3
hosted by
SourceForge.net Logo