public function isValid($value) { $valid = true; $this->_setValue($value); $result = BookDao::getInstance()->get($value); if (!$result) { $valid = false; $this->_error(self::BOOK_NO_EXISTS); } return $valid; }
public function get($bookId) { try { $key = self::BOOK_PAGE . "_id_" . $bookId; $result = $this->getData($key); if ($result === false) { $result = new BookPage(); /* @var Book $book */ $book = BookDao::getInstance()->get($bookId); if (!$book) { return null; } $result->setBook($book); $booksAlsoLiked = BookSvc::getInstance()->getBooksAlsoLiked($bookId, false); $result->setBooksAlsoLiked($booksAlsoLiked); $booksWithSameAuthor = BookSvc::getInstance()->getBooksWithSameContributors($bookId, false); $result->setBooksWithSameAuthor($booksWithSameAuthor); $booksWithSameTags = BookSvc::getInstance()->getBooksWithSameTags($bookId, false); $result->setBooksWithSameTags($booksWithSameTags); $lastlyReadUserbooks = UserBookSvc::getInstance()->getLastlyReadUserbookByBookId($bookId, 5, false); $result->setLastlyReadUserbooks($lastlyReadUserbooks); $reviewedUserBooks = $this->getReviewedUserBooks($book->getNotDeletedUserBooks()); $result->setReviewedUserBooks($reviewedUserBooks); $pressReviews = $this->getBookPressReviews($book); $result->setPressReviews($pressReviews); $relatedChronicles = $this->getChroniclesRelativeToBook($book); $result->setRelatedChronicles($relatedChronicles); $criteria = array("type" => array(false, "=", PressReviewTypes::VIDEO), "book" => array(true, "=", $book), "is_validated" => array(false, "=", 1)); $videoPressReviews = PressReviewSvc::getInstance()->getList($criteria, 1, false); if ($videoPressReviews) { $video = $videoPressReviews[0]; $result->setVideoPressReview($video); } $this->setData($key, $result); } return $result; } catch (\Exception $e) { $this->logException(get_class(), __FUNCTION__, $e); } }
private function searchData($searchTerm, $nbResultsToShow, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested) { if ($searchTerm) { $searchTerm = trim($searchTerm); // faire la recherche dans la base de donnée $this->allResults = \Sb\Db\Dao\BookDao::getInstance()->getListByKeyword($searchTerm); try { $amazonResults = null; // si pas de résultat ou nb de resultats < à ce que l'on souhaite afficher, faire la recherche Amazon if (!$this->allResults || count($this->allResults) < $nbResultsToShow) { // Requesting amazon FR first $amazonResults = $this->getAmazonResults($searchTerm, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested, 'FR'); // Requesting amazon US if (!$amazonResults) { $amazonResults = $this->getAmazonResults($searchTerm, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested, 'US'); } } // si des résultats ont été trouvés avec Amazon // si des résultats avaient été trouvés dans la base // ==> ils doivent être mergés ensemble if ($this->allResults && $amazonResults) { $allResultsKeys = array_map(array(&$this, "extractKey"), $this->allResults); $this->allResults = array_combine($allResultsKeys, $this->allResults); // Adding the books not present in sql found on amazon after the books that are already in sql $this->allResults = $this->allResults + array_diff_key($amazonResults, $this->allResults); } elseif ($amazonResults) { $this->allResults = $amazonResults; } // Sort books by publishing date desc $sorting = new Sorting(); $sorting->setDirection(EntityHelper::DESC); $sorting->setField('publishing_date'); BooksHelper::sort($this->allResults, $sorting); } catch (\Exception $exc) { \Sb\Trace\Trace::addItem(sprintf("Une erreur s'est produite lors de l'appel à l'api amazon : %s", $exc->getMessage())); } } }
public function addFromBookId($id, \Sb\Db\Model\User $user, \Sb\Config\Model\Config $config) { $book = BookDao::getInstance()->get($id); return $this->addUserBook($book, $user, $config); }
private function getLastRated($nbBooks) { try { $nbBooksMax = 25; // Number of books 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. $dataKey = self::LASTY_RATED . "_m_" . $nbBooksMax; $result = $this->getData($dataKey); if ($result === false) { $result = BookDao::getInstance()->getListLastRated($nbBooksMax); // Make the result richer by adding the contributors $result = $this->getRicherBookResult($result); $this->setData($dataKey, $result); } return array_slice($result, 0, $nbBooks); } catch (\Exception $exc) { $this->logException(get_class(), __FUNCTION__, $exc); } }
private function setChronicleData(ChronicleForm $form, Chronicle $chronicle) { $globalContext = new \Sb\Context\Model\Context(); $book = BookDao::getInstance()->get($form->getChronicleBookId()); $chronicle->setBook($book); $group = GroupDao::getInstance()->get($form->getChronicleGroupId()); $chronicle->setGroup($group); if ($form->getChronicleImage()) { $fullImageName = $this->getImageUrl($form->getChronicleGroupId()) . "/" . $form->getChronicleImage(); $chronicle->setImage($fullImageName); } $chronicle->setIs_validated(true); $chronicle->setKeywords($form->getChronicleKeywords()); $chronicle->setLink($form->getChronicleLink()); $tag = TagDao::getInstance()->get($form->getChronicleTagId()); $chronicle->setTag($tag); $chronicle->setText($form->getChronicleText()); $chronicle->setTitle($form->getChronicleTitle()); $chronicle->setType_id($form->getChronicleType()); $chronicle->setUser($globalContext->getConnectedUser()); $chronicle->setLink_type($form->getChronicleLinkType()); }
/** * 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"); } }
/** * Return a chronicle from a user id and a book id * * @param unknown $userId * @param unknown $bookId * @param string $useCache * @return \Sb\Db\Dao\Ambigous|NULL */ public function getChronicle($userId, $bookId, $useCache = true) { try { $results = null; if ($useCache) { $key = self::CHRONICLE_FROM_USER_BOOK . "_uid_" . $userId . "_bid_" . $bookId; $result = $this->getData($key); } if (!isset($results) || $results === false) { $criteria["user"] = array(true, "=", UserDao::getInstance()->get($userId)); $criteria["book"] = array(true, "=", BookDao::getInstance()->get($bookId)); $result = $this->getDao()->getList($criteria, array('id' => 'DESC'), 1); } if ($useCache) { $this->setData($key, $results); } if (is_array($result) && count($result) > 0) { return $result[0]; } return null; } catch (\Exception $e) { $this->logException(get_class(), __FUNCTION__, $e); } return $results; }
private function getBooksInBase($isbns) { $bookDao = \Sb\Db\Dao\BookDao::getInstance(); return $bookDao->getOneByCodes($isbns, null, null); }
private function getBook($bookId) { if (!$bookId) { Flash::addItem(__("Vous devez sélectionner un livre.", "s1b")); HTTPHelper::redirectToReferer(); } $book = BookDao::getInstance()->get($bookId); if (!$book) { Flash::addItem(__("Le livre n'existe pas.", "s1b")); HTTPHelper::redirectToReferer(); } return $book; }