public function disableAction()
 {
     $dest = HTTPHelper::getReferer() ? HTTPHelper::getReferer() : HTTPHelper::Link();
     $id = $this->_getParam('ubgid', -1);
     if ($id > 0) {
         // Getting the userbook gift item
         $userbookGift = UserBookGiftDao::getInstance()->get($id);
         if ($userbookGift) {
             // Checking if the connected user is the offerer
             $globalContext = new \Sb\Context\Model\Context();
             $connectedUser = $globalContext->getConnectedUser();
             if ($userbookGift->getOfferer()->getId() == $connectedUser->getId()) {
                 $userbookGift->setIs_active(false);
                 $userbookGift->setLast_modification_date(new \DateTime());
                 if (UserBookGiftDao::getInstance()->update($userbookGift)) {
                     Flash::addItem(__("L'option d'achat a été annulée correctement.", "s1b"));
                     $this->_redirect($dest);
                     exit;
                 }
             }
         }
     }
     Flash::addItem(__("une erreur s'est produite lors de l'anulation de l'option d'achat.", "s1b"));
     $this->_redirect($dest);
     exit;
 }
 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;
 }
示例#3
0
 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");
     }
 }
示例#4
0
 public static function newCommentPosted($comment, $book)
 {
     $body = __("Bonjour<br/>Un commentaire a été posté sur la critique que vous avez émise sur le livre <a href=\"%s\">%s</a>.<br/><strong>Commentaire :</strong> %s<br/><br/><strong>L'équipe %s</strong>", "s1b");
     $body .= '<br/>' . self::getProfileEditSettingLine();
     $body = sprintf($body, HTTPHelper::Link($book->getLink()), $book->getTitle(), $comment, \Sb\Entity\Constants::SITENAME);
     return $body;
 }
