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); } }
/** * Get a HeaderInformation from a book object : used on book pages * @param \Sb\Service\Sb\Db\Model\Book $book a book object * @return \Sb\Model\HeaderInformation HeaderInformation object for book pages */ public function get(Book $book) { try { $result = new HeaderInformation(); // Set url canonical $result->setUrlCanonical(HTTPHelper::Link($book->getLink())); // Set title tag $publisherName = ""; if ($book->getPublisher()) { $publisherName = $book->getPublisher()->getName(); } // // Get if book is an ebook $bookIsEbook = !$book->getISBN10() && substr($book->getASIN(), 0, 1) == "B"; // For tag title, maximum length recommended is 60 $titlePrefix = ""; if ($bookIsEbook) { $titlePrefix = "ebook "; } // $title = StringHelper::tronque(sprintf(__("%s de %s par %s", "s1b"), $book->getTitle(), $book->getOrderableContributors(), $publisherName), 60 - strlen("...") - strlen($titlePrefix)); $title = $titlePrefix . $title; $result->setTitle($title); // Set description // For meta description, maximum length recommended is 160 $descriptionSuffix = ""; if ($bookIsEbook) { $descriptionSuffix = " | numérique"; } // $description = StringHelper::tronque($book->getDescription(), 160 - strlen("...") - strlen($descriptionSuffix)); $description .= $descriptionSuffix; // Remove double quotes $result->setDescription(str_replace("\"", "", $description)); // Set keywords // Get 2 first tags for keywords $bookTags = TagSvc::getInstance()->getTagsForBooks(array($book)); $tags = ""; if ($bookTags && count($bookTags) > 0) { $firstTags = array_slice($bookTags, 0, 5); $firstTagNames = array_map(array(&$this, "getTagName"), $firstTags); $tags = implode(" | ", $firstTagNames); } $keywords = sprintf(__("%s | %s | %s", "s1b"), $book->getTitle(), $book->getOrderableContributors(), $publisherName); if ($tags != "") { $keywords = sprintf(__("%s | %s | %s | %s", "s1b"), $book->getTitle(), $book->getOrderableContributors(), $publisherName, $tags); } // // Remove double quotes $keywords = str_replace("\"", "", $keywords); $result->setKeywords($keywords); // Set page image $result->setPageImage($book->getImageUrl()); return $result; } catch (\Exception $exc) { $this->logException(get_class(), __FUNCTION__, $exc); } }
/** * * @param type $results */ public function extractKey(\Sb\Db\Model\Book $book) { return $book->getISBN10(); }
public function getISBN10() { $this->__load(); return parent::getISBN10(); }
private function getIsbnFromBook(\Sb\Db\Model\Book $book) { return $book->getISBN10(); }