private function loadResults($fullCacheKey, $doSearch, $searchTerm, $nbResultsToShow, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested) { $cache = \Sb\Cache\ZendFileCache::getInstance(); if ($doSearch) { $cache->remove($fullCacheKey); // Exécution de la recherche pour le premier affichage de la page $this->searchData($searchTerm, $nbResultsToShow, $amazonApiKey, $amazonSecretKey, $amazonAssociateTag, $amazonNumberOfPageRequested); if ($this->allResults) { $cache->save($this->allResults, $fullCacheKey); } } else { // Pagination: Tentative de récupération des données depuis le cache $this->allResults = $cache->load($fullCacheKey); } }
public function addFromPost(\Sb\Db\Model\User $user, \Sb\Config\Model\Config $config) { $bookForm = new \Sb\Form\Book($_POST); // Testing if book can be found in db by id $book = null; if ($bookForm->getId()) { $book = BookDao::getInstance()->get($bookForm->getId()); } // Testing if book can be found in db by isbn10, isbn13, asin if (!$book) { $book = BookDao::getInstance()->getOneByCodes($bookForm->getISBN10(), $bookForm->getISBN13(), $bookForm->getASIN()); } // Testing if we need to add the book first if (!$book) { // Getting book from POST $book = new \Sb\Db\Model\Book(); \Sb\Db\Mapping\BookMapper::map($book, $_POST, "book_"); // Completing Book data by calling google in needed if (!$book->IsComplete()) { \Sb\Helpers\BookHelper::completeInfos($book); } $book->setCreationDate(new \DateTime()); $book->setLastModificationDate(new \DateTime()); BookDao::getInstance()->add($book); // Updating the book in cache to make it available for adding a userbook on form (borrowfromfriends, etc...) \Sb\Cache\ZendFileCache::getInstance()->save($book, \Sb\Entity\Constants::BOOK_TO_ADD_PREFIX . session_id()); } if ($book) { return $this->addUserBook($book, $user, $config); } else { Trace::addItem("Erreur lors de l'ajout d'un livre"); return __("Une erreur s'est produite lors de l'ajout du libre", "s1b"); } }
protected function __construct($dao, $serviceName) { $this->cache = \Sb\Cache\ZendFileCache::getInstance(); $this->dao = $dao; $this->serviceName = $serviceName; }
protected function __construct($serviceName) { $this->cache = ZendFileCache::getInstance(); $this->serviceName = $serviceName; }
/** * Save authors first letters and title first letters * @param $books * @param $fullKey */ private function setListMetaData($books, $fullKey) { if ($books) { // Save authors first letters in cache $authorsFirstLetter = array_unique(array_map(array(&$this, "firstLetterFromAuthor"), $books)); usort($authorsFirstLetter, array(&$this, "compareLetters")); ZendFileCache::getInstance()->save($authorsFirstLetter, $fullKey . self::LIST_AUTHORS_FIRST_LETTER_SUFFIX); // Save titles first letters in cache $titlesFirstLetter = array_unique(array_map(array(&$this, "firstLetterFromTitle"), $books)); usort($titlesFirstLetter, array(&$this, "compareLetters")); ZendFileCache::getInstance()->save($titlesFirstLetter, $fullKey . self::LIST_TITLES_FIRST_LETTER_SUFFIX); } }
public function borrowFromFriendsAction() { try { $globalContext = new \Sb\Context\Model\Context(); $bookIdInIQS = ArrayHelper::getSafeFromArray($_GET, "bid", null); if ($bookIdInIQS) { $book = BookDao::getInstance()->get($bookIdInIQS); } else { // Get Book to add from cache $book = ZendFileCache::getInstance()->load(Constants::BOOK_TO_ADD_PREFIX . session_id()); } if ($book) { $userBookInDb = UserBookDao::getInstance()->getByBookIdAndUserId($globalContext->getConnectedUser()->getId(), $book->getId()); if ($userBookInDb && !$userBookInDb->getIs_deleted()) { Flash::addItem(__("Vous avez déjà ce livre dans votre bibliothèque.", "s1b")); HTTPHelper::redirectToLibrary(); } else { // Checking if a friend has this book in his library $userBookDao = UserBookDao::getInstance(); $user = $globalContext->getConnectedUser(); $friends = $user->getAcceptedFriends(); if ($friends) { $userBooks = $userBookDao->getBookInFriendsUserBook($book->getId(), $globalContext->getConnectedUser()->getId()); if ($userBooks) { $this->view->friendUserBooks = array_filter($userBooks, array(&$this, "IsBorrowable")); } } $bookView = new \Sb\View\Book($book, false, false, true, null, null, null, false); $this->view->book = $bookView->get(); } } else { HTTPHelper::redirectToHome(); } } 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"); } }