You are here

function taxonomy_facets_get_nodes_based_on_intersect_of_terms in Taxonomy Facets 7.2

Same name and namespace in other branches
  1. 7.3 taxonomy_facets.module \taxonomy_facets_get_nodes_based_on_intersect_of_terms()

Get nodes tagged by given terms.

Nodes have been associated with various terms. For terms passed in the url as the argument, return all nodes that have those terms associated with them. Nodes that have *all* of the terms associated will be returned, i.e intersection of terms.

Parameters

array $selected_filters: Array or term id's

array $node_types: (optional) default null. The array of strings, node types. i.e story, page etc..

string $text_compare: (optional) string

string $text_compare_middle: (optional) string

2 calls to taxonomy_facets_get_nodes_based_on_intersect_of_terms()
taxonomy_facets_display_meny_item_check in ./taxonomy_facets.module
When building menu tree we check if we want to display a menu item depending on various user preferences
taxonomy_facets_print_landing_page in ./taxonomy_facets.module
Print the page that displays list of nods when filters are applied.

File

./taxonomy_facets.module, line 949
Taxo Faceted Navigation module code.

Code

function taxonomy_facets_get_nodes_based_on_intersect_of_terms($selected_filters, $text_compare = NULL, $text_compare_middle = NULL) {
  $node_types = variable_get('taxonomy_facets_content_type_options', array());
  $nodeTypes = array();
  foreach ($node_types as $key => $value) {
    if ($value !== 0) {
      $nodeTypes[] = $value;
    }
  }

  // Build the sql query that will bring us desired nodes
  $tids = array();
  $values = array();
  foreach ($selected_filters as $filter) {
    $tids[] = $filter['tid'];
  }
  $joins = ' ';
  $wheres = 'WHERE n.status = 1 ';
  if (!empty($node_types)) {
    $wheres .= " AND n.type in (:node_types)";
    $values[':node_types'] = $node_types;
  }
  $counter = 0;
  foreach ($tids as $key => $value) {
    $joins .= 'INNER JOIN {taxonomy_index} ti' . $counter . ' ON n.nid = ti' . $counter . ' .nid ';
    $wheres .= ' AND ti' . $counter . ' .tid = :tid' . $counter;
    $values['tid' . $counter] = $value;
    $counter++;
  }

  /* TO DO - implement free  text search in conjunction with faceted search
    if ($text_compare) {
    $wheres .= 'AND n.title LIKE \'' . $text_compare . '%\'';
    }

    if ($text_compare_middle) {
    $wheres .= 'AND n.title LIKE \'%' . $text_compare_middle . '%\'';
    }
    */
  $order = 'n.sticky DESC, n.changed DESC';
  $sql = 'SELECT  n.nid
          FROM {node} n ' . $joins . '
          ' . $wheres . ' ORDER BY ' . $order;
  $result = db_query($sql, $values);

  // Convert array of objects to array.
  $arr_result = array();
  foreach ($result as $record) {
    $arr_result[] = $record->nid;
  }
  return $arr_result;
}