示例#5
0
 public function get()
 {
     $tplBook = new Template("wishedUserBook");
     // Prepare variables
     $viewBookLink = HTTPHelper::Link($this->book->getLink());
     $img = BookHelper::getSmallImageTag($this->book, $this->defImg);
     $bookTitle = $this->book->getTitle();
     $bookAuthors = "";
     if ($this->book->getContributors()) {
         $bookAuthors = sprintf("Auteur(s) : %s", $this->book->getOrderableContributors());
     }
     $isOffered = $this->userbook->getActiveGiftRelated() != null;
     $offerer = null;
     $deactivateGiftOptionLink = "";
     if ($isOffered) {
         $deactivateGiftOptionLink = HTTPHelper::Link(Urls::USERBOOK_GIFT_DISABLE, array("ubgid" => $this->userbook->getActiveGiftRelated()->getId()));
         $offerer = $this->userbook->getActiveGiftRelated()->getOfferer();
     }
     $bookDescription = $this->book->getDescription();
     $buyOnAmazonLink = $this->book->getAmazonUrl();
     $buyOnFnacLink = null;
     if ($this->book->getISBN13()) {
         $buyOnFnacLink = 'http://clic.reussissonsensemble.fr/click.asp?ref=751772&site=14485&type=text&tnb=3&diurl=http%3A%2F%2Feultech.fnac.com%2Fdynclick%2Ffnac%2F%3Feseg-name%3DaffilieID%26eseg-item%3D%24ref%24%26eaf-publisher%3DAFFILINET%26eaf-name%3Dg%3Fn%3Frique%26eaf-creative%3D%24affmt%24%26eaf-creativetype%3D%24affmn%24%26eurl%3Dhttp%253A%252F%252Frecherche.fnac.com%252FSearchResult%252FResultList.aspx%253FSCat%253D0%2525211%2526Search%253D' . $this->book->getISBN13() . '%2526Origin%253Daffilinet%2524ref%2524';
     }
     $setAsOfferedLink = HTTPHelper::Link(Urls::WISHED_USERBOOK_SET_AS_OFFERED, array("ubid" => $this->userbook->getId()));
     $subscribeLink = HTTPHelper::Link(Urls::SUBSCRIBE);
     // Set variables
     $tplBook->setVariables(array("bookTitle" => $bookTitle, "bookAuthors" => $bookAuthors, "viewBookLink" => $viewBookLink, "image" => $img, "isOffered" => $isOffered, "buyOnAmazonLink" => $buyOnAmazonLink, "buyOnFnacLink" => $buyOnFnacLink, "offerer" => $offerer, "setAsOfferedLink" => $setAsOfferedLink, "subscribeLink" => $subscribeLink, "deactivateGiftOptionLink" => $deactivateGiftOptionLink, "isConnected" => $this->getContext()->getConnectedUser()));
     return $tplBook->output();
 }
 /**
  * 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 get()
 {
     $baseTpl = "components/autoPromoWishlistWidget";
     $tpl = new Template($baseTpl);
     $autoPromoWishListLink = HTTPHelper::Link(Urls::USER_FRIENDS_WISHLIST);
     $autoPromoWishListImage = $this->getContext()->getBaseUrl() . "Resources/images/homepage/auto-promo-wishlist.png";
     $autoPromoWishListTitle = __("Offrez un livre à vos amis", "s1b");
     $tpl->setVariables(array("autoPromoWishListTitle" => $autoPromoWishListTitle, "autoPromoWishListLink" => $autoPromoWishListLink, "autoPromoWishListImage" => $autoPromoWishListImage));
     return $tpl->output();
 }
示例#8
0
 public function get()
 {
     $tpl = new Template("components/searchForm");
     $formAction = HTTPHelper::Link(Urls::BOOK_SEARCH_SUBMIT);
     $searchTermDef = "Titre, auteur, ISBN";
     $searchTerm = ArrayHelper::getSafeFromArray($_REQUEST, "searchTerm", $searchTermDef);
     $isConnected = false;
     if ($this->getContext()->getConnectedUser()) {
         $isConnected = true;
     }
     $tpl->setVariables(array("formAction" => $formAction, "searchTerm" => $searchTerm, "searchTermDef" => $searchTermDef, "isConnected" => $isConnected, "showSearchTermDef" => $this->showSearchTermDef));
     return $tpl->output();
 }
示例#9
0
 public function get()
 {
     $globalContext = \Sb\Context\Model\Context::getInstance();
     $tplHeader = new Template("header");
     $baseUrl = Urls::USER_LIBRARY;
     if ($globalContext->getIsShowingFriendLibrary()) {
         $baseUrl = Urls::FRIEND_LIBRARY;
     }
     $variables = array("allBooksUrl" => HTTPHelper::Link($baseUrl, array("key" => LibraryListKeys::ALL_BOOKS_KEY, "reset" => 1)), "borrowedBooksUrl" => HTTPHelper::Link($baseUrl, array("key" => LibraryListKeys::BORROWED_BOOKS_KEY, "reset" => 1)), "lendedBooksUrl" => HTTPHelper::Link($baseUrl, array("key" => LibraryListKeys::LENDED_BOOKS_KEY, "reset" => 1)), "wishedBooksUrl" => HTTPHelper::Link($baseUrl, array("key" => LibraryListKeys::WISHED_BOOKS_KEY, "reset" => 1)), "myBooksUrl" => HTTPHelper::Link($baseUrl, array("key" => LibraryListKeys::MY_BOOKS_KEY, "reset" => 1)), "friendLibrary" => false);
     if ($globalContext->getIsShowingFriendLibrary()) {
         $friend = UserDao::getInstance()->get($this->friendUserId);
         $variables["friendLibrary"] = true;
         $variables["friendUserName"] = $friend->getFirstName();
     }
     $tplHeader->setVariables($variables);
     $this->setActiveTab($tplHeader, $this->key);
     return $tplHeader->output();
 }
示例#10
0
 public function editAction()
 {
     $globalContext = new \Sb\Context\Model\Context();
     $user = $globalContext->getConnectedUser();
     $userSettings = $user->getSetting();
     $profile = new UserProfile($user, $userSettings, false, false, false);
     $userLang = ArrayHelper::getSafeFromArray($_SESSION, "WPLANG", "fr_FR");
     $countries = CountryDao::getInstance()->getAll();
     $userCountry = null;
     if ($user->getCountry()) {
         $userCountry = CountryDao::getInstance()->getCountryByCode($user->getCountry());
     }
     $submitUrl = HTTPHelper::Link(Urls::USER_PROFILE_SUBMIT);
     $this->view->profileView = $profile->get();
     $this->view->user = $user;
     $this->view->userSettings = $userSettings;
     $this->view->userLang = $userLang;
     $this->view->countries = $countries;
     $this->view->userCountry = $userCountry;
     $this->view->submitUrl = $submitUrl;
 }
示例#11
0
 public function get()
 {
     $tplBook = new \Sb\Templates\Template("pushedBooks/pushedBook");
     // préparation des champs pour le template
     // Prepare variables
     $avgRating = $this->book->getAverageRating();
     $roundedRating = floor($avgRating);
     $ratingCss = "rating-" . $roundedRating;
     $viewBookLink = \Sb\Helpers\HTTPHelper::Link($this->book->getLink());
     $img = \Sb\Helpers\BookHelper::getMediumImageTag($this->book, $this->defImg);
     $bookTitle = $this->book->getTitle();
     $bookDescription = \Sb\Helpers\StringHelper::tronque($this->book->getDescription(), 250);
     $bookPublication = $this->book->getPublicationInfo();
     $bookAuthors = "";
     if ($this->book->getContributors()) {
         $bookAuthors = sprintf("Auteur(s) : %s", $this->book->getOrderableContributors());
     }
     $nbRatings = $this->book->getNbRatedUserBooks();
     $nbBlowOfHearts = $this->book->getNbOfBlowOfHearts();
     // Set variables
     $tplBook->setVariables(array("averageRating" => round($avgRating, 2), "ratingCss" => $ratingCss, "isBlowOfHeart" => $this->boh, "nbBlowOfHearts" => $nbBlowOfHearts, "roundedRating" => $roundedRating, "bookTitle" => $bookTitle, "bookDescription" => $bookDescription, "bookPublication" => $bookPublication, "bookAuthors" => $bookAuthors, "viewBookLink" => $viewBookLink, "image" => $img, "nbRatings" => $nbRatings));
     return $tplBook->output();
 }
示例#12
0
 public function createWelcomeMessage($userId)
 {
     $siteName = \Sb\Entity\Constants::SITENAME;
     $title = __("Bienvenue au sein de la communauté", "s1b") . " " . $siteName;
     $body = __("Bonjour,", "s1b") . "<br/><br/>";
     $body .= __("Merci d'avoir rejoint", "s1b") . " " . $siteName . "<br/>";
     $body .= __("Toute l'équipe espère que vous profiterez pleinement des fonctionnalités du site, à savoir:", "s1b") . "<br/>";
     $body .= __("* partager vos lectures avec vos amis", "s1b") . "<br/>";
     $body .= __("* leurs recommander un coup de coeur", "s1b") . "<br/>";
     $body .= __("* trouver vos prochaines lectures grâce à leurs conseils", "s1b") . "<br/>";
     $body .= __("* suivre les livres que vous prêtez ou que vous avez emprunté", "s1b") . "<br/>";
     $body .= __("* utiliser les bibliothèques de vos amis, surtout leurs envies de lecture, pour leurs faire un cadeau réussi", "s1b") . "<br/><br/>";
     $body .= __("Bref, cette liste n'est pas exhaustive et nous espérons que vous nous aiderez à continuer à vous proposer de nouvelles fonctionnalités, par exemple en proposant à vos amis de rejoindre", "s1b") . " " . $siteName . "." . "<br/>";
     $body .= '<a href=' . \Sb\Helpers\HTTPHelper::Link(\Sb\Entity\Urls::USER_FRIENDS_FIND) . ' onclick="newInvite(); return false;">' . __("Inviter vos amis de Facebook à rejoindre", "s1b") . " " . $siteName . '</a>' . "<br/>";
     $body .= __("Bonne expérience.", "s1b") . "<br/><br/>";
     $body .= __("L'équipe", "s1b") . " " . $siteName;
     $message = new \Sb\Db\Model\Message();
     $message->setMessage($body);
     $message->setTitle($title);
     $message->setIs_read(false);
     $message->setRecipient(\Sb\Db\Dao\UserDao::getInstance()->get($userId));
     $message->setSender(\Sb\Db\Dao\UserDao::getInstance()->get(1));
     return \Sb\Db\Dao\MessageDao::getInstance()->add($message);
 }
示例#13
0
 public function get()
 {
     $tplBook = new \Sb\Templates\Template("pushedUserBooks/pushedUserBook");
     // Prepare variables
     $rating = $this->userBook->getRating();
     $boh = $this->userBook->getIsBlowOfHeart();
     $ratingCss = "rating-" . $rating;
     $viewBookLink = \Sb\Helpers\HTTPHelper::Link($this->book->getLink());
     $img = \Sb\Helpers\BookHelper::getMediumImageTag($this->book, $this->defImg);
     $bookTitle = $this->book->getTitle();
     $bookDescription = mb_substr($this->book->getDescription(), 0, 250, "utf-8") . "...";
     $bookPublication = $this->book->getPublicationInfo();
     if ($this->book->getContributors()) {
         $bookAuthors = sprintf(__("Auteur(s) : %s", "s1b"), $this->book->getOrderableContributors());
     }
     if ($this->userBook->getReadingState()) {
         $readingStateLabel = $this->userBook->getReadingState()->getLabel();
     }
     $isOwned = $this->userBook->getIsOwned();
     $isWished = $this->userBook->getIsWished();
     // Set variables
     $tplBook->setVariables(array("rating" => $rating, "ratingCss" => $ratingCss, "isBlowOfHeart" => $boh, "bookTitle" => $bookTitle, "bookDescription" => $bookDescription, "bookPublication" => $bookPublication, "bookAuthors" => $bookAuthors, "viewBookLink" => $viewBookLink, "image" => $img, "readingStateLabel" => $readingStateLabel, "isOwned" => $isOwned, "isWished" => $isWished, "showingConnectedUserBook" => $this->showingConnectedUserBook));
     return $tplBook->output();
 }
示例#14
0
 /**
  * Send invitation to users
  */
 public function inviteAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         $user = $globalContext->getConnectedUser();
         $continue = true;
         $emails = ArrayHelper::getSafeFromArray($_POST, 'Emails', null);
         $message = ArrayHelper::getSafeFromArray($_POST, 'Message', null);
         if (!$emails || !$message) {
             Flash::addItem(__("Vous devez renseigner tous les champs obligatoires.", "s1b"));
             $continue = false;
         }
         if ($continue) {
             $emailsListFromPost = explode(",", $emails);
             // Getting emails list
             if ($emailsListFromPost) {
                 // Looping through all emails for validating all of them
                 // At the end of the loop:
                 // we will have an array of emails to be processed
                 // and flag to process or not the sendings
                 $emailsList = array();
                 foreach ($emailsListFromPost as $emailToInvite) {
                     $addEmail = true;
                     $emailToInvite = strtolower(trim($emailToInvite));
                     if ($emailToInvite != "") {
                         // Testing if the email is valid
                         if (!StringHelper::isValidEmail($emailToInvite)) {
                             Flash::addItem(sprintf(__("%s n'est pas un email valide.", "s1b"), $emailToInvite));
                             // We will stop invitation sending
                             $continue = false;
                             // Current email not added to the array of emails to be processed
                             $addEmail = false;
                         } else {
                             // Testing if the email does not match an existing user
                             $userInDb = UserDao::getInstance()->getByEmail($emailToInvite);
                             if ($userInDb && !$userInDb->getDeleted()) {
                                 $friendRequestUrl = HTTPHelper::Link(Urls::USER_FRIENDS_REQUEST, array("fid" => $userInDb->getId()));
                                 Flash::addItem(sprintf(__("Un utilisateur existe déjà avec l'email : %s. <a class=\"link\" href=\"%s\">Envoyer lui une demande d'ami</a>", "s1b"), $emailToInvite, $friendRequestUrl));
                                 // We will stop invitation sending
                                 $continue = false;
                                 // Current email not added to the array of emails to be processed
                                 $addEmail = false;
                             } else {
                                 // Testing if invitations have been sent to that guest (email) by the current user
                                 $invitations = InvitationDao::getInstance()->getListForSenderAndGuestEmail($user, $emailToInvite);
                                 if ($invitations && count($invitations) > 0) {
                                     Flash::addItem(sprintf(__("Vous avez déjà envoyé une invitation à cet email : %s.", "s1b"), $emailToInvite));
                                     // We will stop invitation sending
                                     $continue = false;
                                     // Current email not added to the array of emails to be processed
                                     $addEmail = false;
                                 }
                             }
                         }
                     }
                     if ($addEmail) {
                         $emailsList[] = $emailToInvite;
                     }
                 }
                 if ($continue) {
                     // Looping through all emails for sending invitation
                     $initialMessage = $message;
                     foreach ($emailsList as $emailToInvite) {
                         $emailToInvite = strtolower(trim($emailToInvite));
                         if ($emailToInvite != "") {
                             $sendInvitation = true;
                             // Testing again if invitations have been sent to that guest (email) by the current user
                             $invitations = InvitationDao::getInstance()->getListForSenderAndGuestEmail($user, $emailToInvite);
                             if ($invitations && count($invitations) > 0) {
                                 $sendInvitation = false;
                             }
                             if ($sendInvitation) {
                                 // Getting existing guests matching email, and take first 1
                                 $guest = null;
                                 $guests = GuestDao::getInstance()->getListByEmail($emailToInvite);
                                 if ($guests && count($guests) > 0) {
                                     $guest = $guests[0];
                                 }
                                 $token = sha1(uniqid(rand()));
                                 // Send invite email
                                 $message = str_replace("\n", "<br/>", $initialMessage);
                                 $message .= "<br/><br/>";
                                 $message .= sprintf(__("<a href=\"%s\">S'inscrire</a> ou <a href=\"%s\">Refuser</a>", "s1b"), HTTPHelper::Link(Urls::SUBSCRIBE), HTTPHelper::Link(Urls::REFUSE_INVITATION, array("Token" => $token, "Email" => $emailToInvite)));
                                 $message .= "<br/><br/>";
                                 $message .= "<strong>" . sprintf(__("L'équipe %s", "s1b"), Constants::SITENAME) . "<strong/>";
                                 MailSvc::getNewInstance($user->getEmail(), $user->getEmail())->send($emailToInvite, sprintf(__("Invitation à rejoindre %s", "s1b"), Constants::SITENAME), $message);
                                 // Create invitation
                                 $invitation = new Invitation();
                                 $invitation->setSender($user);
                                 $invitation->setToken($token);
                                 $invitation->setLast_modification_date(new \DateTime());
                                 if ($guest) {
                                     // Updating guest
                                     $guest->addInvitations($invitation);
                                     GuestDao::getInstance()->update($guest);
                                 } else {
                                     // Create guest
                                     $guest = new Guest();
                                     $guest->setEmail($emailToInvite);
                                     $guest->setCreation_date(new \DateTime());
                                     $guest->addInvitations($invitation);
                                     GuestDao::getInstance()->add($guest);
                                 }
                                 Flash::addItem(sprintf(__("Une invitation a été envoyée à %s.", "s1b"), $emailToInvite));
                             }
                         }
                     }
                     HTTPHelper::redirectToHome();
                 }
             }
         }
         // If we arrive here : an error occured, then redirect to the invite form
         HTTPHelper::redirect(Urls::USER_FRIENDS_INVITE, array("emails" => $emails));
     } 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");
     }
 }
