/** * 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); } }
public function getPublisher() { $this->__load(); return parent::getPublisher(); }