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( |
|
56 | /** @noinspection PhpUnusedParameterInspection */ |
||
57 | $content, |
||
|
|||
58 | /** @noinspection PhpUnusedParameterInspection */ |
||
59 | array $configuration |
||
60 | ) { |
||
61 | 18 | $menuStructure = []; |
|
62 | 18 | $facetOptions = $this->cObj->data['facetOptions']; |
|
63 | |||
64 | 18 | foreach ($facetOptions as $facetOptionKey => $facetOption) { |
|
65 | // let's start with top level menu options |
||
66 | 18 | if (substr($facetOptionKey, 0, 1) == '0') { |
|
67 | $topLevelMenu = [ |
||
68 | 18 | 'title' => $this->getFacetOptionLabel($facetOptionKey, |
|
69 | 18 | $facetOption['numberOfResults']), |
|
70 | 18 | 'facetKey' => HierarchicalFacetRenderer::getLastPathSegmentFromHierarchicalFacetOption($facetOptionKey), |
|
71 | 18 | 'numberOfResults' => $facetOption['numberOfResults'], |
|
72 | 18 | '_OVERRIDE_HREF' => $facetOption['url'], |
|
73 | 18 | 'ITEM_STATE' => $facetOption['selected'] ? 'ACT' : 'NO', |
|
74 | 18 | '_PAGES_OVERLAY' => ($GLOBALS['TSFE']->sys_language_uid > 0) |
|
75 | 18 | ]; |
|
76 | |||
77 | 18 | list(, $mainMenuName) = explode('-', $facetOptionKey, 2); |
|
78 | |||
79 | // build sub menus recursively |
||
80 | 18 | $subMenu = $this->getSubMenu($facetOptions, $mainMenuName, 1); |
|
81 | 18 | if (!empty($subMenu)) { |
|
82 | 17 | $topLevelMenu['_SUB_MENU'] = $subMenu; |
|
83 | 17 | if ($topLevelMenu['ITEM_STATE'] == 'ACT') { |
|
84 | $topLevelMenu['ITEM_STATE'] = 'ACTIFSUB'; |
||
85 | } else { |
||
86 | 17 | $topLevelMenu['ITEM_STATE'] = 'IFSUB'; |
|
87 | } |
||
88 | 17 | } |
|
89 | |||
90 | 18 | $menuStructure[] = $topLevelMenu; |
|
91 | 18 | } |
|
92 | 18 | } |
|
93 | |||
94 | 18 | return $menuStructure; |
|
95 | } |
||
96 | |||
97 | /** |
||
98 | * Generates a facet option label from the given facet option. |
||
99 | * |
||
100 | * @param string $facetOptionKey A hierachical facet option path |
||
101 | * @param int $facetOptionResultCount |
||
102 | * @return string The label for the facet option consisting of the last part of the path and the options result count |
||
103 | */ |
||
104 | 18 | protected function getFacetOptionLabel( |
|
114 | |||
115 | /** |
||
116 | * Recursively builds a sub menu structure for the current menu. |
||
117 | * |
||
118 | * @param array $facetOptions Array of facet options |
||
119 | * @param string $menuName Name of the top level menu to build the sub menu structure for |
||
120 | * @param int $level The sub level depth |
||
121 | * @return array Returns an array sub menu structure if a sub menu exists, an empty array otherwise |
||
122 | */ |
||
123 | 18 | protected function getSubMenu(array $facetOptions, $menuName, $level) |
|
168 | } |
||
169 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.