示例#15
0
 /**
  * Get detail page link for chronicle
  * @return string the detail page link
  */
 public function getDetailLink()
 {
     if ($this->getTitle()) {
         return HTTPHelper::Link("chronique/" . StringHelper::sanitize(StringHelper::cleanHTML($this->getTitle())) . "-" . $this->getId());
     } else {
         return HTTPHelper::Link("chronique/chronique-" . $this->getId());
     }
 }
示例#16
0
 public static function getMediumImageTagForFlipCarousel(Book $book, $defaultImg)
 {
     $href = HTTPHelper::Link($book->getLink());
     return ImageHelper::getMediumImageTagForFlipCarousel($book->getImageUrl(), $href, $book->getTitle(), $defaultImg);
 }
示例#17
0
 /**
  * Get a chronicle as ChronicleViewModel object for chronicle detail page
  * @param int $nbSimilarChronicles the number of similar chronicles to return , if not passed (null), then no similar chronicles will be returned
  * @param int $nbSameAuthorChronicles number of same author chronicles to return
  * @param int $nbPressReviews number of press reviews to return
  * @param boolean flag to tell to use cache or not
  * @return \Sb\Model\ChronicleViewModel a chronicle as a ChronicleViewModel object
  */
 public function getAsChronicleViewModel($nbSimilarChronicles = null, $nbSameAuthorChronicles = null, $nbPressReviews = null, $useCache = true)
 {
     /* @var $chronicle ChronicleViewModel */
     $chronicleViewModel = new ChronicleViewModel();
     // Set common members
     $this->setChronicleViewModelLight($chronicleViewModel);
     $chronicleViewModel->setText($this->chronicle->getText());
     $chronicleViewModel->setUserName($this->chronicle->getUser()->getUserName());
     $chronicleViewModel->setUserProfileLink(HTTPHelper::Link(Urls::USER_PROFILE, array("uid" => $this->chronicle->getUser()->getId())));
     $chronicleViewModel->setUserImage(UserHelper::getMediumImageTag($this->chronicle->getUser(), __("image chroniqueur", "s1b")));
     $chronicleViewModel->setSource($this->chronicle->getSource());
     // Set book
     $chronicleViewModel->setChronicleHasBook(false);
     if ($this->chronicle->getBook()) {
         $chronicleViewModel->setChronicleHasBook(true);
         $chronicleViewModel->setBook($this->chronicle->getBook());
     }
     // Set link info
     $chronicleViewModel->setLinkCss("chr-link-other");
     $chronicleViewModel->setLinkText(__("En savoir plus", "s1b"));
     switch ($this->chronicle->getLink_type()) {
         case ChronicleLinkType::IMAGE:
             $chronicleViewModel->setLinkCss("chr-link-image");
             $chronicleViewModel->setLinkText(__("Voir la photo", "s1b"));
             break;
         case ChronicleLinkType::PODCAST:
             $chronicleViewModel->setLinkCss("chr-link-podcast");
             $chronicleViewModel->setLinkText(__("Ecouter le podcast", "s1b"));
             break;
         case ChronicleLinkType::PRESS:
             $chronicleViewModel->setLinkCss("chr-link-press");
             $chronicleViewModel->setLinkText(__("Lire l'article", "s1b"));
             break;
         case ChronicleLinkType::URL:
             $chronicleViewModel->setLinkCss("chr-link-url");
             $chronicleViewModel->setLinkText(__("En savoir plus", "s1b"));
             break;
         case ChronicleLinkType::VIDEO:
             $chronicleViewModel->setLinkCss("chr-link-video");
             $linkText = __("Regarder la video", "s1b");
             break;
     }
     // Set type label
     $chronicleViewModel->setTypeLabel(ChronicleHelper::getTypeLabel($this->chronicle->getType_id()));
     // Set similar chronicles or same author chronicles
     if ($nbSimilarChronicles || $nbSameAuthorChronicles) {
         $chroniclesAdapter = new ChronicleListAdapter();
         // Set the similar chronicles
         if ($nbSimilarChronicles) {
             $chroniclesAdapter->setChronicles($this->getSimilarChronicles($nbSimilarChronicles, $useCache));
             $chronicleViewModel->setSimilarChronicles($chroniclesAdapter->getAsChronicleViewModelList());
         }
         // Set the same author chronicles
         if ($nbSameAuthorChronicles) {
             $chroniclesAdapter->setChronicles($this->getSameAuthorChronicles($nbSameAuthorChronicles, $useCache));
             $chronicleViewModel->setSameAuthorChronicles($chroniclesAdapter->getAsChronicleViewModelList());
         }
     }
     // Set press reviews
     if ($nbPressReviews) {
         $pressReviews = null;
         // Get press review with same tag
         if ($this->chronicle->getTag()) {
             $pressReviews = PressReviewSvc::getInstance()->getList(array("tag" => array(true, "=", $this->chronicle->getTag()), "is_validated" => array(false, "=", 1)), $nbPressReviews, $useCache);
         }
         // Get press review with same keywords
         if ((!$pressReviews || count($pressReviews) < $nbPressReviews) && $this->chronicle->getKeywords()) {
             $keyWords = explode(",", $this->chronicle->getKeywords());
             foreach ($keyWords as $keyWord) {
                 // Get press review with same keywords
                 $criteria = array("keywords" => array(false, "LIKE", $keyWord));
                 $pressReviewsWithKeywords = PressReviewSvc::getInstance()->getList($criteria, $nbPressReviews, $useCache);
                 if ($pressReviewsWithKeywords) {
                     if (!$pressReviews) {
                         $pressReviews = $pressReviewsWithKeywords;
                     } else {
                         $pressReviews = EntityHelper::mergeEntities($pressReviews, $pressReviewsWithKeywords);
                     }
                     if (count($pressReviews) >= $nbPressReviews) {
                         break;
                     }
                 }
             }
             if ($pressReviews) {
                 $pressReviews = array_slice($pressReviews, 0, $nbPressReviews);
             }
         }
         $chronicleViewModel->setPressReviews($pressReviews);
     }
     return $chronicleViewModel;
 }
