/** * * @return array of Books (of type Book) from Amazon */ private function getAmazonResults($searchTerm, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested, $amazonSite) { $amazonService = new \Zend_Service_Amazon($amazonApiKey, $amazonSite, $amazonSecretKey); $amazonResults = null; // tableau d'amazon item recu directement $booksFromAmazon = null; // tableau d'objet Book reçu depuis amazon $responsesGroups = 'Small,ItemAttributes,Images,EditorialReview,Reviews,BrowseNodes,OfferSummary'; //$version = '2005-10-05'; $nbPageRequested = $amazonNumberOfPageRequested; $nbMaxPageRequested = 5; if ($nbPageRequested > $nbMaxPageRequested) { $nbPageRequested = $nbMaxPageRequested; } for ($itemPageNum = 1; $itemPageNum <= $nbPageRequested; $itemPageNum++) { $tmpAmazonResults = null; // recherche faite sur le code isbn10 if (strlen($searchTerm) == 10) { $tmpAmazonResults = $amazonService->itemSearch(array('SearchIndex' => 'Books', 'AssociateTag' => $amazonAssociateTag, 'ResponseGroup' => $responsesGroups, 'Power' => 'isbn:' . $searchTerm, 'ItemPage' => $itemPageNum)); if (!$tmpAmazonResults || $tmpAmazonResults->totalResults() == 0) { $tmpAmazonResults = $amazonService->itemSearch(array('SearchIndex' => 'Books', 'AssociateTag' => $amazonAssociateTag, 'ResponseGroup' => $responsesGroups, 'Power' => 'asin:' . $searchTerm, 'ItemPage' => $itemPageNum)); } } // recherche faite sur le mot clé if (!$tmpAmazonResults || $tmpAmazonResults->totalResults() == 0) { $tmpAmazonResults = $amazonService->itemSearch(array('SearchIndex' => 'Books', 'AssociateTag' => $amazonAssociateTag, 'ResponseGroup' => $responsesGroups, 'Keywords' => $searchTerm, 'ItemPage' => $itemPageNum)); } $amazonResults = $tmpAmazonResults; // mapping des résultats amazon en objet Book if ($amazonResults) { foreach ($amazonResults as $amazonResult) { $result = new \Sb\Db\Model\Book(); \Sb\Db\Mapping\BookMapper::mapFromAmazonResult($result, $amazonResult); // Book is added to the collection only if // author is set // and ISBN10, ISBN13 or ASIN is set if (count($result->getContributors()) > 0) { if ($result->getISBN10() || $result->getISBN13() || $result->getASIN()) { $booksFromAmazon[$result->getISBN10()] = $result; } } } } } return $booksFromAmazon; }
private function getBooksFromAmazon($isbns, Config $config) { \Sb\Trace\Trace::addItem(count($isbns) . " Isbns vont être requetés à Amazon : " . implode(",", $isbns)); $booksFromAmazon = array(); for ($index = 0; $index < count($isbns); $index = $index + 10) { $isbnsSlice = array_slice($isbns, $index, 10); \Sb\Trace\Trace::addItem(count($isbnsSlice) . " Isbns requetés par requête Amazon : " . implode(",", $isbnsSlice)); $amazonService = new Zend_Service_Amazon($config->getAmazonApiKey(), 'FR', $config->getAmazonSecretKey()); $responsesGroups = 'Small,ItemAttributes,Images,EditorialReview,Reviews'; // Recherche d'une liste de livre $amazonResults = $amazonService->itemLookup(implode(",", $isbnsSlice), array('SearchIndex' => 'Books', 'AssociateTag' => $config->getAmazonAssociateTag(), 'ResponseGroup' => $responsesGroups, 'IdType' => 'ISBN')); if ($amazonResults) { $i = 0; foreach ($amazonResults as $amazonResult) { $result = new \Sb\Db\Model\Book(); \Sb\Db\Mapping\BookMapper::mapFromAmazonResult($result, $amazonResult); if ($result->IsValid()) { $i++; $booksFromAmazon[] = $result; } //var_dump($booksFromAmazon); } \Sb\Trace\Trace::addItem($i . " trouvés lors de cette requête amazon."); } } return $booksFromAmazon; }