You are here

function oa_subspaces_views_query_alter in Open Atrium Subspaces 7.2

Implements hook_views_query_alter().

File

./oa_subspaces.module, line 324

Code

function oa_subspaces_views_query_alter(&$view, &$query) {
  if (!empty($view->exposed_input['og_group_ref_target_id']) && is_numeric($view->exposed_input['og_group_ref_target_id']) && !empty($view->filter['og_group_ref_target_id']->options['exposed'])) {
    $settings = _oa_subspaces_find_view_settings($view);

    // Get all the parent or child groups if we are filtering for them.
    $current_group = $view->exposed_input['og_group_ref_target_id'];
    $extra_groups = array();
    if ($settings['og_subspaces_view_all']) {
      $extra_groups = array_merge($extra_groups, oa_core_get_groups_by_parent($current_group, OA_SPACE_TYPE, NULL, FALSE, NULL, TRUE));
    }
    if ($settings['og_subspaces_view_parent']) {
      $extra_groups = array_merge($extra_groups, oa_core_get_parents($current_group, OA_SPACE_TYPE, NULL, FALSE, TRUE));
    }

    // Add the extra groups to query, if there are any.
    if (!empty($extra_groups)) {
      $columns = array(
        'og_membership.gid',
        'field_data_oa_other_spaces_ref.oa_other_spaces_ref_target_id',
      );
      oa_core_view_query_modify_condition($query, $columns, $extra_groups);
    }
    if (!empty($view->exposed_input['oa_section_ref_target_id']) && is_numeric($view->exposed_input['oa_section_ref_target_id']) && !empty($view->filter['oa_section_ref_target_id']->options['exposed'])) {
      if (!empty($extra_groups)) {
        $columns = array(
          'field_data_oa_section_ref.oa_section_ref_target_id',
        );
        $extra_sections = oa_subspaces_matching_sections($view->exposed_input['oa_section_ref_target_id'], $extra_groups, array(
          $current_group,
        ));
        oa_core_view_query_modify_condition($query, $columns, $extra_sections);
      }
    }
  }
}