? og_facets_361848.patch Index: og_facets.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/og_facets/og_facets.module,v retrieving revision 1.1 diff -u -p -r1.1 og_facets.module --- og_facets.module 24 Apr 2008 22:55:14 -0000 1.1 +++ og_facets.module 22 Jan 2009 05:31:30 -0000 @@ -11,46 +11,48 @@ require_once('./'. drupal_get_path('modu /** * Implementation of hook_form_alter(). */ -function og_facets_form_alter($form_id, &$form) { - if ($form_id == 'faceted_search_edit_form') { - $env_id = $form['env_id']['#value']; - - $form['og_facets'] = array( - '#type' => 'fieldset', - '#title' => t('Organic Group Facet options'), - '#collapsible' => TRUE, - '#collapsed' => TRUE, - '#weight' => 10, +function og_facets_form_faceted_search_edit_form_alter(&$form, $form_state) { + + $env = $form['env']['#value']; + + $form['og_facets'] = array( + '#type' => 'fieldset', + '#title' => t('Organic Group Facet options'), + '#collapsible' => TRUE, + '#collapsed' => TRUE, + '#weight' => 10, + ); + + $types = array(); + foreach (og_get_types('group') as $type) { + $types[$type] = $type; + } + if (count($types)) { + $form['og_facets']['og_facets_excluded_types'] = array( + '#type' => 'checkboxes', + '#title' => t('Group types to exclude from the Organic Group facet'), + '#description' => t('Groups of the checked types will not appear in the facet. Note that this setting is not a filter for search results; content from excluded groups can still be searchable through other facets or from text searches.'), + '#options' => $types, + '#default_value' => og_facets_excluded_types($env), + ); + } + else { + $form['og_facets']['og_facets_help'] = array( + '#type' => 'markup', + '#value' => '
'. t('No organic group types are currently available.') .'
', ); - - $types = variable_get('og_node_types', array('og')); - if (count($types)) { - $form['og_facets']['og_facets_excluded_types'] = array( - '#type' => 'checkboxes', - '#title' => t('Group types to exclude from the Organic Group facet'), - '#description' => t('Groups of the checked types will not appear in the facet. Note that this setting is not a filter for search results; content from excluded groups can still be searchable through other facets or from text searches.'), - '#options' => $types, - '#default_value' => isset($env_id) ? og_facets_excluded_types($env_id) : array(), - ); - } - else { - $form['og_facets']['og_facets_help'] = array( - '#type' => 'markup', - '#value' => ''. t('No organic group types are currently available.') .'
', - ); - } } } /** * Implementation of hook_faceted_search_collect(). */ -function og_facets_faceted_search_collect(&$facets, $domain, $env_id, $selection, $arg = NULL) { +function og_facets_faceted_search_collect(&$facets, $domain, $env, $selection, $arg = NULL) { switch ($domain) { - case 'all': + case 'facets': // If the og facet is allowed. - if (!isset($selection) || isset($selection['og'][1])) { - $excluded_types = og_facets_excluded_types($env_id); + if (!isset($selection) || isset($selection['og'][1])) { + $excluded_types = og_facets_excluded_types($env); $facets[] = new og_facets($excluded_types); } break; @@ -62,8 +64,8 @@ function og_facets_faceted_search_collec // facet from it. if ($gid = search_query_extract($arg, 'og')) { if (is_numeric($gid)) { - $excluded_types = og_facets_excluded_types($env_id); - if ($name = og_facets_get_group_name($env_id, $gid, $excluded_types)) { + $excluded_types = og_facets_excluded_types($env); + if ($name = og_facets_get_group_name($env, $gid, $excluded_types)) { // Create a facet with the group found in the search text as the // active category. $facets[] = new og_facets($excluded_types, $gid, $name); @@ -78,9 +80,9 @@ function og_facets_faceted_search_collec case 'node': // If the og facet is allowed. if ($arg->og_groups && (!isset($selection) || isset($selection['og'][1]))) { - $excluded_types = og_facets_excluded_types($env_id); + $excluded_types = og_facets_excluded_types($env); foreach ($arg->og_groups as $gid) { - if ($name = og_facets_get_group_name($env_id, $gid, $excluded_types)) { + if ($name = og_facets_get_group_name($env, $gid, $excluded_types)) { // Create a facet with the group as the active category. $facets[] = new og_facets($excluded_types, $gid, $name); } @@ -96,7 +98,7 @@ function og_facets_faceted_search_collec * @return The group's name, or FALSE if not found or if the group's type is not * allowed in the facet. */ -function og_facets_get_group_name($env_id, $gid, $excluded_types = array()) { +function og_facets_get_group_name($env, $gid, $excluded_types = array()) { if (count($excluded_types)) { return db_result(db_query('SELECT n.title FROM {node} n WHERE n.nid = %d AND NOT n.type IN (\''. implode('\', \'', $excluded_types) .'\')', $gid)); } @@ -108,12 +110,18 @@ function og_facets_get_group_name($env_i /** * Returns an array with the types that should not be used in faceted searches. */ -function og_facets_excluded_types($env_id) { - $types = variable_get('og_node_types', array('og')); - return array_intersect(faceted_search_variable_get($env_id, 'og_facets_excluded_types', array()), array_keys($types)); +function og_facets_excluded_types($env) { + return array_diff($env->settings['og_facets_excluded_types'], array(0)); } /** + * Implementation of hook_faceted_search_init(). + */ +function og_facets_faceted_search_init(&$env) { + $env->settings['og_facets_excluded_types'] = array(); +} + +/** * A facet for organic groups. */ class og_facets extends faceted_search_facet {