/** * 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); } }
private function addCommonListItemsToModelView($pageNumber, $tagId, $searchTerm, $pressReviews, $pressReviewTypeId) { if (!$pageNumber) { $pageNumber = 1; } // // Add press review list to model view $pressReviewsPaginated = $this->getPressReviewsPaginated($pressReviews, $pageNumber, $pressReviewTypeId == PressReviewTypes::ARTICLE ? 10 : 5); $pagesPressReviews = $pressReviewsPaginated->getItems(); $this->view->pressReviews = $pagesPressReviews; // Get tags and add it to model view $tags = TagSvc::getInstance()->getTagsForPressReviews(); // Add reinit url to model view switch ($pressReviewTypeId) { case PressReviewTypes::ARTICLE: $initUrl = $this->view->url(array(), 'articlePressReviews'); $searchLabel = __("Rechercher un article", "s1b"); break; case PressReviewTypes::VIDEO: $initUrl = $this->view->url(array(), 'videoPressReviews'); $searchLabel = __("Rechercher une vidéo", "s1b"); break; } // Get search content form and add it to model view $contentSearch = new ContentSearch("/default/press-review/search", $tags, $tagId, $searchLabel, $pressReviewTypeId, $searchTerm, $initUrl); $this->view->contentSearch = $contentSearch->get(); // Get press review subscription module and add it to view model $pressReviewSubscriptionWidget = new PressReviewsSubscriptionWidget(); $this->view->pressReviewSubscriptionWidget = $pressReviewSubscriptionWidget->get(); // Add navigation bar to view model $this->view->navigationBar = $pressReviewsPaginated->getNavigationBar(); // Get ad and add it to view model $ad = new Ad("", ""); $this->view->ad = $ad->get(); // Get chronicles for right column widget and add to view model $chroniclesTitle = ""; $chronicles = null; if ($tagId) { $chroniclesTitle = __("<strong>Chroniques</strong> dans la même catégorie", "s1b"); $chronicles = ChronicleSvc::getInstance()->getChroniclesWithTags(array($tagId), 5); } else { $chroniclesTitle = __("Dernières chroniques", "s1b"); $chronicles = ChronicleSvc::getInstance()->getLastChronicles(5); } if (count($chronicles) > 0) { $chronicleAdapter = new ChronicleListAdapter(); $chronicleAdapter->setChronicles($chronicles); $chroniclesView = new ChroniclesBlock($chronicleAdapter->getAsChronicleViewModelLightList(), $chroniclesTitle); $this->view->chroniclesView = $chroniclesView->get(); } // Get books with press reviews for right column $this->view->placeholder('footer')->append("<script src=\"" . BASE_URL . 'Resources/js/waterwheel-carousel/jquery.waterwheelCarousel.min.js' . "\"></script>\n"); $this->view->placeholder('footer')->append("<script>\$(function () {initCoverFlip('booksWithPressReviews', 30)});</script>\n"); $books = BookSvc::getInstance()->getListWithPressReviews(15); $booksCoverFlip = new BookCoverFlip($books, __("Les livres dont parlent <strong>les médias</strong>", "s1b"), "booksWithPressReviews", ""); $this->view->booksCoverFlip = $booksCoverFlip->get(); // Add SEO (title, meta description and keywords) $routeName = Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName(); $headerInformation = HeaderInformationSvc::getInstance()->getByRouteName($routeName); $this->view->tagTitle = $headerInformation->getTitle(); $this->view->metaDescription = $headerInformation->getDescription(); $this->view->metaKeywords = $headerInformation->getKeywords(); }
private function getChroniclesRelativeToBook(Book $book) { $chronicles = null; // Get book userbook's tag $bookTags = TagSvc::getInstance()->getTagsForBooks(array($book), false); $bookTagIds = null; foreach ($bookTags as $bookTag) { /* @var $bookTag Tag */ $bookTagIds[] = $bookTag->getId(); } // Get 3 chronicles with same tags if ($bookTags && count($bookTags) > 0) { $chronicles = ChronicleSvc::getInstance()->getChroniclesWithTags($bookTagIds, 3, false); } // // Get last chronicles of any types and add them to previously set list of chronicles if (!$chronicles || count($chronicles) < 3) { $lastChronicles = ChronicleSvc::getInstance()->getLastChronicles(3); foreach ($lastChronicles as $lastChronicle) { $add = true; if ($chronicles) { foreach ($chronicles as $chronicle) { if ($chronicle->getId() == $lastChronicle->getId()) { $add = false; break; } } } if ($add) { $chronicles[] = $lastChronicle; } } } if ($chronicles) { $chronicles = array_slice($chronicles, 0, 3); } return $chronicles; }
public function get() { $baseTpl = "book/bookForm/userBook"; $readingStateSvc = \Sb\Db\Service\ReadingStateSvc::getInstance(); $readingStates = $readingStateSvc->getReadingStates(); $readingStateOptions = ""; if ($readingStates) { foreach ($readingStates as $readingState) { $selected = ""; if ($this->userBook->getReadingState() && $readingState->getId() == $this->userBook->getReadingState()->getId()) { $selected = "selected"; } $readingStateOptions .= "<option value='" . $readingState->getId() . "' {$selected}>" . $readingState->getLabel() . "</option>"; } } $readState = $readingStateSvc->getReadSate(); $tpl = new \Sb\Templates\Template($baseTpl); $tpl->set("id", $this->userBook->getId()); if ($this->userBook->getUser()) { $tpl->set("userid", $this->userBook->getUser()->getId()); } else { $tpl->set("userid", ""); } if ($this->userBook->getBook()) { $tpl->set("bookid", $this->userBook->getBook()->getId()); } else { $tpl->set("bookid", ""); } if ($this->addMode) { $tpl->set("pictos", ""); } else { $tpl->set("pictos", \Sb\Helpers\UserBookHelper::getStatusPictos($this->userBook)); } $tpl->set("readingStateOptions", $readingStateOptions); $tpl->set("review", $this->userBook->getReview()); $rating = $this->userBook->getRating(); if (isset($rating)) { $ratingCssClass = "rating-" . $rating; } else { $ratingCssClass = "no-rating"; } $tpl->set("ratingCssClass", $ratingCssClass); $tpl->set("rating", $rating); if ($this->userBook->getReadingState()) { $tpl->set("displayReadingDateBlock", $this->userBook->getReadingState()->getId() != \Sb\Entity\ReadingStates::READ ? "noDisplay" : ""); $displayNbPagesRead = $this->userBook->getReadingState()->getId() != \Sb\Entity\ReadingStates::READING ? "noDisplay" : ""; } else { $tpl->set("displayReadingDateBlock", "noDisplay"); $displayNbPagesRead = "noDisplay"; } // Getting book total nb of pages $nb_of_pages = $this->userBook->getBook()->getNb_of_pages(); if ($this->userBook->getNb_of_pages()) { $nb_of_pages = $this->userBook->getNb_of_pages(); } // Gettign nb of pages read $nb_of_pages_read = $this->userBook->getNb_of_pages_read(); $tpl->set("isBlowOfHeartChecked", $this->userBook->getIsBlowOfHeart() ? "checked" : ""); if ($this->addMode) { $tpl->set("borrow", sprintf("<a href=\"%s\">%s</a>", "", __("Emprunter ce livre", "s1b"))); } else { $tpl->set("borrow", __("", "")); } $borrowerName = ""; $lenderName = ""; $oneActiveLending = false; $oneActiveBorrowing = false; $lending = $this->userBook->getActiveLending(); if ($lending) { $oneActiveLending = true; $borrowerName = $lending->getBorrower_userbook()->getUser()->getFirstName() . " " . $lending->getBorrower_userbook()->getUser()->getLastName(); } $borrowing = $this->userBook->getActiveBorrowing(); if ($borrowing) { $oneActiveBorrowing = true; if ($borrowing->getUserBook()) { $lenderName = $borrowing->getUserBook()->getUser()->getFirstName() . " " . $borrowing->getUserBook()->getUser()->getLastName(); } elseif ($borrowing->getGuest()) { $lenderName = sprintf(__("%s (invité)", "s1b"), $borrowing->getGuest()->getName()); } } $showLending = true; if ($this->addMode || !$this->userBook->getIsOwned() && !$oneActiveBorrowing) { $showLending = false; } $tpl->set("editLendingText", __("Prêtez ce livre", "s1b")); if (!$oneActiveBorrowing && !$oneActiveLending) { $tpl->set("lendingLabel", ""); } else { if ($oneActiveLending) { $tpl->set("lendingLabel", sprintf(__("Vous prêtez actuellement ce livre à %s", "s1b"), $borrowerName)); $tpl->set("editLendingText", __("Détail", "s1b")); } else { if ($oneActiveBorrowing) { $tpl->set("lendingLabel", sprintf(__("Vous empruntez actuellement ce livre à %s.", "s1b"), $lenderName)); $tpl->set("editLendingText", __("Détail", "s1b")); } else { $tpl->set("lendingLabel", ""); } } } $tpl->set("isOwned", $this->userBook->getIsOwned() ? "checked" : ""); $tpl->set("isWished", $this->userBook->getIsWished() ? "checked" : ""); $tpl->set("editLendingLink", \Sb\Helpers\HTTPHelper::Link(\Sb\Entity\Urls::LENDING_EDIT, array("ubid" => $this->userBook->getId()))); $tpl->set("readingDate", $this->userBook->getReadingDate() ? $this->userBook->getReadingDate()->format(__("d/m/Y", "s1b")) : ""); $tpl->set("hyperlink", $this->userBook->getHyperlink()); $script = ""; if ($readState) { $script = sprintf("<script>var share1bookAddABookJs = {readstate : \"%s\"}</script>", $readState->getId()); } // Get all the tags $labelCol = $this->getTagLabelCol(); $tags = \Sb\Db\Service\TagSvc::getInstance()->getAllTags($labelCol); if (!$this->addMode) { // Get the tags assigned to the userbook $this->userBookTags = $this->userBook->getTags(); $tagsExt = array_map(array($this, "isChecked"), $tags); } $tpl->setVariables(array("addMode" => $this->addMode, "showLending" => $showLending, "tags" => $tags, "tagsExt" => $tagsExt, "nb_of_pages" => $nb_of_pages, "nb_of_pages_read" => $nb_of_pages_read, "displayNbPagesRead" => $displayNbPagesRead)); return $tpl->output(); }
private function setForm($imageUploadPath, $new) { $this->setAction('/member/chronicle/post')->setMethod('post'); $this->setAttrib('enctype', 'multipart/form-data'); // Title element $titleElement = new \Zend_Form_Element_Text("title"); $titleElement->setLabel('Titre de la chronique - OBLIGATOIRE')->setRequired(true)->addFilter('StripTags')->addValidator(new \Zend_Validate_StringLength(3, 500))->addErrorMessage(__("La longueur du titre doit être comprise entre 3 et 500 caractères", "s1b"))->setDescription(__("Titre de la chronique sans caractères HTML, longueur comprise entre 3 et 500 caractères.", "s1b")); $titleElement->class = "input-text"; // Keyword element $keywordsElement = new \Zend_Form_Element_Text("keywords"); $keywordsElement->setLabel("Mots clés - OBLIGATOIRE")->setRequired(true)->addFilter("StripTags")->addValidator(new \Zend_Validate_StringLength(3, 250))->addErrorMessage(__("La longueur des mots clés doit être comprise entre 3 et 250 caractères", "s1b"))->setDescription(__("Mots clés de la chronique séparés par une virgule, longueur comprise entre 3 et 250 caractères.", "s1b")); $keywordsElement->class = "input-text"; // Text element $textElement = new \Zend_Form_Element_Textarea('text'); $textElement->setLabel('Chronique - OBLIGATOIRE')->setRequired(true)->addFilter('StripTags')->setAttribs(array("cols" => 50, "rows" => 6))->addValidator(new \Zend_Validate_StringLength(20, 5000))->addErrorMessage(__("La longueur du texte doit être comprise entre 20 et 5000 caractères", "s1b"))->setDescription(__("Texte de la chronique sans caractères HTML, longueur comprise entre 20 et 5000 caractères.", "s1b")); // Type element $typeElement = new \Zend_Form_Element_Select("type"); $typeOptions = array("" => __("Aucun", "s1b")); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::BOOK_CHRONICLE); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::DISCOVERY); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::FREE); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::GAME); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::JUST_FOR_FUN); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::NEWS); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::NEWSLETTER); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::TOPS); $typeOptions = $this->pushTypeOption($typeOptions, ChronicleType::WEDNESDAY_COMIC); $typeElement->addMultiOptions($typeOptions)->setRequired(true)->setLabel(__("Sélectionner la catégorie - OBLIGATOIRE", "s1b"))->addErrorMessage(__("La catégorie doit être renseignée.", "s1b")); // Link type element $linkTypeElement = new \Zend_Form_Element_Select("link_type"); $linkTypeOptions = array("" => __("Aucun", "s1b")); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::COMIC_BOARD); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::IMAGE); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::OTHER); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::PODCAST); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::PRESS); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::URL); $linkTypeOptions = $this->pushLinkTypeOption($linkTypeOptions, ChronicleLinkType::VIDEO); $linkTypeElement->addMultiOptions($linkTypeOptions)->setLabel(__("Sélectionner le type de lien", "s1b")); // Link element $linkElement = new \Zend_Form_Element_Text("link"); $linkElement->setLabel('Lien')->addValidator("stringLength", false, array("min" => 7, "max" => 255, "messages" => array(\Zend_Validate_StringLength::INVALID => __("La longeur doit être comprise entre 7 et 255 caractères.", "s1b"), \Zend_Validate_StringLength::TOO_LONG => __("La longeur doit être inférieure à 255 caractères.", "s1b"), \Zend_Validate_StringLength::TOO_SHORT => __("La longeur doit être supérieure à 6 caractères.", "s1b"))))->addValidator("regEx", false, array("pattern" => "{(^http://)|(^https://){1}}", "messages" => array(\Zend_Validate_Regex::NOT_MATCH => __("Le lien de la chronique doit commencer par http:// ou bien https://", "s1b")))); $linkElement->class = "input-text"; // Book Id element $bookIdElement = new \Zend_Form_Element_Text("book_id"); $bookIdElement->setLabel(__("Attacher un livre", "s1b"))->addValidator(new BookExists())->addValidator("int", false, array("messages" => array(\Zend_Validate_Int::NOT_INT => __("L'identifiant du livre doit être un chiffre", "s1b"))))->setDescription(__("Renseigner un identifiant de livre. Il s'agit du chiffre visible en toute fin de l'url de la page de détail d'un livre après le caractère \"-\"", "s1b")); $bookIdElement->class = "input-text"; // Image Element $imageElement = new \Zend_Form_Element_File("image"); $imageElement->setLabel(__("Attacher une image", "s1b"))->setDestination($imageUploadPath)->addValidator('Count', false, 1)->addValidator('Size', false, array("max" => 102400))->addValidator('Extension', false, 'jpg,png,gif')->addValidator("NotExists", false, array("messages" => array(\Zend_Validate_File_NotExists::DOES_EXIST => __("L'image chargée est déjà présente. Merci de sélectionner une autre image ou bien de renommer votre image.", "s1b"))))->setMaxFileSize(102400)->setDescription(__("Maximum 100 Ko, extensions .jpg, .png ou .gif", "s1b")); // Tag element $tagElement = new \Zend_Form_Element_Select("tag_id"); $tags = TagSvc::getInstance()->getAllTags("label"); $tagOptions = $this->getTagOptions($tags); $tagElement->setLabel(__("Tag - OBLIGATOIRE", "s1b"))->addMultiOptions($tagOptions)->setRequired(true)->addErrorMessage(__("Le tag doit être renseignée.", "s1b")); // userId element $userIdElement = new \Zend_Form_Element_Hidden("user_id"); $this->removeAllDecorators($userIdElement); // Group id element $groupIdElement = new \Zend_Form_Element_Hidden("group_id"); $this->removeAllDecorators($groupIdElement); // Id element $idElement = new \Zend_Form_Element_Hidden("id"); $this->removeAllDecorators($idElement); // Submit button $submitButtonElement = new \Zend_Form_Element_Submit("submit"); $submitButtonElement->setOptions(array('label' => $new ? __("Créer", "s1b") : __("Mettre à jour", "s1b"))); $submitButtonElement->class = "button bt-blue-xl"; // Add all elements to form $this->addElements(array($typeElement, $titleElement, $keywordsElement, $textElement, $linkTypeElement, $linkElement, $bookIdElement, $tagElement, $imageElement, $userIdElement, $groupIdElement, $idElement, $submitButtonElement)); }
/** * Add common item to view model for list actions * @param String $key the page key (last chronicles, bloggers, bookstores) * @param Array of ChronicleModelView $chronicles the array of ChronicleViewModel to display * @param int $pageNumber the page number * @param String $navigationParamName the page navigation param name */ private function addCommonListItemsToModelView($key, $chronicles, $pageNumber, $tagId, $searchTerm, $initUrl) { switch ($key) { case self::PAGE_KEY_ANY_GROUPS: $title = __("Dernières chroniques", "s1b"); break; case self::PAGE_KEY_BLOGGERS: $title = __("En direct des blogs", "s1b"); break; case self::PAGE_KEY_BOOKSTORES: $title = __("Le mot des libraires", "s1b"); break; } // Add title list to model view $this->view->title = $title; // Get tags and add it to model view $tags = TagSvc::getInstance()->getTagsForChronicles(); $this->view->tags = $tags; // Get search content form and add it to model view $contentSearch = new ContentSearch("/default/chronicle/search", $tags, $tagId, __("Rechercher une chronique", "s1b"), $key, $searchTerm, $initUrl); $this->view->contentSearch = $contentSearch->get(); if (!$pageNumber) { $pageNumber = 1; } $chroniclesPaginated = new PaginatedList($chronicles, 5, $this->navigationParamName, $pageNumber); $chroniclesPage = $chroniclesPaginated->getItems(); $chroniclesAdapter = new ChronicleListAdapter(); $chroniclesAdapter->setChronicles($chroniclesPage); // Get as a chronicle view model list with 2 similar chronicles $chronicleDetailViewModelList = $chroniclesAdapter->getAsChronicleViewModelList(2); // Add chronicleDetailViewModel list to model view $this->view->chronicleDetailViewModelList = $chronicleDetailViewModelList; // Add navigation bar to view model $this->view->navigationBar = $chroniclesPaginated->getNavigationBar(); // Add more seen chronicles to model view $nbMoreSeenChronicles = 5; $orderArray = array("nb_views", "DESC"); switch ($key) { case self::PAGE_KEY_ANY_GROUPS: $moreSeenChronicles = ChronicleSvc::getInstance()->getLastChronicles($nbMoreSeenChronicles, null, GroupTypes::BLOGGER . "," . GroupTypes::BOOK_STORE, true, null, $orderArray); break; case self::PAGE_KEY_BLOGGERS: $moreSeenChronicles = ChronicleSvc::getInstance()->getLastChronicles($nbMoreSeenChronicles, GroupTypes::BLOGGER, null, true, null, $orderArray); break; case self::PAGE_KEY_BOOKSTORES: $moreSeenChronicles = ChronicleSvc::getInstance()->getLastChronicles($nbMoreSeenChronicles, GroupTypes::BOOK_STORE, null, true, null, $orderArray); break; } if ($moreSeenChronicles) { $chroniclesAdapter->setChronicles($moreSeenChronicles); $moreSeenChroniclesView = new ChroniclesBlock($chroniclesAdapter->getAsChronicleViewModelLightList(), __("<strong>Chroniques</strong> les plus en vues", "s1b")); $this->view->moreSeenChronicles = $moreSeenChroniclesView->get(); } // Get books with press reviews $this->view->placeholder('footer')->append("<script src=\"" . BASE_URL . 'Resources/js/waterwheel-carousel/jquery.waterwheelCarousel.min.js' . "\"></script>\n"); $this->view->placeholder('footer')->append("<script>\$(function () {initCoverFlip('booksWithPressReviews', 30)});</script>\n"); $books = BookSvc::getInstance()->getListWithPressReviews(15); $booksCoverFlip = new BookCoverFlip($books, __("Les livres dont parlent <strong>les médias</strong>", "s1b"), "booksWithPressReviews", ""); $this->view->booksCoverFlip = $booksCoverFlip->get(); // Add SEO (title, meta description and keywords) $routeName = Zend_Controller_Front::getInstance()->getRouter()->getCurrentRouteName(); $headerInformation = HeaderInformationSvc::getInstance()->getByRouteName($routeName); $this->view->tagTitle = $headerInformation->getTitle(); $this->view->metaDescription = $headerInformation->getDescription(); $this->view->metaKeywords = $headerInformation->getKeywords(); }
private function bookHasSelectedTag(\Sb\Db\Model\Book $book) { $bookTags = TagSvc::getInstance()->getTagsForBooks(array($book)); foreach ($bookTags as $tag) { if ($tag->getId() == $this->selectedTagId) { return true; } } return false; }