public function setAsOfferedAction() { $dest = HTTPHelper::getReferer() ? HTTPHelper::getReferer() : HTTPHelper::Link(); $id = $this->_getParam('ubid', -1); // Checking if passed id is > 0 if ($id > 0) { $userBook = UserBookDao::getInstance()->get($id); // Checking if id passed matches a user book if ($userBook) { // Checking if user book not set as offered already if (!$userBook->getActiveGiftRelated()) { $userBookGift = new UserBookGift(); $userBookGift->setUserbook($userBook); $globalContext = new \Sb\Context\Model\Context(); $connectedUser = $globalContext->getConnectedUser(); $userBookGift->setOfferer($connectedUser); $userBookGift->setIs_active(true); if (UserBookGiftDao::getInstance()->add($userBookGift)) { Flash::addItem(__("Le livre a correctement été marqué 'déjà acheté'.", "s1b")); $this->_redirect($dest); exit; } } } } Flash::addItem(__("une erreur s'est produite et le livre n'a pas pu être marqué 'déjà acheté'.", "s1b")); $this->_redirect($dest); exit; }
public function recommandAction() { try { $globalContext = new \Sb\Context\Model\Context(); // getting user /* @var \Sb\Db\Model\User $user */ $user = $globalContext->getConnectedUser(); $potentialRecipients = $user->getFriendsForEmailing(); if (count($potentialRecipients) <= 0) { Flash::addItem(__("Pas de destinataire possible. Vous devez ajouter des amis pour pouvoir envoyer des recommandations.", "s1b")); HTTPHelper::redirectToReferer(); } // Getting book $bookId = $this->getParam("id"); $book = $this->getBook($bookId); $this->setFriendsSelectionInModel(); // Add to model $this->view->user = $user; $this->view->book = $book; $this->view->userBook = UserBookDao::getInstance()->getByBookIdAndUserId($globalContext->getConnectedUser()->getId(), $bookId); $this->view->bookLink = HTTPHelper::Link($book->getLink()); $this->view->message = $this->getParam("message"); } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString())); $this->forward("error", "error", "default"); } }
public function get() { $baseTpl = "components/userWishedBooksWidget"; $tpl = new Template($baseTpl); $params = array(); $wishedBooks = UserBookDao::getInstance()->getListWishedBooks($this->user->getId(), -1, false); $params["wishedBooks"] = $wishedBooks; $params["isCurrentConnectedUser"] = $this->isCurrentConnectedUser; $params["user"] = $this->user; $params["defImage"] = $this->defImg; $tpl->setVariables($params); return $tpl->output(); }
public function addUserbookCommentAction() { $this->view->setEncoding('utf-8'); $globalContext = new \Sb\Context\Model\Context(); $this->view->errorMessage = __("Une erreur s'est produite et votre commentaire n'a pas été posté correctement.", "s1b"); if ($globalContext->getConnectedUser()) { // Getting params $bookId = $this->_getParam('bookId'); $reviewPageId = $this->_getParam('reviewPageId'); $userBookId = $this->_getParam('ubid'); $commentValue = $this->_getParam('comment'); // Add userbook comment $userbook = UserBookDao::getInstance()->get($userBookId); $comment = new UserbookComment(); $comment->setValue($commentValue); $comment->setCreation_date(new \DateTime()); $comment->setOwner($globalContext->getConnectedUser()); $comment->setUserbook($userbook); // If the adding happens correctly, we forward to the get-reviews-page action if (UserbookCommentDao::getInstance()->add($comment)) { $reviewUser = $userbook->getUser(); // Sends a mail only if connected user is not the userbook owner if ($reviewUser->getId() != $globalContext->getConnectedUser()->getId() && $reviewUser->getSetting()->getEmailMe() == \Sb\Helpers\UserSettingHelper::EMAIL_ME_YES) { // Send a email to the userbook owner $subject = sprintf(__("%s - Un nouveau commentaire sur un de vos livres.", "s1b"), \Sb\Entity\Constants::SITENAME); $body = \Sb\Helpers\MailHelper::newCommentPosted($commentValue, $userbook->getBook()); \Sb\Service\MailSvc::getInstance()->send($reviewUser->getEmail(), $subject, $body); } // Forward to review page action $this->forward("get-reviews-page", "book", "default", array("key" => $bookId, "param" => $reviewPageId, "format" => "html")); } } else { $this->view->errorMessage = __("Vous devez être connecté pour poster un commentaire.", "s1b"); } // Otherwise, we let the message 'KO' get rendered by the view // This message will be intercepted in javascript code to display a coherent flash message }
/** * Get list of lastly read userbook for a book * @param type $bookId * @param type $nbBooks * @return type */ public function getLastlyReadUserbookByBookId($bookId, $nbBooks = null, $useCache = true) { try { $result = null; $maxResult = 25; // Number of userbooks in the list cached. Items are alays taken from that list. // This value will have to be changed if a bigger list needs to be return. if ($useCache) { $dataKey = self::LASTY_READ . "_bid_" . $bookId . "_m_" . $maxResult; $result = $this->getData($dataKey); } if (!isset($result) || $result === false) { $result = UserBookDao::getInstance()->getLastlyReadUserbookByBookId($bookId, $maxResult); // Loop all the userbooks and set the user's userbooks as they are not fetched automatically foreach ($result as $userbook) { $user = $userbook->getUser(); $userbooks = new \Doctrine\Common\Collections\ArrayCollection(UserBookDao::getInstance()->getListAllBooks($user->getId(), true)); $user->setUserBooks($userbooks); $userbook->setUser($user); } if ($useCache) { $this->setData($dataKey, $result); } } if ($nbBooks) { return array_slice($result, 0, $nbBooks); } else { return $result; } } catch (\Exception $exc) { $this->logException(get_class(), __FUNCTION__, $exc); } }
public function profileAction() { $globalContext = new \Sb\Context\Model\Context(); // Users profile are only accessible for connected users AuthentificationSvc::getInstance()->checkUserIsConnected(); $noUser = true; $friendId = $this->_getParam("uid"); if ($friendId) { $friend = UserDao::getInstance()->get($friendId); $this->view->friend = $friend; if ($friend) { $noUser = false; if ($friend->getId() == $globalContext->getConnectedUser()->getId()) { Flash::addItem(__("Il s'agit de votre profil!", "s1b")); HTTPHelper::redirectToReferer(); } else { $requestingUser = $globalContext->getConnectedUser(); if (SecurityHelper::IsUserAccessible($friend, $requestingUser)) { $this->view->friendSetting = $friend->getSetting(); $this->view->isFriend = UserSvc::getInstance()->areUsersFriends($globalContext->getConnectedUser(), $friend); // getting currently reading or lastly read books $currentlyReading = UserBookDao::getInstance()->getReadingNow($friend->getId()); $lastlyReads = UserBookDao::getInstance()->getListLastlyRead($friend->getId()); if ($currentlyReading && $lastlyReads) { $this->view->currentlyReadingOrLastlyReadBooks = array_merge(array($currentlyReading), $lastlyReads); } elseif ($lastlyReads) { $this->view->currentlyReadingOrLastlyReadBooks = $lastlyReads; } elseif ($currentlyReading) { $this->view->currentlyReadingOrLastlyReadBooks = array($currentlyReading); } // Getting friend currently reading user books $this->view->allCurrentlyReadingUserBooks = UserBookDao::getInstance()->getCurrentlyReadingsNow($friend->getId()); if (count($this->view->allCurrentlyReadingUserBooks) > 1) { $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n"); $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-currentreadings', 298, 190)});</script>\n"); } // Getting friend last boh books $bohUserBooks = UserBookDao::getInstance()->getListUserBOH($friend->getId()); $this->view->bohBooks = array_map(array($this, "getBook"), $bohUserBooks); // Getting books friend could like $this->view->booksHeCouldLikes = BookSvc::getInstance()->getBooksUserCouldLike($friend->getId()); if ($this->view->booksHeCouldLikes && count($this->view->booksHeCouldLikes) > 0) { $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/waterwheel-carousel/jquery.waterwheelCarousel.min.js' . "\"></script>\n"); $this->view->placeholder('footer')->append("<script>\$(function() {initCoverFlip('bookUserCouldLike', 90)});</script>\n"); } // Getting friend's friends last reviews $this->view->friendLastReviews = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), EventTypes::USERBOOK_REVIEW_CHANGE); // Getting friend last friends added events $this->view->friendLastFriendsAddedEvents = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), EventTypes::USER_ADD_FRIEND); if (count($this->view->friendLastFriendsAddedEvents) > 1) { $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n"); $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-friendlastfriends', 298, 85)});</script>\n"); } // Getting friend last events $this->view->friendLastEvents = UserEventSvc::getInstance()->getUserLastEventsOfType($friend->getId(), null, 15); $this->view->placeholder('footer')->append("<script>\n\n toInit.push(\"attachUserEventsExpandCollapse()\");\n\n function attachUserEventsExpandCollapse() {_attachExpandCollapseBehavior(\"js_userLastEvents\", \"userEvent\", \"Voir moins d'activités\", \"Voir plus d'activités\");}\n\n </script>\n"); } else { Flash::addItem(__("Vous ne pouvez pas accéder à ce profil.", "s1b")); HTTPHelper::redirectToReferer(); } } } } if ($noUser) { Flash::addItem(__("Cet utilisateur n'existe pas.", "s1b")); HTTPHelper::redirectToReferer(); } }
public function get() { $globalContext = new \Sb\Context\Model\Context(); $tplEvent = new \Sb\Templates\Template("userEvents/userEvent"); $friend = $this->userEvent->getUser(); $friendImg = UserHelper::getSmallImageTag($friend); if ($friendImg == "") { $friendImg = UserHelper::getSmallImageTag($friend); } $friendName = $friend->getUserName(); $friendProfileLink = HTTPHelper::Link(Urls::USER_PROFILE, array("uid" => $friend->getId())); $userBookRelated = false; $friendRelated = false; // used for cases of new friend event $additionalContent = ""; $friendId = null; $friendFriendImg = null; $friendFriendProfileLink = null; switch ($this->userEvent->getType_id()) { case EventTypes::USERBOOK_ADD: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a ajouté un livre.", $friendProfileLink, $friendName); $userBookRelated = true; break; case EventTypes::USERBOOK_RATING_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $newRating = $this->userEvent->getNew_value(); $resume = sprintf("<div class=\"ue-rating-label\"><a href=\"%s\" class=\"link\">%s</a> a noté.</div> <div class=\"rating rating-" . $newRating . "\"></div>", $friendProfileLink, $friendName); $userBookRelated = true; break; case EventTypes::USERBOOK_BLOWOFHEART_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $isBoh = $this->userEvent->getNew_value(); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a supprimé son coup de coeur.", $friendProfileLink, $friendName); if ($isBoh) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a marqué comme coup de coeur.", $friendProfileLink, $friendName); } $userBookRelated = true; break; case EventTypes::USERBOOK_REVIEW_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $oldReview = $this->userEvent->getOld_value(); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a modifié son commentaire.", $friendProfileLink, $friendName); if ($oldReview == "") { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a ajouté un commentaire.", $friendProfileLink, $friendName); } $additionalContent = StringHelper::tronque(strip_tags($this->userEvent->getNew_value()), 120); $userBookRelated = true; break; case EventTypes::USERBOOK_HYPERLINK_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $oldHyperLink = $this->userEvent->getOld_value(); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a modifié son lien hypertexte.", $friendProfileLink, $friendName); if ($oldHyperLink == "") { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a ajouté un lien hypertexte.", $friendProfileLink, $friendName); } $hyperLink = "http://" . $this->userEvent->getNew_value(); $truncatedHyperLink = \Sb\Helpers\StringHelper::tronque($hyperLink, 100); $additionalContent = sprintf(__("<a href=\"%s\" target=\"_blank\" class=\"hyperlink link\" >%s</a>", "s1b"), $hyperLink, $truncatedHyperLink); $userBookRelated = true; break; case EventTypes::USERBOOK_READINGSTATE_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $newReadingSateId = $this->userEvent->getNew_value(); switch ($newReadingSateId) { case ReadingStates::NOTREAD: $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a marqué non lu.", $friendProfileLink, $friendName); break; case ReadingStates::READING: $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> lit actuellement.", $friendProfileLink, $friendName); break; case ReadingStates::READ: $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a lu.", $friendProfileLink, $friendName); break; } $userBookRelated = true; break; case EventTypes::USERBOOK_WISHEDSTATE_CHANGE: $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->get($this->userEvent->getItem_id()); $newWishedSateValue = $this->userEvent->getNew_value(); $oldWishedSateValue = $this->userEvent->getOld_value(); if ($newWishedSateValue) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a marqué comme souhaité.", $friendProfileLink, $friendName); } elseif ($oldWishedSateValue) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> ne souhaite plus.", $friendProfileLink, $friendName); } $userBookRelated = true; break; case EventTypes::USER_ADD_FRIEND: $friendNewFriendProfileLink = null; $newFriendId = $this->userEvent->getNew_value(); if ($this->getContext()->getConnectedUser() && $newFriendId == $this->getContext()->getConnectedUser()->getId()) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> est ami avec moi.", $friendProfileLink, $friendName); $friendFriendImg = UserHelper::getXSmallImageTag($this->getContext()->getConnectedUser()); } else { $friendNewFriend = UserDao::getInstance()->get($newFriendId); $friendNewFriendProfileLink = HTTPHelper::Link(Urls::USER_PROFILE, array("uid" => $friendNewFriend->getId())); $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> est ami avec <a class=\"link\" href=\"%s\">%s</a>.", $friendProfileLink, $friendName, $friendNewFriendProfileLink, $friendNewFriend->getUserName()); $friendFriendImg = UserHelper::getXSmallImageTag($friendNewFriend); } $friendId = $newFriendId; $friendFriendProfileLink = $friendNewFriendProfileLink; $friendRelated = true; break; case EventTypes::USER_BORROW_USERBOOK: $lendingId = $this->userEvent->getNew_value(); $lending = LendingDao::getInstance()->get($lendingId); $userBookBorrowed = $lending->getUserBook(); $userBook = $userBookBorrowed; $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a emprunté le livre à %s.", $friendProfileLink, $friendName, $userBookBorrowed->getUser()->getUserName()); if ($this->getContext()->getConnectedUser()) { if ($userBookBorrowed->getUser()->getId() == $this->getContext()->getConnectedUser()->getId()) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> m'a emprunté le livre.", $friendProfileLink, $friendName); } } $userBookRelated = true; break; case EventTypes::USER_LEND_USERBOOK: $lendingId = $this->userEvent->getNew_value(); $lending = LendingDao::getInstance()->get($lendingId); $userBookLended = $lending->getBorrower_UserBook(); $userBook = $userBookLended; $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> a prêté le livre à %s.", $friendProfileLink, $friendName, $userBookLended->getUser()->getUserName()); if ($this->getContext()->getConnectedUser()) { if ($userBookLended->getUser()->getId() == $this->getContext()->getConnectedUser()->getId()) { $resume = sprintf("<a href=\"%s\" class=\"link\">%s</a> m'a prêté le livre.", $friendProfileLink, $friendName); } } $userBookRelated = true; break; default: break; } $creationDate = $this->userEvent->getCreation_date()->format(__("d/m/Y à H:m", "s1b")); $bookImageUrl = null; $bookLink = null; $bookTitle = null; $bookAuthor = null; $bookId = null; $bookImgTag = null; if ($userBookRelated) { $bookImageUrl = $userBook->getBook()->getSmallImageUrl(); $bookImgTag = BookHelper::getSmallImageTag($userBook->getBook(), $this->getContext()->getDefaultImage()); $bookLink = HTTPHelper::Link($userBook->getBook()->getLink()); $bookTitle = $userBook->getBook()->getTitle(); $bookAuthor = $userBook->getBook()->getOrderableContributors(); $bookId = $userBook->getBook()->getId(); } $showAddButton = false; if ($globalContext->getConnectedUser()) { $showAddButton = true; } // Set variables $tplEvent->setVariables(array("friendImg" => $friendImg, "friendName" => $friendName, "resume" => $resume, "bookImageUrl" => $bookImageUrl, "bookImgTag" => $bookImgTag, "friendProfileLink" => $friendProfileLink, "friendId" => $friendId, "bookTitle" => $bookTitle, "bookId" => $bookId, "bookAuthor" => $bookAuthor, "creationDate" => $creationDate, "bookLink" => $bookLink, "additionalContent" => $additionalContent, "userBookRelated" => $userBookRelated, "userFriendRelated" => $friendRelated, "friendFriendImg" => $friendFriendImg, "friendFriendProfileLink" => $friendFriendProfileLink, "showOwner" => $this->showOwner, "showAddButton" => $showAddButton)); return $tplEvent->output(); }
public function get() { $tpl = new \Sb\Templates\Template("book"); $isInLibrary = false; $averageRating = $this->book->getAverageRating(); $ratingCss = null; if ($averageRating) { $ratingCss = "rating-" . floor($averageRating); } $nbRatings = $this->book->getNbRatedUserBooks(); $rating = null; $isBlowOfHeart = null; $readingStateLabel = null; $lendingText = null; $lendingLink = null; $editBookLink = null; $recommandLink = null; $owned = null; $requestBorrowLink = null; // testing if book is view while a user is connected if ($this->getContext()->getConnectedUser()) { $isConnected = true; // testing if the connected user has the book and if some additionnal informations can be shown $userBook = \Sb\Db\Dao\UserBookDao::getInstance()->getByBookIdAndUserId($this->getContext()->getConnectedUser()->getId(), $this->book->getId()); if ($userBook && !$userBook->getIs_deleted()) { $isInLibrary = true; $rating = $userBook->getRating(); $isBlowOfHeart = $userBook->getIsBlowOfHeart(); if ($userBook->getReadingState()) { $readingStateLabel = $userBook->getReadingState()->getLabel(); } if ($rating) { $ratingCss = "rating-" . $rating; } $lendingLink = ""; if ($userBook->getIsOwned()) { $lendingLink = HTTPHelper::Link(Urls::LENDING_EDIT, array("ubid" => $userBook->getId())); } $lendingText = __("Prêter à un ami", "s1b"); if ($userBook->getActiveLending()) { $lendingText = __("Prêt", "s1b"); } $editBookLink = HTTPHelper::Link(Urls::USER_BOOK_EDIT, array("ubid" => $userBook->getId())); $owned = $userBook->getIsOwned(); $requestBorrowLink = ""; $recommandLink = HTTPHelper::Link(Urls::USER_MAILBOX_RECOMMAND, array("id" => $this->book->getId())); } else { $requestBorrowLink = HTTPHelper::Link(\Sb\Entity\Urls::USER_BOOK_BORROW_FROM_FRIENDS, array("bid" => $this->book->getId())); } } else { $isConnected = false; } $image = \Sb\Helpers\BookHelper::getMediumImageTag($this->book, $this->defImg, true); $bookTitle = $this->book->getTitle(); $bookDescription = $this->book->getDescription(); $bookPublication = $this->book->getPublicationInfo(); $bookAuthors = $this->book->getOrderableContributors(); $titleEsc = ""; $authorEsc = ""; $isbn10 = ""; $isbn13 = ""; $asin = ""; $id = ""; $smallImg = ""; $img = ""; $largeImg = ""; $pubEsc = ""; $pubDtStr = ""; $amazonUrl = ""; $booksUsersAlsoLikedShelf = ""; $booksWithSameTagsShelf = ""; $descEsc = ""; if ($this->addHiddenFields) { $titleEsc = urlencode($this->book->getTitle()); // encodé $authorEsc = urlencode($this->book->getOrderableContributors()); // encodé $id = $this->book->getId(); $isbn10 = $this->book->getISBN10(); $isbn13 = $this->book->getISBN13(); $asin = $this->book->getASIN(); $descEsc = urlencode($this->book->getDescription()); // encodé $smallImg = $this->book->getSmallImageUrl(); $img = $this->book->getImageUrl(); $largeImg = $this->book->getLargeImageUrl(); if ($this->book->getPublisher()) { $pubEsc = urlencode($this->book->getPublisher()->getName()); } // encodé $pubDtStr = ""; if ($this->book->getPublishingDate()) { $pubDtStr = $this->book->getPublishingDate()->format("Y-m-d H:i:s"); } $amazonUrl = $this->book->getAmazonUrl(); } // book reviews $reviews = ""; $nbOfReviewsPerPage = 5; if ($this->reviewedUserBooks) { $paginatedList = new \Sb\Lists\PaginatedList($this->reviewedUserBooks, $nbOfReviewsPerPage); $reviewsView = new \Sb\View\BookReviews($paginatedList, $this->book->getId()); $reviews = $reviewsView->get(); } if ($this->addRecommendations) { // Books users also liked $booksUsersAlsoLikedShelf = ""; if ($this->booksAlsoLiked && count($this->booksAlsoLiked) > 0) { $booksUsersAlsoLikedShelfView = new BookShelf($this->booksAlsoLiked, __("<strong>Les membres</strong> qui ont lu ce livre <strong>ont aussi aimé</strong>", "s1b")); $booksUsersAlsoLikedShelf = $booksUsersAlsoLikedShelfView->get(); } // Books with same tags $booksWithSameTagsShelf = ""; if ($this->booksWithSameTags && count($this->booksWithSameTags) > 0) { $booksWithSameTagsShelfView = new BookShelf($this->booksWithSameTags, __("Les livres <strong>dans la même catégorie</strong>", "s1b")); $booksWithSameTagsShelf = $booksWithSameTagsShelfView->get(); } } $tpl->setVariables(array("isConnected" => $isConnected, "isInLibrary" => $isInLibrary, "rating" => $rating, "nbRatings" => $nbRatings, "averageRating" => $averageRating, "isBlowOfHeart" => $isBlowOfHeart, "readingStateLabel" => $readingStateLabel, "ratingCss" => $ratingCss, "lendingText" => $lendingText, "lendingLink" => $lendingLink, "editBookLink" => $editBookLink, "requestBorrowLink" => $requestBorrowLink, "recommandLink" => $recommandLink, "image" => $image, "bookTitle" => $bookTitle, "bookDescription" => $bookDescription, "bookPublication" => $bookPublication, "bookAuthors" => $bookAuthors, "owned" => $owned, "addReviews" => $this->addReviews, "addButtons" => $this->addButtons, "reviews" => $reviews, "addHiddenFields" => $this->addHiddenFields, "titleEsc" => $titleEsc, "authorEsc" => $authorEsc, "id" => $id, "isbn10" => $isbn10, "isbn13" => $isbn13, "asin" => $asin, "descEsc" => $descEsc, "smallImg" => $smallImg, "img" => $img, "largeImg" => $largeImg, "pubEsc" => $pubEsc, "pubDtStr" => $pubDtStr, "amazonUrl" => $amazonUrl, "isInForm" => $this->isInForm, "booksUsersAlsoLikedShelf" => $booksUsersAlsoLikedShelf, "booksWithSameTagsShelf" => $booksWithSameTagsShelf)); return $tpl->output(); }
/** * Get a full UserEvent object related to a book with all members initialised * This is necessary for storing the object in cache otherwise when getting the object from cahc (and detach from database) * these members won't be initialized * @param \Sb\Db\Model\UserEvent $event */ private function getFullBookRelatedUserEvent(UserEvent $event) { // If item_id is not null, we get the userbook item from db if ($event->getItem_id()) { $userbook = UserBookDao::getInstance()->get($event->getItem_id()); if ($userbook) { $book = $userbook->getBook(); $contributors = \Sb\Db\Dao\ContributorDao::getInstance()->getListForBook($book->getId()); $book->setContributors($contributors); $event->setBook($book); } return $event; } else { return $event; } }
public function submitAction() { try { $globalContext = new \Sb\Context\Model\Context(); if ($_REQUEST['LendingType'] == "NEW") { $userBookId = $_POST['ubid']; // getting userbook lent $userBook = UserBookDao::getInstance()->get($userBookId); $userBook->setLentOnce(true); // getting borrower userbook (new one) // checking if borrower alreday have the book $borrowerId = $_POST['BorrowerId']; $userBookBorrower = UserBookDao::getInstance()->getByBookIdAndUserId($borrowerId, $userBook->getBook()->getId()); // if not creating a new one if (!$userBookBorrower) { $userBookBorrower = new UserBook(); $userBookBorrower->setCreationDate(new \DateTime()); $userBookBorrower->setLastModificationDate(new \DateTime()); $userBookBorrower->setBook($userBook->getBook()); $borrower = UserDao::getInstance()->get($borrowerId); $userBookBorrower->setUser($borrower); } $userBookBorrower->setIs_deleted(false); // set is_deleted to false in case the borrower already had the book but deleted it in the past $userBookBorrower->setBorrowedOnce(true); // creating lending $lending = new Lending(); $lending->setUserbook($userBook); $lending->setBorrower_userbook($userBookBorrower); $lending->setStartDate(new \DateTime()); $lending->setCreationDate(new \DateTime()); $lending->setLastModificationDate(new \DateTime()); $lending->setState(LendingState::ACTIV); if (LendingDao::getInstance()->add($lending)) { Trace::addItem("Lending créé avec succès."); Flash::addItem(__("Les informations de prêt ont bien été mises à jour.", "s1b")); try { $userEvent = new UserEvent(); $userEvent->setNew_value($lending->getId()); $userEvent->setType_id(EventTypes::USER_LEND_USERBOOK); $userEvent->setUser($globalContext->getConnectedUser()); UserEventDao::getInstance()->add($userEvent); } catch (Exception $exc) { Trace::addItem("erreur lors de l'ajout de l'évènement suite au prêt : " . $exc->getMessages()); } } } else { // editing a lending -> ending it $lendingId = $_POST["LendingId"]; $lending = LendingDao::getInstance()->get($lendingId); if ($lending) { // Testing if the user editing the lending is either the lender or the borrower $canEditLending = false; if ($lending->getUserbook() && $lending->getUserbook()->getUser()->getId() == $globalContext->getConnectedUser()->getId()) { $canEditLending = true; } if ($lending->getBorrower_userbook() && $lending->getBorrower_userbook()->getUser()->getId() == $globalContext->getConnectedUser()->getId()) { $canEditLending = true; } if ($canEditLending) { $lending->setEndDate(new \DateTime()); // End date set to today $userIsLender = $lending->getUserbook() && $lending->getUserbook()->getUser()->getId() == $globalContext->getConnectedUser()->getId(); $userIsBorrower = $lending->getBorrower_userbook() && $lending->getBorrower_userbook()->getUser()->getId() == $globalContext->getConnectedUser()->getId(); $isBorrowedToGuest = $lending->getGuest(); if ($userIsLender) { $lending->setState(LendingState::IN_ACTIVE); // user is the lender, State set to IN_ACTIVE } elseif ($userIsBorrower) { if (!$isBorrowedToGuest) { $lending->setState(LendingState::WAITING_INACTIVATION); } else { $lending->setState(LendingState::IN_ACTIVE); } // user is the borrower but is borrowed to a guest, State set to IN_ACTIVE } $lending->setLastModificationDate(new \DateTime()); if (LendingDao::getInstance()->update($lending)) { // Send email to owner to remind him that he needs to validate the lending end if ($userIsBorrower && !$isBorrowedToGuest) { MailSvc::getInstance()->send($lending->getUserbook()->getUser()->getEmail(), __("Prêt en attente de retour de validation", "s1b"), $this->emailReturnValidationRequiredBody($lending->getUserbook()->getBook()->getTitle(), $lending->getBorrower_userbook()->getUser()->getUserName())); } Trace::addItem("Mise à jour (FIN) du lending correctement."); if ($userIsBorrower && !$isBorrowedToGuest) { Flash::addItem(__("Les informations de prêt ont bien été mises à jour mais le retour doit être validé par le prêteur.", "share1book")); } else { Flash::addItem(__("Les informations de prêt ont bien été mises à jour.", "s1b")); } } } } } HTTPHelper::redirectToLibrary(); } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString())); $this->forward("error", "error", "default"); } }
/** * Show member home page action * @global type $globalContextMe */ public function indexAction() { try { $globalContext = new \Sb\Context\Model\Context(); $globalConfig = new Sb\Config\Model\Config(); /* @var $connectedUser User */ $connectedUser = $globalContext->getConnectedUser(); // Getting friends boh $blowOfHeartFriendsBooks = BookDao::getInstance()->getListBOHFriends($connectedUser->getId()); $this->view->isShowingFriendsBOH = false; if (!$blowOfHeartFriendsBooks || count($blowOfHeartFriendsBooks) < 5) { // Setting class property with array of friend boh books ids to use it in "notInArray" function below $this->blowOfHeartFriendsBooksId = array_map(array(&$this, "getId"), $blowOfHeartFriendsBooks); // Getting all users boh $blowOfHeartBooks = BookSvc::getInstance()->getBOHForUserHomePage(); $blowOfHeartBooks = array_filter($blowOfHeartBooks, array(&$this, "notInArray")); // Merging 2 arrays if ($blowOfHeartFriendsBooks && $blowOfHeartBooks) { $blowOfHeartBooks = array_merge($blowOfHeartFriendsBooks, $blowOfHeartBooks); } $blowOfHeartBooks = array_slice($blowOfHeartBooks, 0, 5); } else { $this->view->isShowingFriendsBOH = true; $blowOfHeartBooks = $blowOfHeartFriendsBooks; } $this->view->blowOfHeartBooks = $blowOfHeartBooks; // Getting friends user events $this->view->userEvents = UserEventDao::getInstance()->getListUserFriendsUserEvents($connectedUser->getId()); // Getting top books $this->view->topsBooks = BookSvc::getInstance()->getTopsUserHomePage(); // Getting last review by friends $lastReviews = UserEventSvc::getInstance()->getFriendsLastEventsOfType($connectedUser->getId(), EventTypes::USERBOOK_REVIEW_CHANGE); $this->view->lastReviews = $lastReviews; $this->view->lastReviewsView = new LastReviews($lastReviews, __("<strong>Dernières critiques postées par vos amis</strong>", "s1b")); // Getting User Reading Widget $allCurrentlyReadingUserBooks = UserBookDao::getInstance()->getCurrentlyReadingsNow($connectedUser->getId()); $userReading = new UserReadingWidget($connectedUser, $allCurrentlyReadingUserBooks, true); // If more than one book as 'being read', we need to set the javascript carousel if (count($allCurrentlyReadingUserBooks) > 1) { $this->view->placeholder('footer')->append("<script src=\"" . $globalContext->getBaseUrl() . 'Resources/js/simple-carousel/simple.carousel.js' . "\"></script>\n"); $this->view->placeholder('footer')->append("<script>\$(function() {initCarousel('carousel-currentreadings', 270, 210)});</script>\n"); } $this->view->userReading = $userReading; // Getting user wished books widget $userWishedBooks = new UserWishedBooksWidget($connectedUser, true); $this->view->userWishedBooks = $userWishedBooks; // Getting wish list search widget $this->view->wishListSearchWidget = new WishListSearchWidget(); // Getting the ad (second paramters is not used anymore) $this->view->ad = new Ad("user_homepage", "6697829998"); // Getting twitter widget $this->view->twitter = new TwitterWidget(TwitterSvc::getInstance($globalConfig)); // Getting facebook frame $this->view->facebookFrame = new FacebookFrame(); // Get create chronicle links widget if ($connectedUser->getIs_partner() && $connectedUser->getGroupusers()) { $createChroniclesLink = new CreateChroniclesLinks($connectedUser->getGroupusers()); $this->view->createChroniclesLinkView = $createChroniclesLink->get(); } } catch (\Exception $e) { Trace::addItem(sprintf("Une erreur s'est produite dans \"%s->%s\", TRACE : %s\"", get_class(), __FUNCTION__, $e->getTraceAsString())); $this->forward("error", "error", "default"); } }
private function addUserBook($bookId, \Sb\Context\Model\Context $context) { $userBook = new \Sb\Db\Model\UserBook(); $userBook->setUserId($context->getConnectedUser()->getId()); $userBook->setBookId($bookId); $userBook->setIsOwned(true); $userBookDao = \Sb\Db\Dao\UserBookDao::getInstance(); $returnId = $userBookDao->Add($userBook); if ($returnId) { \Sb\Trace\Trace::addItem("Le livre a été ajouté à la biblio correctement."); } else { \Sb\Trace\Trace::addItem("KO : Le livre n'a pas été ajouté à la biblio."); } return $returnId; }