function taxo_faceted_navigation_get_nodes_based_on_intersect_of_terms in Taxonomy Facets 7
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 taxo_faceted_navigation_get_nodes_based_on_intersect_of_terms()
- taxo_faceted_navigation_print_landing_page in ./
taxo_faceted_navigation.module - Print the page that filters are applied to.
- _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 875 - Taxo Faceted Navigation module code.
Code
function taxo_faceted_navigation_get_nodes_based_on_intersect_of_terms($selected_filters, $text_compare = NULL, $text_compare_middle = NULL) {
$node_types = variable_get('taxo_faceted_navigation_content_type_options', array());
$nodeTypes = array();
foreach ($node_types as $key => $value) {
if ($value !== 0) {
$nodeTypes[] = $value;
}
}
$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;
}