Exemple #1
0
 private function getBrowseCategoryResults($pageToLoad = 1)
 {
     $browseMode = $this->setBrowseMode();
     if ($pageToLoad == 1 && !isset($_REQUEST['reload'])) {
         // only first page is cached
         global $memCache, $solrScope;
         $key = 'browse_category_' . $this->textId . '_' . $solrScope . '_' . $browseMode;
         $browseCategoryInfo = $memCache->get($key);
         if ($browseCategoryInfo != false) {
             return $browseCategoryInfo;
         }
     }
     $result = array('result' => false);
     $browseCategory = $this->getBrowseCategory();
     if ($browseCategory) {
         global $interface;
         $interface->assign('browseCategoryId', $this->textId);
         $result['result'] = true;
         $result['textId'] = $browseCategory->textId;
         $result['label'] = $browseCategory->label;
         //$result['description'] = $browseCategory->description; // the description is not used anywhere on front end. plb 1-2-2015
         // User List Browse Category //
         if ($browseCategory->sourceListId != null && $browseCategory->sourceListId > 0) {
             require_once ROOT_DIR . '/sys/LocalEnrichment/UserList.php';
             $sourceList = new UserList();
             $sourceList->id = $browseCategory->sourceListId;
             if ($sourceList->find(true)) {
                 $records = $sourceList->getBrowseRecords(($pageToLoad - 1) * self::ITEMS_PER_PAGE, self::ITEMS_PER_PAGE);
             } else {
                 $records = array();
             }
             $result['searchUrl'] = '/MyAccount/MyList/' . $browseCategory->sourceListId;
             // Search Browse Category //
         } else {
             $this->searchObject = SearchObjectFactory::initSearchObject();
             $defaultFilterInfo = $browseCategory->defaultFilter;
             $defaultFilters = preg_split('/[\\r\\n,;]+/', $defaultFilterInfo);
             foreach ($defaultFilters as $filter) {
                 $this->searchObject->addFilter(trim($filter));
             }
             //Set Sorting, this is actually slightly mangled from the category to Solr
             $this->searchObject->setSort($browseCategory->getSolrSort());
             if ($browseCategory->searchTerm != '') {
                 $this->searchObject->setSearchTerm($browseCategory->searchTerm);
             }
             //Get titles for the list
             $this->searchObject->clearFacets();
             $this->searchObject->disableSpelling();
             $this->searchObject->disableLogging();
             $this->searchObject->setLimit(self::ITEMS_PER_PAGE);
             $this->searchObject->setPage($pageToLoad);
             $this->searchObject->processSearch();
             $records = $this->searchObject->getBrowseRecordHTML();
             $result['searchUrl'] = $this->searchObject->renderSearchUrl();
             //TODO: Check if last page
             // Shutdown the search object
             $this->searchObject->close();
         }
         if (count($records) == 0) {
             $records[] = $interface->fetch('Browse/noResults.tpl');
         }
         $result['records'] = implode('', $records);
         $result['numRecords'] = count($records);
     }
     // Store first page of browse category in the MemCache
     if ($pageToLoad == 1) {
         global $memCache, $configArray, $solrScope;
         $key = 'browse_category_' . $this->textId . '_' . $solrScope . '_' . $browseMode;
         $memCache->add($key, $result, 0, $configArray['Caching']['browse_category_info']);
     }
     return $result;
 }