コード例 #1
0
ファイル: BookList.php プロジェクト: berliozd/cherbouquin
 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
ファイル: BookSearch.php プロジェクト: berliozd/cherbouquin
 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()));
         }
     }
 }