/**
  * Tests for formatDisplayText
  */
 public function testFormatDisplayText()
 {
     $this->assertEquals($this->helper->formatDisplayText('0/Sound/'), 'Sound');
     $this->assertEquals($this->helper->formatDisplayText('1/Sound/Noisy/'), 'Noisy');
     $this->assertEquals($this->helper->formatDisplayText('1/Sound/Noisy/', true), 'Sound/Noisy');
     $this->assertEquals($this->helper->formatDisplayText('1/Sound/Noisy/', true, ' - '), 'Sound - Noisy');
 }
 /**
  * Helper method for building hierarchical facets:
  * Convert facet list to a hierarchical array
  *
  * @param string    $facet     Facet name
  * @param array     $facetList Facet list
  * @param UrlHelper $urlHelper Query URL helper for building facet URLs
  *
  * @return array Facet hierarchy
  */
 public function buildFacetArray($facet, $facetList, $urlHelper = false)
 {
     $result = parent::buildFacetArray($facet, $facetList, $urlHelper);
     if ($urlHelper !== false) {
         // Recreate href's for any facet items that have children/ancestors
         // applied to remove them from the filters
         $result = $this->removeAncestorAndChildFilters($facet, $result);
     }
     return $result;
 }
 /**
  * Format a facet field according to the settings
  *
  * @param string $facet Facet field
  * @param string $value Facet value
  *
  * @return string Formatted field
  */
 protected function formatFacetField($facet, $value)
 {
     if (in_array($facet, $this->translatedFacets)) {
         $value = $this->translator->translate($value);
     }
     $allLevels = isset($this->displayStyles[$facet]) ? $this->displayStyles[$facet] == 'full' : false;
     $separator = isset($this->separators[$facet]) ? $this->separators[$facet] : '/';
     $value = $this->facetHelper->formatDisplayText($value, $allLevels, $separator);
     return $value;
 }
 /**
  * Format a facet field according to the settings
  *
  * @param string $facet Facet field
  * @param string $value Facet value
  * @param bool   $last  Whether this is the last of multiple values
  *
  * @return string Formatted field
  */
 protected function formatFacetField($facet, $value, $last)
 {
     $allLevels = isset($this->displayStyles[$facet]) ? $this->displayStyles[$facet] == 'full' : false;
     $separator = isset($this->separators[$facet]) ? $this->separators[$facet] : '/';
     $value = $this->facetHelper->formatDisplayText($value, $allLevels, $separator);
     // If full display style is used, clear out default display text for all but
     // the last value:
     if ($allLevels && !$last) {
         $value = new \VuFind\I18n\TranslatableString((string) $value, '');
     }
     return $value;
 }
Exemple #5
0
 /**
  * Get facet information from the search results.
  *
  * @return array
  * @throws \Exception
  */
 public function getFacetSet()
 {
     $facetSet = $this->results->getFacetList($this->mainFacets);
     foreach ($this->hierarchicalFacets as $hierarchicalFacet) {
         if (isset($facetSet[$hierarchicalFacet])) {
             if (!$this->hierarchicalFacetHelper) {
                 throw new \Exception(get_class($this) . ': hierarchical facet helper unavailable');
             }
             $facetArray = $this->hierarchicalFacetHelper->buildFacetArray($hierarchicalFacet, $facetSet[$hierarchicalFacet]['list']);
             $facetSet[$hierarchicalFacet]['list'] = $this->hierarchicalFacetHelper->flattenFacetHierarchy($facetArray);
         }
     }
     return $facetSet;
 }