/**
  * 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);
     }
 }
示例#2
0
 private function addUserBook(\Sb\Db\Model\Book $book, \Sb\Db\Model\User $user, \Sb\Config\Model\Config $config)
 {
     $userBookDao = UserBookDao::getInstance();
     $userBook = $userBookDao->getByBookIdAndUserId($user->getId(), $book->getId());
     // Testing if the user :
     // - doesn't already have that book or
     // - have it but is deleted : in this case we will undelete the book
     if ($userBook && !$userBook->getIs_deleted()) {
         $returnMsg = __("Vous avez déjà ce livre dans votre bibliothèque.", "s1b");
     } else {
         // Getting current user current nb userbooks in libary
         $userNbUserBooks = count($user->getNotDeletedUserBooks());
         if ($userNbUserBooks >= $config->getMaximumNbUserBooksForPublic()) {
             $returnMsg = sprintf(__("Vous ne pouvez pas avoir plus de %s livres dans votre bibliothèque.", "s1b"), $config->getMaximumNbUserBooksForPublic());
         } else {
             // Ajout du UserBook
             $existingUserBook = false;
             $userBook = UserBookDao::getInstance()->getByBookIdAndUserId($user->getId(), $book->getId());
             // testing if the user already had the book but deleted it :
             // if yes, then the userbook is undeleted
             if ($userBook && $userBook->getIs_deleted()) {
                 $userBook->setIs_deleted(false);
                 $existingUserBook = true;
             } else {
                 // Création du UserBoook
                 $userBook = new \Sb\Db\Model\UserBook();
                 $userBook->setCreationDate(new \DateTime());
             }
             // Updating userbook data
             $userBook->setLastModificationDate(new \DateTime());
             $userBook->setUser($user);
             $userBook->setBook($book);
             $bookLink = \Sb\Helpers\HTTPHelper::Link($book->getLink());
             // Persisting userbook in DB
             $addOk = false;
             if ($existingUserBook) {
                 if (UserBookDao::getInstance()->update($userBook)) {
                     $editUserBookLink = \Sb\Helpers\HTTPHelper::Link(\Sb\Entity\Urls::USER_BOOK_EDIT, array("ubid" => $userBook->getId()));
                     $returnMsg = sprintf(__("Vous aviez déjà le livre \"%s\" dans votre bibliothèque mais l'aviez supprimé. Il a été rajouté.<br/><a class=\"link\" href=\"%s\">Remplir votre fiche de lecture</a> ou <a class=\"link\" href=\"%s\">Voir ce livre</a>", "s1b"), $book->getTitle(), $editUserBookLink, $bookLink);
                     $addOk = true;
                 }
             } else {
                 if (UserBookDao::getInstance()->add($userBook)) {
                     $editUserBookLink = \Sb\Helpers\HTTPHelper::Link(\Sb\Entity\Urls::USER_BOOK_EDIT, array("ubid" => $userBook->getId()));
                     $returnMsg = sprintf(__("Le livre \"%s\" a été ajouté à votre bibliothèque.<br/><a class=\"link\" href=\"%s\">Remplir votre fiche de lecture</a> ou <a class=\"link\" href=\"%s\">Voir ce livre</a>", "s1b"), $book->getTitle(), $editUserBookLink, $bookLink);
                     $addOk = true;
                 }
             }
             if ($addOk) {
                 try {
                     $userEvent = new \Sb\Db\Model\UserEvent();
                     $userEvent->setItem_id($userBook->getId());
                     $userEvent->setType_id(\Sb\Entity\EventTypes::USERBOOK_ADD);
                     $userEvent->setUser($user);
                     \Sb\Db\Dao\UserEventDao::getInstance()->add($userEvent);
                 } catch (\Exception $exc) {
                     Trace::addItem("Une erreur s'est produite lors de l'ajout de l'événement suite à l'ajout d'un livre " . $exc->getMessage());
                 }
             }
         }
     }
     return $returnMsg;
 }
示例#3
0
 /**
  * Get the book id, called in array_map
  * @param \Sb\Db\Model\Book $book
  * @return type
  */
 private function getId(Book $book)
 {
     return $book->getId();
 }
示例#4
0
 public static function recommandationBody(\Sb\Db\Model\Book $book)
 {
     $body = __("Découvrez", "s1b") . " " . "<a href='" . \Sb\Helpers\HTTPHelper::Link($book->getLink()) . "'>" . $book->getTitle() . "</a>" . " " . __("de", "s1b") . " " . $book->getOrderableContributors() . '<br/><br/>' . __("L'équipe", "s1b") . " " . \Sb\Entity\Constants::SITENAME . '<br/><br/>' . self::getProfileEditSettingLine();
     return $body;
 }
 public function getLink()
 {
     $this->__load();
     return parent::getLink();
 }
示例#6
0
 /**
  *
  * @param type $results
  */
 public function extractKey(\Sb\Db\Model\Book $book)
 {
     return $book->getISBN10();
 }
示例#7
0
 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);
     }
 }
示例#8
0
 public function setBook(\Sb\Db\Model\Book $book)
 {
     $this->book = $book;
     $book->addUserBook($this);
 }
示例#9
0
 /**
  * Get e book with contributors
  * @param \Sb\Db\Model\Book $book
  * @return \Sb\Db\Model\Book
  */
 private function getFullBook(\Sb\Db\Model\Book $book)
 {
     $contributors = \Sb\Db\Dao\ContributorDao::getInstance()->getListForBook($book->getId());
     $book->setContributors($contributors);
     return $book;
 }
示例#10
0
 private function getIsbnFromBook(\Sb\Db\Model\Book $book)
 {
     return $book->getISBN10();
 }
示例#11
0
 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);
     }
 }