1 | <?php |
||
35 | class HierarchicalFacetHelper |
||
36 | { |
||
37 | |||
38 | /** |
||
39 | * Parent content object, set when called by ContentObjectRenderer->callUserFunction() |
||
40 | * |
||
41 | * @var ContentObjectRenderer |
||
42 | */ |
||
43 | public $cObj; |
||
44 | |||
45 | /** |
||
46 | * Builds a menu structure usable with HMENU and returns it. |
||
47 | * |
||
48 | * Starts with the top level menu entries and hands the sub menu building |
||
49 | * off to a recursive method. |
||
50 | * |
||
51 | * @param string $content |
||
52 | * @param array $configuration |
||
53 | * @return array A menu structure usable for HMENU |
||
54 | */ |
||
55 | 18 | public function getMenuStructure($content, array $configuration) |
|
56 | { |
||
57 | 18 | $menuStructure = []; |
|
58 | 18 | $facetOptions = $this->cObj->data['facetOptions']; |
|
59 | |||
60 | 18 | foreach ($facetOptions as $facetOptionKey => $facetOption) { |
|
61 | // let's start with top level menu options |
||
62 | 18 | if (substr($facetOptionKey, 0, 1) == '0') { |
|
63 | $topLevelMenu = [ |
||
64 | 18 | 'title' => $this->getFacetOptionLabel($facetOptionKey, |
|
65 | 18 | $facetOption['numberOfResults']), |
|
66 | 18 | 'facetKey' => HierarchicalFacetRenderer::getLastPathSegmentFromHierarchicalFacetOption($facetOptionKey), |
|
67 | 18 | 'numberOfResults' => $facetOption['numberOfResults'], |
|
68 | 18 | '_OVERRIDE_HREF' => $facetOption['url'], |
|
69 | 18 | 'ITEM_STATE' => $facetOption['selected'] ? 'ACT' : 'NO', |
|
70 | 18 | '_PAGES_OVERLAY' => ($GLOBALS['TSFE']->sys_language_uid > 0) |
|
71 | ]; |
||
72 | |||
73 | 18 | list(, $mainMenuName) = explode('-', $facetOptionKey, 2); |
|
74 | |||
75 | // build sub menus recursively |
||
76 | 18 | $subMenu = $this->getSubMenu($facetOptions, $mainMenuName, 1); |
|
77 | 18 | if (!empty($subMenu)) { |
|
78 | 17 | $topLevelMenu['_SUB_MENU'] = $subMenu; |
|
79 | 17 | if ($topLevelMenu['ITEM_STATE'] == 'ACT') { |
|
80 | $topLevelMenu['ITEM_STATE'] = 'ACTIFSUB'; |
||
81 | } else { |
||
82 | 17 | $topLevelMenu['ITEM_STATE'] = 'IFSUB'; |
|
83 | } |
||
84 | } |
||
85 | |||
86 | 18 | $menuStructure[] = $topLevelMenu; |
|
87 | } |
||
88 | } |
||
89 | |||
90 | 18 | return $menuStructure; |
|
91 | } |
||
92 | |||
93 | /** |
||
94 | * Generates a facet option label from the given facet option. |
||
95 | * |
||
96 | * @param string $facetOptionKey A hierachical facet option path |
||
97 | * @param int $facetOptionResultCount |
||
98 | * @return string The label for the facet option consisting of the last part of the path and the options result count |
||
99 | */ |
||
100 | 18 | protected function getFacetOptionLabel( |
|
110 | |||
111 | /** |
||
112 | * Recursively builds a sub menu structure for the current menu. |
||
113 | * |
||
114 | * @param array $facetOptions Array of facet options |
||
115 | * @param string $menuName Name of the top level menu to build the sub menu structure for |
||
116 | * @param int $level The sub level depth |
||
117 | * @return array Returns an array sub menu structure if a sub menu exists, an empty array otherwise |
||
118 | */ |
||
119 | 18 | protected function getSubMenu(array $facetOptions, $menuName, $level) |
|
164 | } |
||
165 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.