示例#1
0
 public function prepare()
 {
     if ($this->allResults) {
         //Application des options de liste (tri, pagination, search, filering)
         $pageId = null;
         if ($this->listOptions) {
             // Sorting
             if ($this->listOptions->getSorting()) {
                 \Sb\Trace\Trace::addItem("Tri de la liste de livre ");
                 \Sb\Helpers\BooksHelper::sort($this->allResults, $this->listOptions->getSorting());
             }
             // Paging
             if ($this->listOptions->getPaging()) {
                 $pageId = $this->listOptions->getPaging()->getCurrentPageId();
             }
             // Searching
             if ($this->listOptions->getSearch()) {
                 $backedUpBooks = $this->allResults;
                 $tmpRes = \Sb\Helpers\BooksHelper::search($this->allResults, $this->listOptions->getSearch()->getValue());
                 if (!$tmpRes) {
                     \Sb\Flash\Flash::addItem(__("Aucun livre ne correspond à votre recherche.", "s1b"));
                     $this->allResults = $backedUpBooks;
                 }
             }
             // Filtering
             if ($this->listOptions->getFiltering()) {
                 \Sb\Helpers\BooksHelper::filter($this->allResults, $this->listOptions->getFiltering()->getValue(), $this->listOptions->getFiltering()->getType());
             }
         }
         $params = array('itemData' => $this->allResults, 'perPage' => $this->nbResultsPerPage, 'delta' => 8, 'append' => true, 'clearIfVoid' => false, 'urlVar' => 'pagenumber', 'useSessions' => false, 'closeSession' => false, 'mode' => 'Jumping', 'httpMethod' => 'GET');
         $pager = \Sb\Lists\Pager\Pager::factory($params);
         $pageData = $pager->getPageData($pageId);
         $this->pagerLinks = $pager->getLinks($pageId);
         $this->nbItemsTot = $pager->numItems();
         $this->shownResults = $pageData;
         $offSet = $pager->getOffsetByPageId($pageId);
         if ($offSet && count($offSet) >= 2) {
             $this->firstItemIdx = $offSet[0];
             $this->lastItemIdx = $offSet[1];
         }
         if ($this->shownResults) {
             $this->hasResults = true;
         }
     }
 }
示例#2
0
 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()));
         }
     }
 }
示例#3
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;
 }