Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
n/a
0 / 0
n/a
0 / 0
CRAP
n/a
0 / 0
1<?php
2
3/**
4 * Hierarchical facet helper interface
5 *
6 * Copyright (C) The National Library of Finland 2022.
7 *
8 * PHP version 8
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2,
12 * as published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
22 *
23 * @category VuFind
24 * @package  Search_Base
25 * @author   Ere Maijala <ere.maijala@helsinki.fi>
26 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
27 * @link     https://vufind.org Main Page
28 */
29
30namespace VuFind\Search\Base;
31
32/**
33 * Hierarchical facet helper interface
34 *
35 * @category VuFind
36 * @package  Search_Base
37 * @author   Ere Maijala <ere.maijala@helsinki.fi>
38 * @license  http://opensource.org/licenses/gpl-2.0.php GNU General Public License
39 * @link     https://vufind.org Main Page
40 */
41interface HierarchicalFacetHelperInterface
42{
43    /**
44     * Helper method for building hierarchical facets:
45     * Sort a facet list according to the given sort order
46     *
47     * @param array          $facetList Facet list returned from Solr
48     * @param boolean|string $order     Sort order:
49     * - true|top  sort top level alphabetically and the rest by count
50     * - false|all sort all levels alphabetically
51     * - count     sort all levels by count
52     *
53     * @return void
54     */
55    public function sortFacetList(&$facetList, $order = null);
56
57    /**
58     * Helper method for building hierarchical facets:
59     * Convert facet list to a hierarchical array
60     *
61     * @param string    $facet     Facet name
62     * @param array     $facetList Facet list
63     * @param UrlHelper $urlHelper Query URL helper for building facet URLs
64     * @param bool      $escape    Whether to escape URLs
65     *
66     * @return array Facet hierarchy
67     *
68     * @see http://blog.tekerson.com/2009/03/03/
69     * converting-a-flat-array-with-parent-ids-to-a-nested-tree/
70     * Based on this example
71     */
72    public function buildFacetArray(
73        $facet,
74        $facetList,
75        $urlHelper = false,
76        $escape = true
77    );
78
79    /**
80     * Flatten a hierarchical facet list to a simple array
81     *
82     * @param array $facetList Facet list
83     *
84     * @return array Simple array of facets
85     */
86    public function flattenFacetHierarchy($facetList);
87
88    /**
89     * Format a facet display text for displaying
90     *
91     * @param string       $displayText Display text
92     * @param bool         $allLevels   Whether to display all levels or only the
93     * current one
94     * @param string       $separator   Separator string displayed between levels
95     * @param string|false $domain      Translation domain for default translations
96     * of a multilevel string or false to omit translation
97     *
98     * @return TranslatableString Formatted text
99     */
100    public function formatDisplayText(
101        $displayText,
102        $allLevels = false,
103        $separator = '/',
104        $domain = false
105    );
106
107    /**
108     * Format a filter string in parts suitable for displaying or translation
109     *
110     * @param string $filter Filter value
111     *
112     * @return array
113     */
114    public function getFilterStringParts($filter);
115
116    /**
117     * Check if the given value is the deepest level in the facet list.
118     *
119     * Takes into account lists with multiple top levels.
120     *
121     * @param array  $facetList Facet list
122     * @param string $value     Facet value
123     *
124     * @return bool
125     */
126    public function isDeepestFacetLevel($facetList, $value);
127}