title aliasing?

mizerydearia - October 14, 2009 - 02:19
Project:Faceted Search
Version:6.x-1.0-beta2
Component:General
Category:support request
Priority:normal
Assigned:Unassigned
Status:active
Description

How can I set the title depending on the terms selected from guided search?

I have created my own solution in a custom module, however, it is hardcoded into the module file as opposed to offering a solution that allows others to configure. I'm not sure if there is another method of doing this, but if anyone can offer suggestions, it would be much appreciated.

function therugcompany_menu() {
  foreach (faceted_search_get_env_ids() as $env_id) {
    $env = faceted_search_env_load($env_id);
    $base_path = $env->settings['base_path'];
    $items[$base_path .'/results'] = array(
      'page callback' => 'trc_faceted_search_ui_stage_results',
      'page arguments' => array((string)$env_id),
      'access arguments' => array('use faceted search'),
      'type' => MENU_CALLBACK,
    );   
  }
  return $items;
}

function trc_faceted_search_ui_stage_results($env_id, $text = '') {
  // If the menu system has splitted the search text because of slashes, glue it back.
  if (func_num_args() > 2) {
    $args = func_get_args();
    $text .= '/'. implode('/', array_slice($args, 2));
  }

  $env = faceted_search_env_load($env_id);
 
  // Initialize the current search.
  $env->prepare($text);
  $env->ui_state['stage'] = 'results';

  if ($text) {
    // Log the search text.
    $path = faceted_search_ui_build_path($env, $env->ui_state, $text);
    watchdog('faceted_search', '%text.', array('%text' => $text), WATCHDOG_NOTICE, l(t('results'), $path));
  }

  faceted_search_ui_add_robots_directive($env);
  faceted_search_ui_add_css();

  // Collect the search results.
  $env->execute();
  $style = faceted_search_ui_get_style($env);
  if (method_exists($style, 'format_results')) {
    $results = $style->format_results($env);
  }

  trc_faceted_search_ui_set_title($env);
  $content = theme('faceted_search_ui_stage_results', $results, $style);
  return theme('faceted_search_ui_page', $env, $content);
}

function trc_faceted_search_ui_set_title($env) {
  $labels = array();
  if ($env->get_text()) {
    foreach ($env->get_filters() as $filter) {
      if ($filter->is_active()) {
        $category = $filter->get_active_category();
        // Note: get_label() is responsible for filtering its returned string.
        $labels[] = $category->get_label(FALSE);
      }
    }
  }
  if (count($labels)) {
    if (count($labels) == 2 && in_array('Hand Knotted', $labels) && in_array('Oriental', $labels))
      drupal_set_title('Hand Knotted Oriental Rugs');
    else if (count($labels) == 2 && in_array('Machine Loomed', $labels) && in_array('Polypropylene', $labels))
      drupal_set_title('Machine Loomed Polypropylene Rugs');
    else if (count($labels) == 2 && in_array('Machine Loomed', $labels) && in_array('Wool', $labels))
      drupal_set_title('Machine Loomed Wool Rugs');
    else drupal_set_title(t('!terms Rugs', array('!terms' => implode(', ', $labels))));
  }
  else drupal_set_title(check_plain($env->settings['title']));
}

I want to set the titles in particular order, so that for example even if $labels includes 'Oriental' and 'Hand Knotted' it does not appear as 'Oriental Hand Knotted Rugs' but always as 'Hand Knotted Oriental Rugs'

 
 

Drupal is a registered trademark of Dries Buytaert.