You are here

function apachesolr_og_alter_callback in Apache Solr Organic Groups Integration 7

Alters the build array of the OG_AUDIENCE_FIELD filter. Adds a filter that allows the user to filter on his groups.

@global type $user

Parameters

array $build:

FacetapiAdapter $adapter:

array $facet:

1 string reference to 'apachesolr_og_alter_callback'
apachesolr_og_apachesolr_field_mappings_alter in ./apachesolr_og.module
Implements hook_apachesolr_field_mappings_alter().

File

./apachesolr_og.module, line 28
Integrates Organic Group info with Apache Solr search application.

Code

function apachesolr_og_alter_callback(&$build, FacetapiAdapter $adapter, $facet) {
  $count = 0;
  global $user;
  if (is_array($build) && !empty($build)) {

    // Add a filter 'Your Groups'
    $user_groups = og_get_groups_by_user($user);
    foreach ($build as $filter => $value) {

      // We could do this with the objects, but it would make it a lot more

      //complex
      $filter_values = explode(':', $filter);
      $count += isset($user_groups[$filter_values[0]][$filter_values[1]]) ? $value['#count'] : 0;
    }
    $search_string = apachesolr_og_get_my_groups_filter();
    $build[$search_string] = array(
      '#count' => $count,
    );
  }
}