You are here

function taxo_faceted_navigation_build_url_alias in Taxonomy Facets 7

Build a URL to be used in the menu item.

Use the taxonomy term of the menu item that we are building, plus all other terms in the page url to construct the url of the menu item.

Parameters

integer $vid: Vocabulary id.

array $terms: Terms in the url, i.e applied filters

integer $tid: Term id of the term, the term of the menu item that we are building.

Return value

string Menu item url.

1 call to taxo_faceted_navigation_build_url_alias()
_taxo_faceted_navigation_get_menu_tree in ./taxo_faceted_navigation.module
Helper function for taxo_faceted_navigation_get_menu_tree.

File

./taxo_faceted_navigation.module, line 575
Taxo Faceted Navigation module code.

Code

function taxo_faceted_navigation_build_url_alias($vid, $terms, $tid) {

  // Prepend language prefix to the path.
  global $language;
  if ($language->prefix != NULL) {
    $alias = '/' . $language->prefix;
  }
  else {
    $alias = '';
  }

  // Get the first argument form settings.
  $alias .= '/' . variable_get('taxo_faceted_navigation_first_argument', 'items_list');
  $filters_vids = array();

  // If no other terms applied as filters yet, i.e no filters selected
  // then just build url based on the term we are building menu item for.
  if ($terms == NULL) {
    $alias .= '/' . taxo_faceted_navigation_get_term_url_alias_from_tid($tid);
  }
  else {

    // There are other terms, so we need to append other filter terms to the
    // current menu item, but always preserving the order of vocabularies,
    // so that we do not end up with multiple urls for the same page.
    // So replace current vocabulary filter item with the url
    // of the current menu item we are printing.
    $count = 0;
    $arr_element = 999999;
    foreach ($terms as $term) {

      // If filter is from current vocab do not append it,
      // as we are using menu item in loop to build urls alias for this vocab bit.
      if ($term['vid'] == $vid) {

        // Get index of array element.
        $arr_element = $count;
      }
      $count++;
      $filters_vids[] = $term['vid'];
    }

    // Found, so replace.
    if ($arr_element != 999999) {
      $terms[$arr_element]['term_path_alias'] = taxo_faceted_navigation_get_term_url_alias_from_tid($tid);
    }
    else {

      // There was no term in current filters that was part of this vocabulary
      // (vocabulary we are building tree for)
      // so create term for it as we will need it to build menu item, it
      // will be the term of the menu item we are building.
      $term['tid'] = $tid;
      $term['term_path_alias'] = taxo_faceted_navigation_get_term_url_alias_from_tid($tid);
      $term['term_name'] = 'x';
      $term['vid'] = $vid;
      $terms[] = $term;
      $filters_vids[] = $vid;
    }

    // If more than one filter order them.
    if (count($terms) > 1) {

      // Get order of filters from user preferences,
      // this is a variable that stores vocabularies to be used for
      // taxo faceted navigation, and its ordered.
      $taxos = variable_get('taxo_faceted_navigation_taxonomies', $terms);

      // Will hold ordered filters.
      $ret_filters = array();
      foreach ($taxos as $taxo) {

        // If this vocab in loop is also in the filter array($terms) , add
        // it to new array of filters,
        // that way filters in this new array will be ordered the same as in
        // user preference array ($taxos).
        if (in_array($taxo['vid'], $filters_vids)) {
          $ret_filters[] = taxo_faceted_navigation_get_array_element($taxo['vid'], $terms);
        }
      }
    }
    else {
      $ret_filters = $terms;
    }

    // Build menu item url string.
    foreach ($ret_filters as $term) {
      if ($term['term_path_alias']) {
        $alias .= '/' . $term['term_path_alias'];
      }
    }
  }
  return $alias;
}