public static function completeInfos(Book &$book) { try { $config = self::getConfig(); $googleBook = new \Sb\Google\Model\GoogleBook($book->getISBN10(), $book->getISBN13(), $book->getASIN(), $config->getGoogleApiKey()); if ($googleBook->getVolumeInfo()) { $bookFromGoogle = new Book(); \Sb\Db\Mapping\BookMapper::mapFromGoogleBookVolumeInfo($bookFromGoogle, $googleBook->getVolumeInfo()); if (!$book->getDescription() && $bookFromGoogle->getDescription()) { $book->setDescription($bookFromGoogle->getDescription()); } if (!$book->getImageUrl() && $bookFromGoogle->getImageUrl()) { $book->setImageUrl($bookFromGoogle->getImageUrl()); } if (!$book->getSmallImageUrl() && $bookFromGoogle->getSmallImageUrl()) { $book->setSmallImageUrl($bookFromGoogle->getSmallImageUrl()); } if (!$book->getPublishingDate() && $bookFromGoogle->getPublishingDate()) { $book->setPublishingDate($bookFromGoogle->getPublishingDate()); } } else { \Sb\Trace\Trace::addItem('Le livre n\'a pas été trouvé sur Google.'); } } catch (\Exception $exc) { $message = sprintf("Une erreur s'est produite lors de l'appel à l'api google books : %s", $exc->getMessage()); MailSvc::getInstance()->send(Constants::WEBMASTER_EMAIL, "Erreur interne", $message); \Sb\Trace\Trace::addItem($message); } }
public function setDescription($description) { $this->__load(); return parent::setDescription($description); }
public static function mapFromAmazonResult(\Sb\Db\Model\Book &$book, \Zend_Service_Amazon_Item $amazonResult) { if (isset($amazonResult->Language)) { $book->setLanguage($amazonResult->Language); } if (isset($amazonResult->Author)) { $contributors = new \Doctrine\Common\Collections\ArrayCollection(); if (is_array($amazonResult->Author)) { foreach ($amazonResult->Author as $author) { $contributor = new \Sb\Db\Model\Contributor(); $contributor->setFullName($author); $contributors->add($contributor); } } else { $contributor = new \Sb\Db\Model\Contributor(); $contributor->setFullName($amazonResult->Author); $contributors->add($contributor); } $book->setContributors($contributors); } if (isset($amazonResult->EditorialReviews)) { if (count($amazonResult->EditorialReviews) > 0) { //$book->setDescription($amazonResult->EditorialReviews[0]->Content); // Replace all HTML in description by ' ' to prevent bad formatting HTML $book->setDescription(preg_replace('/<[^>]*>/', ' ', $amazonResult->EditorialReviews[0]->Content)); } } if (isset($amazonResult->ISBN)) { $book->setISBN10($amazonResult->ISBN); } if (isset($amazonResult->EAN)) { $book->setISBN13($amazonResult->EAN); } if (isset($amazonResult->ASIN)) { $book->setASIN($amazonResult->ASIN); } if (isset($amazonResult->SmallImage)) { if ($amazonResult->SmallImage && $amazonResult->SmallImage->Url) { $book->setSmallImageUrl($amazonResult->SmallImage->Url->getUri()); } } if (isset($amazonResult->MediumImage)) { if ($amazonResult->MediumImage && $amazonResult->MediumImage->Url) { $book->setImageUrl($amazonResult->MediumImage->Url->getUri()); } } if (isset($amazonResult->LargeImage)) { if ($amazonResult->LargeImage && $amazonResult->LargeImage->Url) { $book->setLargeImageUrl($amazonResult->LargeImage->Url->getUri()); } } //Publisher if (isset($amazonResult->PublicationDate)) { $book->setPublishingDate(\Sb\Helpers\DateHelper::createDate($amazonResult->PublicationDate)); } if (isset($amazonResult->Publisher)) { $publisher = new \Sb\Db\Model\Publisher(); $publisher->setName($amazonResult->Publisher); $book->setPublisher($publisher); } if (isset($amazonResult->Title)) { $book->setTitle($amazonResult->Title); } if (isset($amazonResult->DetailPageURL)) { $book->setAmazonUrl($amazonResult->DetailPageURL); } if (isset($amazonResult->NumberOfPages)) { $book->setNb_of_pages($amazonResult->NumberOfPages); } }