示例#18
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();
 }
示例#19
0
 private static function getProfileEditSettingLine()
 {
     return '<h5>' . __("Si vous souhaitez ne plus recevoir par email les alertes modifiez les paramètres de votre profil dans", "s1b") . " " . "<a href='" . \Sb\Helpers\HTTPHelper::Link(\Sb\Entity\Urls::USER_PROFILE_SETTINGS) . "'>" . __("Mes paramètres", "s1b") . "</a>" . '</h5>';
 }
示例#20
0
 /**
  * @return mixed|string
  */
 public function get()
 {
     $lineIdx = 0;
     foreach (array_values($this->shownResults) as $book) {
         $lineIdx++;
         $addSep = true;
         if ($lineIdx == 1) {
             $addSep = false;
         }
         $bk = $book;
         $language = urlencode($bk->getLanguage());
         if ($bk->getImageUrl()) {
             $imgSrc = $bk->getImageUrl();
         } else {
             $imgSrc = $this->defImg;
         }
         // Utilisation de urlencode à la place htmlspecialchars car ce dernier pose des pbs qd la valeur est ensuite passée en post
         $title = $bk->getTitle();
         $titleEsc = urlencode($bk->getTitle());
         // encodé
         $author = $bk->getOrderableContributors();
         $authorEsc = urlencode($bk->getOrderableContributors());
         // encodé
         $id = $bk->getId();
         $isbn10 = $bk->getISBN10();
         $isbn13 = $bk->getISBN13();
         $asin = $bk->getASIN();
         $desc = StringHelper::tronque($bk->getDescription(), 350);
         $descEsc = urlencode($bk->getDescription());
         // encodé
         $smallImg = $bk->getSmallImageUrl();
         $img = $bk->getImageUrl();
         $largeImg = $bk->getLargeImageUrl();
         $pubEsc = "";
         $pubInfo = "";
         if ($bk->getPublisher()) {
             $pubEsc = urlencode($bk->getPublisher()->getName());
             // encodé
             $pubInfo = $bk->getPublicationInfo();
         }
         $pubDtStr = "";
         if ($book->getPublishingDate()) {
             $pubDtStr = $book->getPublishingDate()->format("Y-m-d H:i:s");
         }
         $amazonUrl = $book->getAmazonUrl();
         $nbOfPages = $book->getNb_of_pages();
         $cssClass = $lineIdx % 2 ? "lineA" : "lineB";
         $viewBookLink = null;
         $bookInDB = false;
         if ($bk->getId()) {
             $viewBookLink = HTTPHelper::Link($bk->getLink());
             $bookInDB = true;
         }
         $resultTpl = new Template('searchBook/resultRow');
         $resultTpl->setVariables(array('addSep' => $addSep, 'viewBookLink' => $viewBookLink, 'bookInDB' => $bookInDB, 'cssClass' => $cssClass . ' ' . ($bookInDB ? 'indb' : ''), 'title' => $title, 'publisher' => $pubInfo, 'author' => $author, 'id' => $id, 'isbn10' => $isbn10, 'isbn13' => $isbn13, 'asin' => $asin, 'titleEsc' => $titleEsc, 'descEsc' => $descEsc, 'desc' => $desc, 'smallImg' => $smallImg, 'img' => $img, 'largeImg' => $largeImg, 'imgSrc' => $imgSrc, 'authorEsc' => $authorEsc, 'pubEsc' => $pubEsc, 'pubDtStr' => $pubDtStr, 'amazonUrl' => $amazonUrl, 'language' => $language, 'nbOfPages' => $nbOfPages));
         $resultTplArr[] = $resultTpl;
     }
     $results = Template::merge($resultTplArr);
     $resultsTpl = new Template('searchBook/results');
     $resultsTpl->set("resultRows", $results);
     $links = $this->pagerLinks;
     $resultsTpl->set("links", $links['all']);
     $resultsTpl->set("first", $this->firstItemIdx);
     $resultsTpl->set("last", $this->lastItemIdx);
     $resultsTpl->set("nbItemsTot", $this->nbItemsTot);
     return $resultsTpl->output();
 }
