VuFind API Documentation

HierarchicalFacetHelper
in package
implements HierarchicalFacetHelperInterface, TranslatorAwareInterface, HasSorterInterface Uses TranslatorAwareTrait, HasSorterTrait

Functions for manipulating facets

Tags
category

VuFind

author

Ere Maijala ere.maijala@helsinki.fi

author

Juha Luoma juha.luoma@helsinki.fi

license

http://opensource.org/licenses/gpl-2.0.php GNU General Public License

link

Main Site

Interfaces, Classes, Traits and Enums

HierarchicalFacetHelperInterface
Hierarchical facet helper interface
TranslatorAwareInterface
Lightweight translator aware marker interface (used as an alternative to \Laminas\I18n\Translator\TranslatorAwareInterface, which requires an excessive number of methods to be implemented).
HasSorterInterface
Interface SortingInterface

Table of Contents

$sorter  : SorterInterface|null
Sorter
$translator  : TranslatorInterface
Translator
$viewRenderer  : RendererInterface
View renderer
buildFacetArray()  : array<string|int, mixed>
Helper method for building hierarchical facets: Convert facet list to a hierarchical array
filterFacets()  : array<string|int, mixed>
Filter hierarchical facets
flattenFacetHierarchy()  : array<string|int, mixed>
Flatten a hierarchical facet list to a simple array
formatDisplayText()  : TranslatableString
Format a facet display text for displaying
getFilterStringParts()  : array<string|int, mixed>
Format a filter string in parts suitable for displaying or translation
getSorter()  : SorterInterface
Get the sorter
getTranslator()  : TranslatorInterface
Get translator object.
getTranslatorLocale()  : string
Get the locale from the translator.
isDeepestFacetLevel()  : bool
Check if the given value is the deepest level in the facet list.
setSorter()  : void
Set the sorter
setTranslator()  : TranslatorAwareInterface
Set a translator
setViewRenderer()  : void
Set view renderer
sortFacetList()  : void
Helper method for building hierarchical facets: Sort a facet list according to the given sort order
translate()  : string
Translate a string (or string-castable object)
translateWithPrefix()  : string
Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.
createFacetItem()  : array<string|int, mixed>
Create an item for the hierarchical facet array
extractTextDomain()  : array<string|int, mixed>
Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.
getDebugTranslation()  : string
Build a debug-mode translation
sanitizeTranslationKey()  : string
Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.
translateString()  : string
Get translation for a string
updateAppliedChildrenStatus()  : bool
Update 'opened' of all facet items

Properties

Methods

buildFacetArray()

Helper method for building hierarchical facets: Convert facet list to a hierarchical array

public buildFacetArray(string $facet, array<string|int, mixed> $facetList[, UrlHelper $urlHelper = false ][, bool $escape = true ]) : array<string|int, mixed>
Parameters
$facet : string

Facet name

$facetList : array<string|int, mixed>

Facet list

$urlHelper : UrlHelper = false

Query URL helper for building facet URLs

$escape : bool = true

Whether to escape URLs

Tags
see
http://blog.tekerson.com/2009/03/03/

converting-a-flat-array-with-parent-ids-to-a-nested-tree/ Based on this example

Return values
array<string|int, mixed>

Facet hierarchy

filterFacets()

Filter hierarchical facets

public filterFacets(string $name, array<string|int, mixed> $facets, Options $options) : array<string|int, mixed>
Parameters
$name : string

Facet name

$facets : array<string|int, mixed>

Facet list

$options : Options

Options

Return values
array<string|int, mixed>

flattenFacetHierarchy()

Flatten a hierarchical facet list to a simple array

public flattenFacetHierarchy(array<string|int, mixed> $facetList) : array<string|int, mixed>
Parameters
$facetList : array<string|int, mixed>

Facet list

Return values
array<string|int, mixed>

Simple array of facets

formatDisplayText()

Format a facet display text for displaying

public formatDisplayText(string $displayText[, bool $allLevels = false ][, string $separator = '/' ][, string|false $domain = false ]) : TranslatableString
Parameters
$displayText : string

Display text

$allLevels : bool = false

Whether to display all levels or only the current one

$separator : string = '/'

Separator string displayed between levels

$domain : string|false = false

Translation domain for default translations of a multilevel string or false to omit translation

Return values
TranslatableString

