/** * Add links to facets * * @param ResultSet $results */ public function addFacetLinks(ResultSet &$results) { // facets $facets = $results->getFacets(); if ($facets != "") { foreach ($facets->getGroups() as $group) { foreach ($group->getFacets() as $facet) { // existing url $url = $this->facetParams(); // now add the new one if ($facet->key != "") { // key defines a way to pass the (internal) value // in the param, while the name is the display value $url["facet." . $group->name . "." . urlencode($facet->key)] = $facet->name; } else { $url["facet." . $group->name] = $facet->name; } $facet->url = $this->request->url_for($url); } } } }
/** * Add links to facets * * @param ResultSet $results */ public function addFacetLinks(ResultSet &$results) { // facets $facets = $results->getFacets(); if ($facets != "") { $group_id = 0; foreach ($facets->getGroups() as $group) { // this is used for javascript selecting $group_id++; $facet_id = 0; // group identifiers $group->group_id = 'facet-' . $group_id; $group->param_name = 'facet.' . $group->name; // link to multi-select facet page $group_params = $this->query->getAllSearchParams(); $group_params['controller'] = $this->request->getParam('controller'); $group_params['action'] = 'facet'; $group_params['group'] = $group->param_name; $group->url = $this->request->url_for($group_params); // print_r($group->getFacets()); foreach ($group->getFacets() as $facet) { $facet_id++; $param_name = Query::getParamFromParts($group->name, urlencode($facet->key), $facet->is_excluded); // link $url = $this->facetParams(); if ($facet->is_excluded == true) { // selecting this option removes our exclude param foreach ($url as $key => $value) { if ($key == $param_name) { // if we have multiple values, only remove the matching one if (is_array($value)) { $new_array = array(); foreach ($value as $entry) { if ($entry != $facet->name) { $new_array[] = $entry; } } $url[$key] = $new_array; } else { $url[$key] = ''; } } } } else { // selecting this option adds our param $url[$param_name] = $facet->name; } $facet->url = $this->request->url_for($url); // facet identifiers $facet->input_id = $group->group_id . '-' . $facet_id; // add the name of the param as well $facet->param_name = $param_name; // see if this facet is selected (for multi-select facets) if ($this->request->hasParamValue($param_name, $facet->name)) { $facet->selected = true; } // exclude facet param $facet->param_exclude = str_replace('facet.', 'facet.remove.', $param_name); } } } }