function facetapi_facet_sorts_get in Facet API 6
Returns sorts enabled for a facet in a realm. Sort definitions are returned in the order specified in the configurations settings.
Parameters
$adapter: A FacetapiAdapter object.
$realm: An array containing the full realm definition.
$facet: An array containing the full realm definition.
Return value
An array of enabled sort definitions.
2 calls to facetapi_facet_sorts_get()
- FacetapiFacet::build in ./
facetapi.adapter.inc - Returns the facet's render array.
- facetapi_facet_settings_form in ./
facetapi.admin.inc - Returns settings for an individual facet that apply to a realm.
File
- ./
facetapi.module, line 654 - An abstracted facet API that can be used by various search backens.
Code
function facetapi_facet_sorts_get(FacetapiAdapter $adapter, array $realm, array $facet) {
// Gets active sorts.
$searcher = $adapter
->getSearcher();
$active_sorts = (array) facetapi_setting_get('sort', $searcher, $realm['name'], $facet['name']);
// Applies defaults if nothing is set.
$defaults = array();
if (empty($active_sorts)) {
$weight = -50;
foreach ($facet['default sorts'] as $sort) {
$active_sorts[$sort[0]] = $sort[0];
$defaults[$sort[0]] = array(
'weight' => $weight++,
'order' => $sort[1],
);
}
}
// Finalizes sort definitions with settings or defaults.
$sorts = array_intersect_key(facetapi_sorts_get(), array_filter($active_sorts));
foreach ($sorts as $sort_name => &$sort_info) {
if (empty($defaults)) {
$sort_info['weight'] = facetapi_setting_get('sort_weight', $searcher, $realm['name'], $facet['name'], $sort_name);
$sort_info['order'] = facetapi_setting_get('sort_order', $searcher, $realm['name'], $facet['name'], $sort_name);
}
else {
$sort_info['weight'] = $defaults[$sort_name]['weight'];
$sort_info['order'] = $defaults[$sort_name]['order'];
}
}
unset($sort_info);
uasort($sorts, 'facetapi_sort_weight');
return $sorts;
}