Formatted text

getFilterStringParts()

Format a filter string in parts suitable for displaying or translation

public getFilterStringParts(string $filter) : array<string|int, mixed>
Parameters
$filter : string

Filter value

Return values
array<string|int, mixed>

getTranslator()

Get translator object.

public getTranslator() : TranslatorInterface
Return values
TranslatorInterface

getTranslatorLocale()

Get the locale from the translator.

public getTranslatorLocale([string $default = 'en' ]) : string
Parameters
$default : string = 'en'

Default to use if translator absent.

Return values
string

isDeepestFacetLevel()

Check if the given value is the deepest level in the facet list.

public isDeepestFacetLevel(array<string|int, mixed> $facetList, string $value) : bool

Takes into account lists with multiple top levels.

Parameters
$facetList : array<string|int, mixed>

Facet list

$value : string

Facet value

Return values
bool

setViewRenderer()

Set view renderer

public setViewRenderer(RendererInterface $renderer) : void
Parameters
$renderer : RendererInterface

View renderer

Return values
void

sortFacetList()

Helper method for building hierarchical facets: Sort a facet list according to the given sort order

public sortFacetList(array<string|int, mixed> &$facetList[, bool|string $order = null ]) : void
Parameters
$facetList : array<string|int, mixed>

Facet list returned from Solr

$order : bool|string = null

Sort order:

  • true|top sort top level alphabetically and the rest by count
  • false|all sort all levels alphabetically
  • count sort all levels by count
Return values
void

translate()

Translate a string (or string-castable object)

public translate(string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

translateWithPrefix()

Translate a string (or string-castable object) using a prefix, or without the prefix if a prefixed translation is not found.

public translateWithPrefix(string $prefix, string|object|array<string|int, mixed> $target[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, bool $useIcuFormatter = false ][, array<string|int, string> $fallbackDomains = [] ]) : string
Parameters
$prefix : string

Translation key prefix

$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

$fallbackDomains : array<string|int, string> = []

Text domains to check if no match is found in the domain specified in $target

Return values
string

createFacetItem()

Create an item for the hierarchical facet array

protected createFacetItem(string $facet, array<string|int, mixed> $item, UrlQueryHelper $urlHelper[, bool $escape = true ]) : array<string|int, mixed>
Parameters
$facet : string

Facet name

$item : array<string|int, mixed>

Facet item received from Solr

$urlHelper : UrlQueryHelper

UrlQueryHelper for creating facet URLs

$escape : bool = true

Whether to escape URLs

Return values
array<string|int, mixed>

Facet item

extractTextDomain()

Given a translation string with or without a text domain, return an array with the raw string and the text domain separated.

protected extractTextDomain(string|object|array<string|int, mixed> $target) : array<string|int, mixed>
Parameters
$target : string|object|array<string|int, mixed>

String to translate or an array of text domain and string to translate

Return values
array<string|int, mixed>

getDebugTranslation()

Build a debug-mode translation

protected getDebugTranslation(string $domain, string $str, array<string|int, mixed> $tokens) : string
Parameters
$domain : string

Text domain

$str : string

String to translate

$tokens : array<string|int, mixed>

Tokens to inject into the translated string

Return values
string

sanitizeTranslationKey()

Make sure there are not any illegal characters in the translation key that might prevent successful lookup in language files.

protected sanitizeTranslationKey(string $key) : string
Parameters
$key : string

Key to sanitize

Return values
string

Sanitized key

translateString()

Get translation for a string

protected translateString(string $rawStr[, array<string|int, mixed> $tokens = [] ][, string $default = null ][, string $domain = 'default' ][, bool $useIcuFormatter = false ]) : string
Parameters
$rawStr : string

String to translate

$tokens : array<string|int, mixed> = []

Tokens to inject into the translated string

$default : string = null

Default value to use if no translation is found (null for no default).

$domain : string = 'default'

Text domain (omit for default)

$useIcuFormatter : bool = false

Should we use an ICU message formatter instead of the default behavior?

Return values
string

updateAppliedChildrenStatus()

Update 'opened' of all facet items

protected updateAppliedChildrenStatus(array<string|int, mixed> $list) : bool
Parameters
$list : array<string|int, mixed>

Facet list

Return values
bool

Whether any items are applied (for recursive calls)

Search results