Esempio n. 1
0
 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();
 }
Esempio n. 2
0
 public function get()
 {
     $lineIdx = 0;
     $userBooks = $this->shownResults;
     $booksTemplates = array();
     if ($userBooks) {
         $i = 0;
         foreach ($userBooks as $userBook) {
             $i++;
             $addSep = true;
             if ($i == 1) {
                 $addSep = false;
             }
             //$book = new \Sb\Db\Model\Book;
             $book = $userBook->getBook();
             // Get row template
             $rowTpl = new \Sb\Templates\Template("bookList/bookTableRow");
             $pictos = \Sb\Helpers\UserBookHelper::getStatusPictos($userBook, $this->friendLibrary);
             $rowTpl->set("pictos", $pictos);
             $cssClass = $lineIdx % 2 ? "lineA" : "lineB";
             $rowTpl->set("cssClass", $cssClass);
             $img = "";
             if ($book->getSmallImageUrl()) {
                 $img = sprintf("<img src = '%s' class = 'image-thumb-small'/>", $book->getSmallImageUrl());
             } else {
                 $img = sprintf("<img src = '%s' border = '0' class = 'image-thumb-small'/>", $this->defImg);
             }
             $rowTpl->set("img", $img);
             $rowTpl->set("title", $book->getTitle());
             if ($book->getPublisher()) {
                 $rowTpl->set("publicationInfo", $book->getPublicationInfo());
             } else {
                 $rowTpl->set("publicationInfo", "");
             }
             $rowTpl->set("author", $book->getOrderableContributors());
             $status = "";
             if ($userBook->getReadingState()) {
                 $status = $userBook->getReadingState()->getLabel();
             }
             $readingStateSvc = \Sb\Db\Service\ReadingStateSvc::getInstance();
             $readState = $readingStateSvc->getReadSate();
             if ($userBook->getReadingState() && $userBook->getReadingState()->getId() == $readState->getId()) {
                 if ($userBook->getReadingDate()) {
                     $status = sprintf(__("%s le %s", "s1b"), $status, $userBook->getReadingDate()->format(__("d/m/Y", "s1b")));
                 }
             }
             $rowTpl->set("status", $status);
             $rating = $userBook->getRating();
             if ($rating || $rating == 0) {
                 $ratingCssClass = "rating-" . $rating;
                 $rowTpl->set("ratingCssClass", "stars " . $ratingCssClass);
             } else {
                 $rowTpl->set("ratingCssClass", "");
             }
             if ($userBook->getIsBlowOfHeart()) {
                 $rowTpl->set("bohCssClass", "boh");
             } else {
                 $rowTpl->set("bohCssClass", "");
             }
             $editLink = HTTPHelper::Link(Urls::USER_BOOK_EDIT, array("ubid" => $userBook->getId()));
             $deleteLink = HTTPHelper::Link(Urls::USER_BOOK_DELETE, array("ubid" => $userBook->getId()));
             $viewLink = HTTPHelper::Link($book->getLink());
             // Showing "Borrow this book" link only if:
             // - friend ownes the book
             // - book is not lent
             $borrowLink = null;
             if ($this->friendLibrary && $userBook->getIsOwned() && !$userBook->getActiveLending()) {
                 $borrowLink = \Sb\Helpers\HTTPHelper::Link(Urls::USER_BOOK_BORROW, array("ubid" => $userBook->getId()));
             }
             $rowTpl->setVariables(array("addSep" => $addSep, "friendLibrary" => $this->friendLibrary, "editLink" => $editLink, "deleteLink" => $deleteLink, "viewLink" => $viewLink, "borrowLink" => $borrowLink, "bookId" => $book->getId()));
             $booksTemplates[] = $rowTpl;
             $lineIdx++;
             unset($addSep);
             unset($book);
             unset($rowTpl);
             unset($pictos);
             unset($cssClass);
             unset($img);
             unset($status);
             unset($rating);
             unset($ratingCssClass);
             unset($editLink);
             unset($deleteLink);
             unset($viewLink);
             unset($borrowLink);
             unset($userBook);
         }
     }
     $bookListTpl = new \Sb\Templates\Template("bookList/bookTable");
     if ($booksTemplates) {
         // Get row header template
         $headerTpl = new \Sb\Templates\Template("bookList/bookTableHeader");
         // Assignation des classe pour afficher le petit picto indiquant le sens de tri
         if ($this->listOptions) {
             if ($this->listOptions->getSorting()) {
                 if ($this->listOptions->getSorting()->getField() == \Sb\Helpers\BooksHelper::SORTING_FIELD_AUTHOR) {
                     $headerTpl->set("titlesortingdirection", "");
                     $headerTpl->set("ratingsortingdirection", "");
                     $headerTpl->set("authorsortingdirection", $this->listOptions->getSorting()->getDirection());
                     $headerTpl->set("statesortingdirection", "");
                 }
                 if ($this->listOptions->getSorting()->getField() == \Sb\Helpers\BooksHelper::SORTING_FIELD_RATING) {
                     $headerTpl->set("titlesortingdirection", "");
                     $headerTpl->set("ratingsortingdirection", $this->listOptions->getSorting()->getDirection());
                     $headerTpl->set("authorsortingdirection", "");
                     $headerTpl->set("statesortingdirection", "");
                 }
                 if ($this->listOptions->getSorting()->getField() == \Sb\Helpers\BooksHelper::SORTING_FIELD_TITLE) {
                     $headerTpl->set("titlesortingdirection", $this->listOptions->getSorting()->getDirection());
                     $headerTpl->set("ratingsortingdirection", "");
                     $headerTpl->set("authorsortingdirection", "");
                     $headerTpl->set("statesortingdirection", "");
                 }
                 if ($this->listOptions->getSorting()->getField() == \Sb\Helpers\BooksHelper::SORTING_FIELD_STATE) {
                     $headerTpl->set("titlesortingdirection", "");
                     $headerTpl->set("ratingsortingdirection", "");
                     $headerTpl->set("authorsortingdirection", "");
                     $headerTpl->set("statesortingdirection", $this->listOptions->getSorting()->getDirection());
                 }
             }
         }
         $headerTpl->setVariables(array("friendLibrary" => $this->friendLibrary));
         $bookListTpl->set("tableHeader", $headerTpl->output());
         $booksToShow = \Sb\Templates\Template::merge($booksTemplates);
         $bookListTpl->set("booksToShow", $booksToShow);
         $links = $this->pagerLinks;
         $bookListTpl->set("links", $links['all']);
         $bookListTpl->set("first", $this->firstItemIdx);
         $bookListTpl->set("last", $this->lastItemIdx);
         $bookListTpl->set("nbItemsTot", $this->nbItemsTot);
         $listSearchDefValue = __("Un titre, un auteur, ISBN dans ma bibliothèque", "s1b");
         $bookListTpl->set("listSearchDefValue", $listSearchDefValue);
         if ($this->searchValue) {
             $bookListTpl->set("listSearchValue", $this->searchValue);
         } else {
             $bookListTpl->set("listSearchValue", $listSearchDefValue);
         }
         $key = \Sb\Helpers\ArrayHelper::getSafeFromArray($_GET, "key", null);
         $bookListTpl->set("key", $key);
         $selectedAuthorLetter = null;
         $selectedTitleLetter = null;
         $filtertype = \Sb\Helpers\ArrayHelper::getSafeFromArray($_GET, "filtertype", null);
         if ($filtertype == \Sb\Lists\FilteringType::AUTHOR_FIRST_LETTER) {
             $selectedAuthorLetter = \Sb\Helpers\ArrayHelper::getSafeFromArray($_GET, "filter", null);
         } elseif ($filtertype == \Sb\Lists\FilteringType::TITLE_FIRST_LETTER) {
             $selectedTitleLetter = \Sb\Helpers\ArrayHelper::getSafeFromArray($_GET, "filter", null);
         }
         $bookListTpl->setVariables(array("authorsFirstLetters" => $this->authorsFirstLetters, "titlesFirstLetters" => $this->titlesFirstLetters, "selectedTitleLetter" => $selectedTitleLetter, "selectedAuthorLetter" => $selectedAuthorLetter, "emptyList" => false));
     } else {
         $bookListTpl->setVariables(array("emptyList" => true));
     }
     return $bookListTpl->output();
 }