示例#21
0
 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();
 }
示例#22
0
 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();
 }
示例#23
0
 public function facebookLogAction()
 {
     try {
         $globalConfig = new Sb\Config\Model\Config();
         $accountDeleted = __("Votre compte a été supprimé.", "s1b");
         $home = HTTPHelper::Link("");
         $loginFaceBook = HTTPHelper::Link(Urls::LOGIN_FACEBOOK);
         // Testing if user is facebook connected
         $facebookSvc = new FacebookSvc($globalConfig->getFacebookApiId(), $globalConfig->getFacebookSecret(), $loginFaceBook, $home);
         $facebookUser = $facebookSvc->getUser();
         if ($facebookUser) {
             // If yes, testing if a user exist in db (and not deleted)
             // Search a matching activated user in DB
             $faceBookEmail = $facebookUser->getEmail();
             $facebookId = $facebookUser->getUid();
             $userInDB = \Sb\Db\Dao\UserDao::getInstance()->getFacebookUser($faceBookEmail);
             if (!$userInDB) {
                 // If no existing user => create an account and redirect to user homepage
                 // create user in db
                 $userFromFB = new User();
                 UserMapper::mapFromFacebookUser($userFromFB, $facebookUser);
                 $userFromFB->setToken(sha1(uniqid(rand())));
                 $userFromFB->setDeleted(false);
                 $setting = new UserSetting();
                 UserSettingHelper::loadDefaultSettings($setting);
                 $userFromFB->setSetting($setting);
                 $userInDB = UserDao::getInstance()->add($userFromFB);
                 // send confirmation email
                 $subject = sprintf(__("Votre compte %s a été créé avec Facebook", "s1b"), Constants::SITENAME);
                 MailSvc::getInstance()->send($userInDB->getEmail(), $subject, MailHelper::faceBookAccountCreationEmailBody($userInDB->getFirstName()));
                 // Test if the email matches invitations and set them to accepted and validated
                 InvitationSvc::getInstance()->setInvitationsAccepted($userInDB->getEmail());
                 // Send warning email to webmaster
                 MailSvc::getInstance()->send(\Sb\Entity\Constants::WEBMASTER_EMAIL . ", berliozd@gmail.com, rebiffe_olivier@yahoo.fr", __("nouveau user via facebook", "s1b"), $userInDB->getEmail());
                 // send message in user internal mailbox
                 MessageSvc::getInstance()->createWelcomeMessage($userInDB->getId());
                 // redirect to user homepage
                 AuthentificationSvc::getInstance()->loginSucces($userInDB);
             } elseif ($userInDB->getDeleted()) {
                 // In user deleted, display a message and redirect to referer
                 Flash::addItem($accountDeleted);
                 $facebookSvc->cleanUser();
                 $facebookUser = null;
                 $faceBookEmail = null;
                 $facebookId = null;
                 HTTPHelper::redirectToReferer();
             } else {
                 // If yes => connect and redirect to user homepage
                 if (!$userInDB->getConnexionType() != ConnexionType::FACEBOOK) {
                     $userInDB->setConnexionType(ConnexionType::FACEBOOK);
                 }
                 if (!$userInDB->getFacebookId()) {
                     $userInDB->setFacebookId($facebookUser->getUid());
                 }
                 if (!$userInDB->getPicture()) {
                     $userInDB->setPicture($facebookUser->getPic_small());
                 }
                 if (!$userInDB->getPictureBig()) {
                     $userInDB->setPictureBig($facebookUser->getPic());
                 }
                 if (!$userInDB->getFacebookLanguage()) {
                     $userInDB->setFacebookLanguage($facebookUser->getLocale());
                 }
                 if (!$userInDB->getGender()) {
                     $userInDB->setGender($facebookUser->getSex());
                 }
                 if (!$userInDB->getCity()) {
                     $userInDB->setCity($facebookUser->getHometown_location());
                 }
                 if (!$userInDB->getBirthDay()) {
                     $userInDB->setBirthDay($facebookUser->getBirthday());
                 }
                 $userInDB->setLastLogin(new \DateTime());
                 UserDao::getInstance()->update($userInDB);
                 AuthentificationSvc::getInstance()->loginSucces($userInDB);
             }
         } else {
             // If no, redirect to facebook login page
             HTTPHelper::redirectToUrl($facebookSvc->getFacebookLogInUrl());
         }
     } 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");
     }
 }
