/** * Recursively builds a sub menu structure for the current menu. * * @param array $facetOptions Array of facet options * @param string $menuName Name of the top level menu to build the sub menu structure for * @param integer $level The sub level depth * @return array Returns an array sub menu structure if a sub menu exists, an empty array otherwise */ protected function getSubMenu(array $facetOptions, $menuName, $level) { $menu = array(); $subMenuEntryPrefix = $level . '-' . $menuName . '/'; foreach ($facetOptions as $facetOptionKey => $facetOption) { // find the sub menu items for the current menu if (GeneralUtility::isFirstPartOfStr($facetOptionKey, $subMenuEntryPrefix)) { $currentMenu = array('title' => $this->getFacetOptionLabel($facetOptionKey, $facetOption['numberOfResults']), 'facetKey' => HierarchicalFacetRenderer::getLastPathSegmentFromHierarchicalFacetOption($facetOptionKey), 'numberOfResults' => $facetOption['numberOfResults'], '_OVERRIDE_HREF' => $facetOption['url'], 'ITEM_STATE' => $facetOption['selected'] ? 'ACT' : 'NO', '_PAGES_OVERLAY' => $GLOBALS['TSFE']->sys_language_uid > 0); $lastPathSegment = HierarchicalFacetRenderer::getLastPathSegmentFromHierarchicalFacetOption($facetOptionKey); // move one level down (recursion) $subMenu = $this->getSubMenu($facetOptions, $menuName . '/' . $lastPathSegment, $level + 1); if (!empty($subMenu)) { $currentMenu['_SUB_MENU'] = $subMenu; if ($currentMenu['ITEM_STATE'] == 'ACT') { $currentMenu['ITEM_STATE'] = 'ACTIFSUB'; } else { $currentMenu['ITEM_STATE'] = 'IFSUB'; } } $menu[] = $currentMenu; } } // return one level up return $menu; }
/** * Generates a facet option label from the given facet option. * * @param string $facetOptionKey A hierachical facet option path * @param integer $facetOptionResultCount * @return string The label for the facet option consisting of the last part of the path and the options result count */ protected function getFacetOptionLabel($facetOptionKey, $facetOptionResultCount) { // use the last path segment and the result count to build the label $lastPathSegment = HierarchicalFacetRenderer::getLastPathSegmentFromHierarchicalFacetOption($facetOptionKey); $facetOptionLabel = $lastPathSegment . ' (' . $facetOptionResultCount . ')'; return $facetOptionLabel; }