function facetapi_enabled_facets_get in Facet API 6
Returns facets enabled in a given realm. If the realm name is NULL, all facets that are enabled in at least one realm will be returned.
Parameters
$searcher: A string containing the machine readable name of the searcher module.
$realm_name: A string containing the realm. Passing NULL will check all realms and return the facet if it is enabled in at least one realm.
$reset: A boolean flagging whether the static should be reset.
Return value
An array of facets.
13 calls to facetapi_enabled_facets_get()
- facetapi_apachesolr_apachesolr_prepare_query in contrib/
facetapi_apachesolr/ facetapi_apachesolr.module - Implementation of hook_apachesolr_prepare_query().
- facetapi_apachesolr_date_range in contrib/
facetapi_apachesolr/ facetapi_apachesolr.module - Gets the range of dates we are using.
- facetapi_block_info in ./
facetapi.widget.inc - Returns data for the "list" operation of hook_block().
- facetapi_delta_map_get in ./
facetapi.widget.inc - Returns a "delta map", because sometimes our deltas are longer than 32 chars and need to be passed to md5(). Due to the block table's schema, deltas cannot be longer than 32 characters. However, md5 hashes are nasty as CSS IDs, so we…
- facetapi_facet_enabled in ./
facetapi.module - Tests whether a single facet is enabled in a given realm.
File
- ./
facetapi.module, line 439 - An abstracted facet API that can be used by various search backens.
Code
function facetapi_enabled_facets_get($searcher, $realm_name = NULL, $reset = FALSE) {
static $facets = array();
// Formats cache ID based on $searcher, $realm_name, and language.
global $language;
$cid = 'facetapi:facets:' . $searcher;
if (NULL !== $realm_name) {
$cid .= ':' . $realm_name;
}
$cid .= ':' . $language->language;
// Checks if the facets have already been loaded.
if (!isset($facets[$cid]) || $reset) {
// Tests if data is cached, otherwise calculates enabled facets.
if ($data = cache_get($cid, 'cache')) {
$facets[$cid] = $data->data;
}
else {
// Gets the searcher module's adapter, returns an empty array if $searcher
// does not have an adapter.
$facets[$cid] = array();
if (!($adapter = facetapi_adapter_load($searcher))) {
return $facets[$cid];
}
// Normalizes realm name(s) to an array, adds weights if realm was passed.
$realm_names = NULL === $realm_name ? array_keys(facetapi_realms_get()) : array(
$realm_name,
);
// Finds enabled facets for each realm.
// NOTE: We use $_realm_name for the variable name because $realm_name
// cannot be overwritten since its value checked later in the code.
$enabled_facets = array();
foreach ($realm_names as $_realm_name) {
$enabled_facets = array_merge($enabled_facets, array_filter((array) facetapi_setting_get('facet_status', $searcher, $_realm_name)));
}
// Gets full facet definitions for all facets, strips out facets that are
// not in $enabled_facets using the array_intersect_key() function.
if ($all_facets = facetapi_facets_get($searcher, $adapter
->getType())) {
$facets[$cid] = array_intersect_key($all_facets, $enabled_facets);
if (NULL !== $realm_name) {
facetapi_facets_sort($facets[$cid], $searcher, $realm_name);
}
cache_set($cid, $facets[$cid], 'cache', CACHE_TEMPORARY);
}
}
// Loads all include files.
foreach ($facets[$cid] as $facet) {
facetapi_file_include($facet);
}
}
return $facets[$cid];
}