示例#24
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();
 }
示例#25
0
 public static function getStatusPictos(\Sb\Db\Model\UserBook $userBook, $friendLibraryView = false)
 {
     $config = self::getConfig();
     $lendings = $userBook->getLendings();
     $borrowings = $userBook->getBorrowings();
     //        var_dump($lending);
     $isBorrowed = false;
     $isLent = false;
     $isOwned = $userBook->getIsOwned();
     $isWished = $userBook->getIsWished();
     $borrowedOnce = $userBook->getBorrowedOnce();
     $link = \Sb\Helpers\HTTPHelper::Link(\Sb\Entity\Urls::LENDING_EDIT, array("ubid" => $userBook->getId()));
     $borrowerName = "";
     $lenderName = "";
     $lendingStartDate = "";
     $borrowingStartDate = "";
     $oneActiveLending = false;
     $oneActiveBorrowing = false;
     $oneLendingWaitingInactivation = false;
     if ($lendings) {
         $lending = new \Sb\Db\Model\Lending();
         foreach ($lendings as $lending) {
             if ($lending->getState() != \Sb\Lending\Model\LendingState::IN_ACTIVE) {
                 $oneActiveLending = true;
                 $borrowerName = $lending->getBorrower_userbook()->getUser()->getFirstName() . " " . $lending->getBorrower_userbook()->getUser()->getLastName();
                 $lendingStartDate = $lending->getStartDate()->format(__("d/m/Y", "s1b"));
             }
             if ($lending->getState() == \Sb\Lending\Model\LendingState::WAITING_INACTIVATION) {
                 $oneLendingWaitingInactivation = true;
             }
         }
     }
     if ($borrowings) {
         $borrowing = new \Sb\Db\Model\Lending();
         foreach ($borrowings as $borrowing) {
             if ($borrowing->getState() != \Sb\Lending\Model\LendingState::IN_ACTIVE) {
                 $oneActiveBorrowing = true;
                 if ($borrowing->getUserbook()) {
                     $lenderName = $borrowing->getUserbook()->getUser()->getFirstName() . " " . $borrowing->getUserBook()->getUser()->getLastName();
                 } elseif ($borrowing->getGuest()) {
                     $lenderName = sprintf("%s (invité)", $borrowing->getGuest()->getName());
                 }
                 $borrowingStartDate = $borrowing->getStartDate()->format(__("d/m/Y", "s1b"));
             }
             //                if ($borrowing->getState() == \Sb\Lending\Model\LendingState::WAITING_INACTIVATION) {
             //                    $oneLendingWaitingInactivation = true;
             //                }
         }
     }
     // Y'a t'il un prêt en cours pour ce livre ?
     if ($oneActiveLending) {
         $editLendingInfo = sprintf("Prêt&eacute; à %s depuis le %s", $borrowerName, $lendingStartDate);
         $isLent = true;
     } elseif ($oneActiveBorrowing) {
         $editLendingInfo = sprintf("Emprunté à %s depuis le %s", $lenderName, $borrowingStartDate);
         $isBorrowed = true;
     } else {
         $editLendingInfo = __("Prétez ce livre", "s1b");
     }
     $pictos = "";
     if ($isOwned) {
         $pictos .= \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_OWNED);
     }
     if ($isWished) {
         $pictos .= \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_WISHED);
     }
     if ($isLent) {
         if ($friendLibraryView) {
             $pictos .= \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_LENT);
         } else {
             $pictos .= sprintf("<a href=\"%s\" title=\"%s\">%s</a>", $link, $editLendingInfo, \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_LENT));
         }
     }
     if ($isBorrowed) {
         if ($friendLibraryView) {
             $pictos .= \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_BORROWED);
         } else {
             $pictos .= sprintf("<a href=\"%s\" title=\"%s\">%s</a>", $link, $editLendingInfo, \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_BORROWED));
         }
     }
     if (!$friendLibraryView) {
         if ($isOwned && !$isLent && !$isBorrowed && !$isWished) {
             if ($friendLibraryView) {
                 $pictos .= \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_LENDING);
             } else {
                 $pictos .= sprintf("<a href=\"%s\" title=\"%s\">%s</a>", $link, $editLendingInfo, \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_LENDING));
             }
         }
     }
     if ($oneLendingWaitingInactivation) {
         $pictos .= sprintf("<a href=\"%s\" title=\"%s\">%s</a>", $link, $editLendingInfo, \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_RETURN_TO_VALIDATE));
     }
     //        if (!$isBorrowed && $borrowedOnce)
     //            $pictos.=sprintf("<span title=\"%s\">%s</span>", __("Ce livre a fait l'objet d'un emprunt dans le passé.", "s1b"), \Sb\Helpers\BooksHelper::getStatusPicto(\Sb\Helpers\BooksHelper::PICTO_BORROWED_ONCE));
     return $pictos;
 }
