Ejemplo n.º 1
0
 public function process()
 {
     global $interface;
     //Get Facet settings for processing display
     $interface->assign('checkboxFilters', $this->searchObject->getCheckboxFacets());
     //Get applied facets
     $filterList = $this->searchObject->getFilterList(true);
     foreach ($filterList as $facetKey => $facet) {
         //Remove any top facets since the removal links are displayed above results
         if (strpos($facet[0]['field'], 'availability_toggle') === 0) {
             unset($filterList[$facetKey]);
         }
     }
     $interface->assign('filterList', $filterList);
     //Process the side facet set to handle the Added In Last facet which we only want to be
     //visible if there is not a value selected for the facet (makes it single select
     $sideFacets = $this->searchObject->getFacetList($this->mainFacets);
     $searchLibrary = Library::getSearchLibrary();
     //Do additional processing of facets for non-genealogy searches
     if ($this->searchObject->getSearchType() != 'genealogy') {
         foreach ($sideFacets as $facetKey => $facet) {
             $facetSetting = $this->facetSettings[$facetKey];
             //Do special processing of facets
             if (preg_match('/time_since_added/i', $facetKey)) {
                 $timeSinceAddedFacet = $this->updateTimeSinceAddedFacet($facet);
                 $sideFacets[$facetKey] = $timeSinceAddedFacet;
             } elseif ($facetKey == 'rating_facet') {
                 $userRatingFacet = $this->updateUserRatingsFacet($facet);
                 $sideFacets[$facetKey] = $userRatingFacet;
             } elseif ($facetKey == 'available_at') {
                 //Mangle the availability facets
                 $oldFacetValues = $sideFacets['available_at']['list'];
                 ksort($oldFacetValues);
                 $filters = $this->searchObject->getFilterList();
                 //print_r($filters);
                 $appliedAvailability = array();
                 foreach ($filters as $appliedFilters) {
                     foreach ($appliedFilters as $filter) {
                         if ($filter['field'] == 'available_at') {
                             $appliedAvailability[$filter['value']] = $filter['removalUrl'];
                         }
                     }
                 }
                 $availableAtFacets = array();
                 foreach ($oldFacetValues as $facetKey2 => $facetInfo) {
                     if (strlen($facetKey2) > 1) {
                         $sortIndicator = substr($facetKey2, 0, 1);
                         if ($sortIndicator >= '1' && $sortIndicator <= '4') {
                             $availableAtFacets[$facetKey2] = $facetInfo;
                         }
                     }
                 }
                 $includeAnyLocationFacet = $this->searchObject->getFacetSetting("Availability", "includeAnyLocationFacet");
                 $includeAnyLocationFacet = $includeAnyLocationFacet == '' || $includeAnyLocationFacet == 'true';
                 if ($searchLibrary) {
                     $includeAnyLocationFacet = $searchLibrary->showAvailableAtAnyLocation;
                 }
                 //print_r ("includeAnyLocationFacet = $includeAnyLocationFacet");
                 if ($includeAnyLocationFacet) {
                     $anyLocationLabel = $this->searchObject->getFacetSetting("Availability", "anyLocationLabel");
                     //print_r ("anyLocationLabel = $anyLocationLabel");
                     $availableAtFacets['*'] = array('value' => '*', 'display' => $anyLocationLabel == '' ? "Any Marmot Location" : $anyLocationLabel, 'count' => $this->searchObject->getResultTotal() - (isset($oldFacetValues['']['count']) ? $oldFacetValues['']['count'] : 0), 'url' => $this->searchObject->renderLinkWithFilter('available_at:*'), 'isApplied' => array_key_exists('*', $appliedAvailability), 'removalUrl' => array_key_exists('*', $appliedAvailability) ? $appliedAvailability['*'] : null);
                 }
                 $sideFacets['available_at']['list'] = $availableAtFacets;
             } else {
                 //Do other handling of the display
                 if ($facetSetting->sortMode == 'alphabetically') {
                     asort($sideFacets[$facetKey]['list']);
                 }
                 if ($facetSetting->numEntriesToShowByDefault > 0) {
                     $sideFacets[$facetKey]['valuesToShow'] = $facetSetting->numEntriesToShowByDefault;
                 }
                 if ($facetSetting->showAsDropDown) {
                     $sideFacets[$facetKey]['showAsDropDown'] = $facetSetting->showAsDropDown;
                 }
                 if ($facetSetting->useMoreFacetPopup && count($sideFacets[$facetKey]['list']) > 12) {
                     $sideFacets[$facetKey]['showMoreFacetPopup'] = true;
                     $facetsList = $sideFacets[$facetKey]['list'];
                     $sideFacets[$facetKey]['list'] = array_slice($facetsList, 0, 5);
                     $sortedList = array();
                     foreach ($facetsList as $key => $value) {
                         $sortedList[strtolower($key)] = $value;
                     }
                     ksort($sortedList);
                     $sideFacets[$facetKey]['sortedList'] = $sortedList;
                 } else {
                     $sideFacets[$facetKey]['showMoreFacetPopup'] = false;
                 }
             }
             $sideFacets[$facetKey]['collapseByDefault'] = $facetSetting->collapseByDefault;
         }
     }
     $interface->assign('sideFacetSet', $sideFacets);
 }