示例#26
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;
 }
示例#27
0
 public function borrowFromGuestAction()
 {
     try {
         $globalContext = new \Sb\Context\Model\Context();
         if ($this->validateUserInputForm()) {
             $bookForm = new BookForm($_POST);
             // testing if book can be found in db by id
             if ($bookForm->getId()) {
                 $bookInDb = BookDao::getInstance()->get($bookForm->getId());
             }
             // testing if book can be found in db by isbn10, isbn13, asin
             if (!$bookInDb) {
                 $bookInDb = BookDao::getInstance()->getOneByCodes($bookForm->getISBN10(), $bookForm->getISBN13(), $bookForm->getASIN());
             }
             // getting the book data from post and adding to db
             if (!$bookInDb) {
                 // Récupération du Book depuis le POST
                 $bookInDb = new Book();
                 BookMapper::map($bookInDb, $_POST, "book_");
                 // book not in db : need to add it
                 $bookInDb->setCreationDate(new \DateTime());
                 $bookInDb->setLastModificationDate(new \DateTime());
                 BookDao::getInstance()->add($bookInDb);
             }
             if ($bookInDb) {
                 $guestName = ArrayHelper::getSafeFromArray($_POST, "guest_name", null);
                 $guestEmail = ArrayHelper::getSafeFromArray($_POST, "guest_email", null);
                 $guest = new Guest();
                 $guest->setName($guestName);
                 $guest->setEmail($guestEmail);
                 $guest->setCreation_date(new \DateTime());
                 if ($guestEmail) {
                     $friendToBorrowInDb = UserDao::getInstance()->getByEmail($guestEmail);
                     if ($friendToBorrowInDb) {
                         Flash::addItem(sprintf(__("Un utilisateur existe déjà avec l'email que vous avez saisi. Nous vous proposons de lui envoyer une demande d'ami. Vous pourrez ensuite lui emprunter ce livre directement depuis sa bibliothèque. <a class=\"link\" href=\"%s\">Envoyer une demande d'ami</a>", "s1b"), HTTPHelper::Link(Urls::USER_FRIENDS_REQUEST, array("fid" => $friendToBorrowInDb->getId()))));
                         HTTPHelper::redirectToReferer();
                     } else {
                         $token = sha1(uniqid(rand()));
                         // Send invite email
                         $message = __(sprintf("%s vous invite à rejoindre %s, réseau communautaire autour du livre et de la lecture.", sprintf("%s %s", $globalContext->getConnectedUser()->getFirstName(), $globalContext->getConnectedUser()->getLastName()), $_SERVER["SERVER_NAME"]), "s1b");
                         $message .= "<br/><br/>";
                         $message .= sprintf(__("Il a utilisé %s pour noter qu'il vous a emprunté \"%s\"."), Constants::SITENAME, $bookInDb->getTitle());
                         $message .= "<br/><br/>";
                         $message .= __("Venez échanger sur vos lectures et coups de coeur, chercher l'inspiration grâce aux recommandations, gérer et partager votre bibliothèque avec vos amis et trouver dans leurs listes d'envies des idées de cadeaux.");
                         $message .= "<br/><br/>";
                         $subscriptionLink = HTTPHelper::Link(Urls::SUBSCRIBE);
                         $refuseInvitationLink = HTTPHelper::Link(Urls::REFUSE_INVITATION, array("Token" => $token, "Email" => $guestEmail));
                         $message .= sprintf(__("L'inscription est gratuite ! Rejoignez-nous... <a href=\"%s\">S'inscrire</a> ou <a href=\"%s\">Refuser l'invitation</a>"), $subscriptionLink, $refuseInvitationLink);
                         $message .= "<br/><br/>";
                         $message .= sprintf(__("<strong>L'équipe Cherbouquin</strong>", "s1b"), Constants::SITENAME);
                         MailSvc::getInstance()->send($guestEmail, sprintf(__("Invitation à rejoindre %s", "s1b"), Constants::SITENAME), $message);
                         // Create invitation in DB
                         $invitation = new Invitation();
                         $invitation->setSender($globalContext->getConnectedUser());
                         $invitation->setGuest($guest);
                         $invitation->setCreation_date(new \DateTime());
                         $invitation->setToken($token);
                         InvitationDao::getInstance()->add($invitation);
                         Flash::addItem(__("Un email d'invitation a été envoyé à votre ami.", "s1b"));
                     }
                 } else {
                     GuestDao::getInstance()->add($guest);
                 }
                 // Testing if the user has the book in his lib but marked as deleted
                 $userBookBorrower = UserBookDao::getInstance()->getByBookIdAndUserId($globalContext->getConnectedUser()->getId(), $bookInDb->getId());
                 if ($userBookBorrower && $userBookBorrower->getIs_deleted()) {
                     $userBookBorrower->setIs_deleted(false);
                     $userBookBorrower->setLastModificationDate(new \DateTime());
                     UserBookDao::getInstance()->update($userBookBorrower);
                     Flash::addItem(sprintf(__("Vous aviez déjà le livre \"%s\" dans votre bibliothèque mais l'aviez supprimé. Il a été rajouté.", "s1b"), $bookInDb->getTitle()));
                 } else {
                     // Create userbook for connected user
                     $userBookBorrower = new UserBook();
                     $userBookBorrower->setUser($globalContext->getConnectedUser());
                     $userBookBorrower->setBook($bookInDb);
                     $userBookBorrower->setCreationDate(new \DateTime());
                     $userBookBorrower->setBorrowedOnce(true);
                     UserBookDao::getInstance()->add($userBookBorrower);
                     Flash::addItem(__("Le livre a été ajouté à votre bibliothèque.", "s1b"));
                 }
                 $lending = new Lending();
                 $lending->setBorrower_userbook($userBookBorrower);
                 $lending->setGuest($guest);
                 $lending->setCreationDate(new \DateTime());
                 $lending->setState(LendingState::ACTIV);
                 $lending->setStartDate(new \DateTime());
                 LendingDao::getInstance()->add($lending);
             }
             HTTPHelper::redirectToLibrary();
         } else {
             HTTPHelper::redirectToReferer();
         }
     } 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");
     }
 }
示例#28
0
 public function logOffAction()
 {
     try {
         $globalConfig = new Sb\Config\Model\Config();
         if (isset($_COOKIES) && array_key_exists("PHPSESSID", $_COOKIES)) {
             unset($_COOKIES["PHPSESSID"]);
         }
         // destruction du cookie de connexion PHPSESSID 3600 correspond à 60 min
         if (ini_get("session.use_cookies")) {
             $params = session_get_cookie_params();
             setcookie(session_name(), '', time() - 3600, $params["path"], $params["domain"], $params["secure"], $params["httponly"]);
         }
         $tmpLang = null;
         if (isset($_SESSION) && array_key_exists('WPLANG', $_SESSION)) {
             $tmpLang = $_SESSION['WPLANG'];
         }
         session_destroy();
         $_SESSION['WPLANG'] = $tmpLang;
         $facebookSvc = new FacebookSvc($globalConfig->getFacebookApiId(), $globalConfig->getFacebookSecret(), HTTPHelper::Link(Urls::USER_HOME), HTTPHelper::Link(Urls::LOGIN), HTTPHelper::Link(Urls::LOGIN));
         $faceBookUser = $facebookSvc->getUser();
         $facebookSvc->cleanUser();
         if ($faceBookUser) {
             HTTPHelper::redirect($facebookSvc->getFacebookLogOutUrl());
         }
         Flash::addItem(__("Déconnexion réussie", "s1b"));
         // Redirecting to login page
         HTTPHelper::redirect("");
     } 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");
     }
 }